From 08d3f1711011d7c3996c7c9b48210bf6e3e027f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Mon, 23 Sep 2024 13:18:07 +0100 Subject: [PATCH] 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. --- runtime/js/99_main.js | 1 + tests/specs/run/location/__test__.jsonc | 8 ++++++++ tests/specs/run/location/location.js | 24 ++++++++++++++++++++++++ tests/specs/run/location/location.out | 5 +++++ 4 files changed, 38 insertions(+) create mode 100644 tests/specs/run/location/__test__.jsonc create mode 100644 tests/specs/run/location/location.js create mode 100644 tests/specs/run/location/location.out diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js index 8f53cffc42df92..9134ac48a15d95 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 00000000000000..551463d594d8dd --- /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 00000000000000..8562a39957d084 --- /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 00000000000000..bcb3ff67b91dbf --- /dev/null +++ b/tests/specs/run/location/location.out @@ -0,0 +1,5 @@ +undefined +undefined +https://deno.com +https://deno.com +undefined