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
8
cli/tests/testdata/070_location.ts
vendored
8
cli/tests/testdata/070_location.ts
vendored
|
@ -1,6 +1,14 @@
|
||||||
|
// deno-lint-ignore-file no-global-assign
|
||||||
console.log(Location);
|
console.log(Location);
|
||||||
console.log(Location.prototype);
|
console.log(Location.prototype);
|
||||||
console.log(location);
|
console.log(location);
|
||||||
|
try {
|
||||||
|
location = {};
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
console.log(error.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
location.hostname = "bar";
|
location.hostname = "bar";
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
1
cli/tests/testdata/070_location.ts.out
vendored
1
cli/tests/testdata/070_location.ts.out
vendored
|
@ -11,5 +11,6 @@ Location {
|
||||||
protocol: "https:",
|
protocol: "https:",
|
||||||
search: "?baz"
|
search: "?baz"
|
||||||
}
|
}
|
||||||
|
NotSupportedError: Cannot set "location".
|
||||||
NotSupportedError: Cannot set "location.hostname".
|
NotSupportedError: Cannot set "location.hostname".
|
||||||
[WILDCARD]
|
[WILDCARD]
|
||||||
|
|
13
cli/tests/testdata/071_location_unset.ts
vendored
13
cli/tests/testdata/071_location_unset.ts
vendored
|
@ -1,3 +1,16 @@
|
||||||
console.log(Location);
|
console.log(Location);
|
||||||
console.log(Location.prototype);
|
console.log(Location.prototype);
|
||||||
console.log(location);
|
console.log(location);
|
||||||
|
|
||||||
|
globalThis.location = {
|
||||||
|
hash: "#bat",
|
||||||
|
host: "foo",
|
||||||
|
hostname: "foo",
|
||||||
|
href: "https://foo/bar?baz#bat",
|
||||||
|
origin: "https://foo",
|
||||||
|
pathname: "/bar",
|
||||||
|
port: "",
|
||||||
|
protocol: "https:",
|
||||||
|
search: "?baz",
|
||||||
|
};
|
||||||
|
console.log(location.pathname);
|
||||||
|
|
1
cli/tests/testdata/071_location_unset.ts.out
vendored
1
cli/tests/testdata/071_location_unset.ts.out
vendored
|
@ -1,4 +1,5 @@
|
||||||
[WILDCARD][Function: Location]
|
[WILDCARD][Function: Location]
|
||||||
Location {}
|
Location {}
|
||||||
undefined
|
undefined
|
||||||
|
/bar
|
||||||
[WILDCARD]
|
[WILDCARD]
|
||||||
|
|
|
@ -639,6 +639,18 @@ delete Intl.v8BreakIterator;
|
||||||
throw new Error("Worker runtime already bootstrapped");
|
throw new Error("Worker runtime already bootstrapped");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const {
|
||||||
|
args,
|
||||||
|
location: locationHref,
|
||||||
|
noColor,
|
||||||
|
isTty,
|
||||||
|
pid,
|
||||||
|
ppid,
|
||||||
|
unstableFlag,
|
||||||
|
cpuCount,
|
||||||
|
userAgent: userAgentInfo,
|
||||||
|
} = runtimeOptions;
|
||||||
|
|
||||||
performance.setTimeOrigin(DateNow());
|
performance.setTimeOrigin(DateNow());
|
||||||
const consoleFromV8 = window.console;
|
const consoleFromV8 = window.console;
|
||||||
const wrapConsole = window.__bootstrap.console.wrapConsole;
|
const wrapConsole = window.__bootstrap.console.wrapConsole;
|
||||||
|
@ -648,6 +660,18 @@ delete Intl.v8BreakIterator;
|
||||||
delete globalThis.bootstrap;
|
delete globalThis.bootstrap;
|
||||||
util.log("bootstrapMainRuntime");
|
util.log("bootstrapMainRuntime");
|
||||||
hasBootstrapped = true;
|
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);
|
ObjectDefineProperties(globalThis, windowOrWorkerGlobalScope);
|
||||||
if (runtimeOptions.unstableFlag) {
|
if (runtimeOptions.unstableFlag) {
|
||||||
ObjectDefineProperties(globalThis, unstableWindowOrWorkerGlobalScope);
|
ObjectDefineProperties(globalThis, unstableWindowOrWorkerGlobalScope);
|
||||||
|
@ -678,22 +702,8 @@ delete Intl.v8BreakIterator;
|
||||||
});
|
});
|
||||||
|
|
||||||
runtimeStart(runtimeOptions);
|
runtimeStart(runtimeOptions);
|
||||||
const {
|
|
||||||
args,
|
|
||||||
location: locationHref,
|
|
||||||
noColor,
|
|
||||||
isTty,
|
|
||||||
pid,
|
|
||||||
ppid,
|
|
||||||
unstableFlag,
|
|
||||||
cpuCount,
|
|
||||||
userAgent: userAgentInfo,
|
|
||||||
} = runtimeOptions;
|
|
||||||
|
|
||||||
colors.setNoColor(noColor || !isTty);
|
colors.setNoColor(noColor || !isTty);
|
||||||
if (locationHref != null) {
|
|
||||||
location.setLocationHref(locationHref);
|
|
||||||
}
|
|
||||||
numCpus = cpuCount;
|
numCpus = cpuCount;
|
||||||
userAgent = userAgentInfo;
|
userAgent = userAgentInfo;
|
||||||
registerErrors();
|
registerErrors();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue