mirror of
https://github.com/denoland/deno.git
synced 2024-12-23 07:44:48 -05:00
feat: make 'globalThis.location' a configurable property (#25812)
This commit changes `globalThis.location` property to be configurable so that packages wanting to override it (or delete it) work properly. Towards https://github.com/denoland/deno/issues/23882 This change makes reproduction from https://github.com/denoland/deno/issues/23882#issuecomment-2340783437 pass properly.
This commit is contained in:
parent
8f32a1577e
commit
08d3f17110
4 changed files with 38 additions and 0 deletions
|
@ -654,6 +654,7 @@ function bootstrapMainRuntime(runtimeOptions, warmup = false) {
|
|||
if (location_ == null) {
|
||||
mainRuntimeGlobalProperties.location = {
|
||||
writable: true,
|
||||
configurable: true,
|
||||
};
|
||||
} else {
|
||||
location.setLocationHref(location_);
|
||||
|
|
8
tests/specs/run/location/__test__.jsonc
Normal file
8
tests/specs/run/location/__test__.jsonc
Normal file
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"tests": {
|
||||
"location_object_define_property": {
|
||||
"args": "run location.js",
|
||||
"output": "location.out"
|
||||
}
|
||||
}
|
||||
}
|
24
tests/specs/run/location/location.js
Normal file
24
tests/specs/run/location/location.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
let _location = undefined;
|
||||
|
||||
console.log(globalThis.location);
|
||||
|
||||
Object.defineProperty(globalThis, "location", {
|
||||
get() {
|
||||
return _location;
|
||||
},
|
||||
set(v) {
|
||||
_location = v;
|
||||
},
|
||||
configurable: true,
|
||||
});
|
||||
|
||||
console.log(globalThis.location);
|
||||
|
||||
globalThis.location = "https://deno.com";
|
||||
|
||||
console.log(_location);
|
||||
console.log(location);
|
||||
|
||||
delete globalThis["location"];
|
||||
|
||||
console.log(globalThis.location);
|
5
tests/specs/run/location/location.out
Normal file
5
tests/specs/run/location/location.out
Normal file
|
@ -0,0 +1,5 @@
|
|||
undefined
|
||||
undefined
|
||||
https://deno.com
|
||||
https://deno.com
|
||||
undefined
|
Loading…
Reference in a new issue