1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-28 10:09:20 -05:00
denoland-deno/cli/tests/testdata/replace_self.js
Andreu Botella fbcbbd7ae3
fix(runtime): Declare Window.self and DedicatedWorkerGlobalScope.name with util.writable() (#12378)
`Window`'s `self` property and `DedicatedWorkerGlobalScope`'s `name`
property are defined as Web IDL read-only attributes with the
`[Replaceable]` extended attribute, meaning that their setter will
redefine the property as a data property with the set value, rather than
changing some internal state. Deno currently defines them as read-only
data properties instead.

Given that Web IDL requires all attributes to be accessor properties
rather than data properties, but Deno exposes almost all of those
properties as either read-only or writable data properties, it makes
sense to expose `[Replaceable]` properties as writable as well – as is
already the case with `WindowOrWorkerGlobalScope`'s `performance`
property.
2021-10-11 18:50:18 +02:00

21 lines
528 B
JavaScript

// 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)");
};