mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 12:19:12 +00:00
fix: allow setting globalThis.location
when no --location
is provided (#15448)
This commit is contained in:
parent
f16fe44303
commit
08061b60d9
5 changed files with 47 additions and 14 deletions
|
@ -639,6 +639,18 @@ delete Intl.v8BreakIterator;
|
|||
throw new Error("Worker runtime already bootstrapped");
|
||||
}
|
||||
|
||||
const {
|
||||
args,
|
||||
location: locationHref,
|
||||
noColor,
|
||||
isTty,
|
||||
pid,
|
||||
ppid,
|
||||
unstableFlag,
|
||||
cpuCount,
|
||||
userAgent: userAgentInfo,
|
||||
} = runtimeOptions;
|
||||
|
||||
performance.setTimeOrigin(DateNow());
|
||||
const consoleFromV8 = window.console;
|
||||
const wrapConsole = window.__bootstrap.console.wrapConsole;
|
||||
|
@ -648,6 +660,18 @@ delete Intl.v8BreakIterator;
|
|||
delete globalThis.bootstrap;
|
||||
util.log("bootstrapMainRuntime");
|
||||
hasBootstrapped = true;
|
||||
|
||||
// If the `--location` flag isn't set, make `globalThis.location` `undefined` and
|
||||
// writable, so that they can mock it themselves if they like. If the flag was
|
||||
// set, define `globalThis.location`, using the provided value.
|
||||
if (locationHref == null) {
|
||||
mainRuntimeGlobalProperties.location = {
|
||||
writable: true,
|
||||
};
|
||||
} else {
|
||||
location.setLocationHref(locationHref);
|
||||
}
|
||||
|
||||
ObjectDefineProperties(globalThis, windowOrWorkerGlobalScope);
|
||||
if (runtimeOptions.unstableFlag) {
|
||||
ObjectDefineProperties(globalThis, unstableWindowOrWorkerGlobalScope);
|
||||
|
@ -678,22 +702,8 @@ delete Intl.v8BreakIterator;
|
|||
});
|
||||
|
||||
runtimeStart(runtimeOptions);
|
||||
const {
|
||||
args,
|
||||
location: locationHref,
|
||||
noColor,
|
||||
isTty,
|
||||
pid,
|
||||
ppid,
|
||||
unstableFlag,
|
||||
cpuCount,
|
||||
userAgent: userAgentInfo,
|
||||
} = runtimeOptions;
|
||||
|
||||
colors.setNoColor(noColor || !isTty);
|
||||
if (locationHref != null) {
|
||||
location.setLocationHref(locationHref);
|
||||
}
|
||||
numCpus = cpuCount;
|
||||
userAgent = userAgentInfo;
|
||||
registerErrors();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue