Skip to content

Commit

Permalink
feat: make 'globalThis.location' a configurable property (#25812)
Browse files Browse the repository at this point in the history
This commit changes `globalThis.location` property to be configurable
so that packages wanting to override it (or delete it) work properly.

Towards #23882

This change makes reproduction from
#23882 (comment)
pass properly.
  • Loading branch information
bartlomieju authored Sep 23, 2024
1 parent 8f32a15 commit 08d3f17
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions runtime/js/99_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,7 @@ function bootstrapMainRuntime(runtimeOptions, warmup = false) {
if (location_ == null) {
mainRuntimeGlobalProperties.location = {
writable: true,
configurable: true,
};
} else {
location.setLocationHref(location_);
Expand Down
8 changes: 8 additions & 0 deletions tests/specs/run/location/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"tests": {
"location_object_define_property": {
"args": "run location.js",
"output": "location.out"
}
}
}
24 changes: 24 additions & 0 deletions tests/specs/run/location/location.js
Original file line number Diff line number Diff line change
@@ -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 changes: 5 additions & 0 deletions tests/specs/run/location/location.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
undefined
undefined
https://deno.com
https://deno.com
undefined

0 comments on commit 08d3f17

Please sign in to comment.