summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/tests/integration/run_tests.rs7
-rw-r--r--cli/tests/testdata/replace_self.js21
-rw-r--r--cli/tests/testdata/replace_self.js.out4
-rw-r--r--runtime/js/99_main.js4
-rw-r--r--tools/wpt/expectation.json2
5 files changed, 35 insertions, 3 deletions
diff --git a/cli/tests/integration/run_tests.rs b/cli/tests/integration/run_tests.rs
index f247aa93f..f469bb364 100644
--- a/cli/tests/integration/run_tests.rs
+++ b/cli/tests/integration/run_tests.rs
@@ -1185,6 +1185,13 @@ itest!(error_import_map_unable_to_load {
exit_code: 1,
});
+// Test that setting `self` in the main thread to some other value doesn't break
+// the world.
+itest!(replace_self {
+ args: "run replace_self.js",
+ output: "replace_self.js.out",
+});
+
itest!(worker_event_handler_test {
args: "run --quiet --reload --allow-read worker_event_handler_test.js",
output: "worker_event_handler_test.js.out",
diff --git a/cli/tests/testdata/replace_self.js b/cli/tests/testdata/replace_self.js
new file mode 100644
index 000000000..cfd473cd3
--- /dev/null
+++ b/cli/tests/testdata/replace_self.js
@@ -0,0 +1,21 @@
+// Test that setting `self` in the main thread to some other value doesn't break
+// the world, in particular for events fired on the global scope.
+
+// deno-lint-ignore no-global-assign
+self = null;
+
+addEventListener("load", () => {
+ console.log("load event (event listener)");
+});
+
+addEventListener("unload", () => {
+ console.log("unload event (event listener)");
+});
+
+globalThis.onload = () => {
+ console.log("load event (event handler)");
+};
+
+globalThis.onunload = () => {
+ console.log("unload event (event handler)");
+};
diff --git a/cli/tests/testdata/replace_self.js.out b/cli/tests/testdata/replace_self.js.out
new file mode 100644
index 000000000..aaffb5a62
--- /dev/null
+++ b/cli/tests/testdata/replace_self.js.out
@@ -0,0 +1,4 @@
+load event (event listener)
+load event (event handler)
+unload event (event listener)
+unload event (event handler)
diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js
index 32732923b..a895b0c57 100644
--- a/runtime/js/99_main.js
+++ b/runtime/js/99_main.js
@@ -475,7 +475,7 @@ delete Object.prototype.__proto__;
location: location.locationDescriptor,
Window: globalInterfaces.windowConstructorDescriptor,
window: util.readOnly(globalThis),
- self: util.readOnly(globalThis),
+ self: util.writable(globalThis),
Navigator: util.nonEnumerable(Navigator),
navigator: {
configurable: true,
@@ -628,7 +628,7 @@ delete Object.prototype.__proto__;
ObjectDefineProperties(globalThis, unstableWindowOrWorkerGlobalScope);
}
ObjectDefineProperties(globalThis, workerRuntimeGlobalProperties);
- ObjectDefineProperties(globalThis, { name: util.readOnly(name) });
+ ObjectDefineProperties(globalThis, { name: util.writable(name) });
if (runtimeOptions.enableTestingFeaturesFlag) {
ObjectDefineProperty(
globalThis,
diff --git a/tools/wpt/expectation.json b/tools/wpt/expectation.json
index 511e1ddad..8e631f471 100644
--- a/tools/wpt/expectation.json
+++ b/tools/wpt/expectation.json
@@ -27840,7 +27840,7 @@
"headers-normalize.any.html": true,
"headers-record.any.html": true,
"headers-structure.any.html": true,
- "headers-basic.any.worker.html": false,
+ "headers-basic.any.worker.html": true,
"headers-casing.any.worker.html": true,
"headers-combine.any.worker.html": true,
"headers-errors.any.worker.html": true,