summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2024-09-23 13:18:07 +0100
committerGitHub <noreply@github.com>2024-09-23 14:18:07 +0200
commit08d3f1711011d7c3996c7c9b48210bf6e3e027f7 (patch)
tree55789c5fc2ef80c98041245ae7e1c872da8e915c
parent8f32a1577ec00d239bce39dd1f526b5678041b8b (diff)
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.
-rw-r--r--runtime/js/99_main.js1
-rw-r--r--tests/specs/run/location/__test__.jsonc8
-rw-r--r--tests/specs/run/location/location.js24
-rw-r--r--tests/specs/run/location/location.out5
4 files changed, 38 insertions, 0 deletions
diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js
index 8f53cffc4..9134ac48a 100644
--- a/runtime/js/99_main.js
+++ b/runtime/js/99_main.js
@@ -654,6 +654,7 @@ function bootstrapMainRuntime(runtimeOptions, warmup = false) {
if (location_ == null) {
mainRuntimeGlobalProperties.location = {
writable: true,
+ configurable: true,
};
} else {
location.setLocationHref(location_);
diff --git a/tests/specs/run/location/__test__.jsonc b/tests/specs/run/location/__test__.jsonc
new file mode 100644
index 000000000..551463d59
--- /dev/null
+++ b/tests/specs/run/location/__test__.jsonc
@@ -0,0 +1,8 @@
+{
+ "tests": {
+ "location_object_define_property": {
+ "args": "run location.js",
+ "output": "location.out"
+ }
+ }
+}
diff --git a/tests/specs/run/location/location.js b/tests/specs/run/location/location.js
new file mode 100644
index 000000000..8562a3995
--- /dev/null
+++ b/tests/specs/run/location/location.js
@@ -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);
diff --git a/tests/specs/run/location/location.out b/tests/specs/run/location/location.out
new file mode 100644
index 000000000..bcb3ff67b
--- /dev/null
+++ b/tests/specs/run/location/location.out
@@ -0,0 +1,5 @@
+undefined
+undefined
+https://deno.com
+https://deno.com
+undefined