2024-08-28 19:56:15 -04:00
|
|
|
// deno-lint-ignore-file no-prototype-builtins
|
2024-07-25 01:30:28 -04:00
|
|
|
import { assert } from "@std/assert";
|
2019-07-16 00:19:26 -04:00
|
|
|
import "./imported.ts";
|
|
|
|
|
2024-08-28 19:56:15 -04:00
|
|
|
assert(globalThis.hasOwnProperty("onload"));
|
|
|
|
assert(globalThis.onload === null);
|
2020-12-07 15:22:58 -05:00
|
|
|
|
2021-08-05 07:08:58 -04:00
|
|
|
const eventHandler = (e: Event) => {
|
2022-10-13 04:47:47 -04:00
|
|
|
assert(e.type === "beforeunload" ? e.cancelable : !e.cancelable);
|
2019-10-02 11:32:51 -04:00
|
|
|
console.log(`got ${e.type} event in event handler (main)`);
|
|
|
|
};
|
|
|
|
|
2024-08-28 19:56:15 -04:00
|
|
|
globalThis.addEventListener("load", eventHandler);
|
2019-10-02 11:32:51 -04:00
|
|
|
|
2024-08-28 19:56:15 -04:00
|
|
|
globalThis.addEventListener("beforeunload", eventHandler);
|
2022-10-13 04:47:47 -04:00
|
|
|
|
2024-08-28 19:56:15 -04:00
|
|
|
globalThis.addEventListener("unload", eventHandler);
|
2019-07-16 00:19:26 -04:00
|
|
|
|
2024-08-28 19:56:15 -04:00
|
|
|
globalThis.onload = (e: Event) => {
|
2019-10-02 11:32:51 -04:00
|
|
|
assert(!e.cancelable);
|
2019-07-16 00:19:26 -04:00
|
|
|
console.log(`got ${e.type} event in onload function`);
|
|
|
|
};
|
|
|
|
|
2024-08-28 19:56:15 -04:00
|
|
|
globalThis.onbeforeunload = (e: BeforeUnloadEvent) => {
|
2022-10-13 04:47:47 -04:00
|
|
|
assert(e.cancelable);
|
|
|
|
console.log(`got ${e.type} event in onbeforeunload function`);
|
|
|
|
};
|
|
|
|
|
2024-08-28 19:56:15 -04:00
|
|
|
globalThis.onunload = (e: Event) => {
|
2019-10-02 11:32:51 -04:00
|
|
|
assert(!e.cancelable);
|
|
|
|
console.log(`got ${e.type} event in onunload function`);
|
|
|
|
};
|
|
|
|
|
2019-07-16 00:19:26 -04:00
|
|
|
console.log("log from main");
|