mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 12:19:12 +00:00
fix(ext/console): don't depend on globalThis present (#13387)
This commit is contained in:
parent
1ab5dea367
commit
bc666e42a8
5 changed files with 24 additions and 3 deletions
|
@ -2479,3 +2479,8 @@ itest!(import_assertions_type_check {
|
||||||
output: "import_assertions/type_check.out",
|
output: "import_assertions/type_check.out",
|
||||||
exit_code: 1,
|
exit_code: 1,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
itest!(colors_without_global_this {
|
||||||
|
args: "run colors_without_globalThis.js",
|
||||||
|
output_str: Some("true\n"),
|
||||||
|
});
|
||||||
|
|
1
cli/tests/testdata/colors_without_globalThis.js
vendored
Normal file
1
cli/tests/testdata/colors_without_globalThis.js
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
console.log(delete globalThis.globalThis);
|
|
@ -11,6 +11,16 @@
|
||||||
ArrayPrototypeJoin,
|
ArrayPrototypeJoin,
|
||||||
} = window.__bootstrap.primordials;
|
} = window.__bootstrap.primordials;
|
||||||
|
|
||||||
|
let noColor = false;
|
||||||
|
|
||||||
|
function setNoColor(value) {
|
||||||
|
noColor = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getNoColor() {
|
||||||
|
return noColor;
|
||||||
|
}
|
||||||
|
|
||||||
function code(open, close) {
|
function code(open, close) {
|
||||||
return {
|
return {
|
||||||
open: `\x1b[${open}m`,
|
open: `\x1b[${open}m`,
|
||||||
|
@ -79,7 +89,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function maybeColor(fn) {
|
function maybeColor(fn) {
|
||||||
return !(globalThis.Deno?.noColor ?? false) ? fn : (s) => s;
|
return !noColor ? fn : (s) => s;
|
||||||
}
|
}
|
||||||
|
|
||||||
window.__bootstrap.colors = {
|
window.__bootstrap.colors = {
|
||||||
|
@ -95,5 +105,7 @@
|
||||||
magenta,
|
magenta,
|
||||||
stripColor,
|
stripColor,
|
||||||
maybeColor,
|
maybeColor,
|
||||||
|
setNoColor,
|
||||||
|
getNoColor,
|
||||||
};
|
};
|
||||||
})(this);
|
})(this);
|
||||||
|
|
|
@ -1650,7 +1650,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function inspectArgs(args, inspectOptions = {}) {
|
function inspectArgs(args, inspectOptions = {}) {
|
||||||
const noColor = globalThis.Deno?.noColor ?? true;
|
const noColor = colors.getNoColor();
|
||||||
const rInspectOptions = { ...DEFAULT_INSPECT_OPTIONS, ...inspectOptions };
|
const rInspectOptions = { ...DEFAULT_INSPECT_OPTIONS, ...inspectOptions };
|
||||||
const first = args[0];
|
const first = args[0];
|
||||||
let a = 0;
|
let a = 0;
|
||||||
|
@ -1759,7 +1759,7 @@
|
||||||
function getConsoleInspectOptions() {
|
function getConsoleInspectOptions() {
|
||||||
return {
|
return {
|
||||||
...DEFAULT_INSPECT_OPTIONS,
|
...DEFAULT_INSPECT_OPTIONS,
|
||||||
colors: !(globalThis.Deno?.noColor ?? false),
|
colors: !colors.getNoColor(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@ delete Object.prototype.__proto__;
|
||||||
const timers = window.__bootstrap.timers;
|
const timers = window.__bootstrap.timers;
|
||||||
const base64 = window.__bootstrap.base64;
|
const base64 = window.__bootstrap.base64;
|
||||||
const encoding = window.__bootstrap.encoding;
|
const encoding = window.__bootstrap.encoding;
|
||||||
|
const colors = window.__bootstrap.colors;
|
||||||
const Console = window.__bootstrap.console.Console;
|
const Console = window.__bootstrap.console.Console;
|
||||||
const worker = window.__bootstrap.worker;
|
const worker = window.__bootstrap.worker;
|
||||||
const internals = window.__bootstrap.internals;
|
const internals = window.__bootstrap.internals;
|
||||||
|
@ -574,6 +575,7 @@ delete Object.prototype.__proto__;
|
||||||
cpuCount,
|
cpuCount,
|
||||||
} = runtimeOptions;
|
} = runtimeOptions;
|
||||||
|
|
||||||
|
colors.setNoColor(noColor);
|
||||||
if (locationHref != null) {
|
if (locationHref != null) {
|
||||||
location.setLocationHref(locationHref);
|
location.setLocationHref(locationHref);
|
||||||
}
|
}
|
||||||
|
@ -664,6 +666,7 @@ delete Object.prototype.__proto__;
|
||||||
cpuCount,
|
cpuCount,
|
||||||
} = runtimeOptions;
|
} = runtimeOptions;
|
||||||
|
|
||||||
|
colors.setNoColor(noColor);
|
||||||
location.setLocationHref(locationHref);
|
location.setLocationHref(locationHref);
|
||||||
numCpus = cpuCount;
|
numCpus = cpuCount;
|
||||||
registerErrors();
|
registerErrors();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue