diff options
author | Kayla Washburn <mckayla@hey.com> | 2022-08-10 12:57:30 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-10 12:57:30 -0600 |
commit | 08061b60d9be2b6990d1134aa5b94ec36f9266aa (patch) | |
tree | 88f4621b251d74cdb179afd1af07cc446951ca08 /runtime/js | |
parent | f16fe443038454ef49641b097c0a0161a97bd1c3 (diff) |
fix: allow setting `globalThis.location` when no `--location` is provided (#15448)
Diffstat (limited to 'runtime/js')
-rw-r--r-- | runtime/js/99_main.js | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js index 167862a9e..b397fcb47 100644 --- a/runtime/js/99_main.js +++ b/runtime/js/99_main.js @@ -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(); |