summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/dts/lib.deno.window.d.ts3
-rw-r--r--cli/tests/testdata/run/onload/imported.ts3
-rw-r--r--cli/tests/testdata/run/onload/main.out4
-rw-r--r--cli/tests/testdata/run/onload/main.ts9
-rw-r--r--cli/tests/testdata/run/onload/nest_imported.ts3
5 files changed, 19 insertions, 3 deletions
diff --git a/cli/dts/lib.deno.window.d.ts b/cli/dts/lib.deno.window.d.ts
index 9515f5b23..77204fcbd 100644
--- a/cli/dts/lib.deno.window.d.ts
+++ b/cli/dts/lib.deno.window.d.ts
@@ -21,6 +21,7 @@ declare class Window extends EventTarget {
readonly self: Window & typeof globalThis;
onerror: ((this: Window, ev: ErrorEvent) => any) | null;
onload: ((this: Window, ev: Event) => any) | null;
+ onbeforeunload: ((this: Window, ev: Event) => any) | null;
onunload: ((this: Window, ev: Event) => any) | null;
onunhandledrejection:
| ((this: Window, ev: PromiseRejectionEvent) => any)
@@ -76,6 +77,8 @@ declare var onerror: ((this: Window, ev: ErrorEvent) => any) | null;
/** @category DOM Events */
declare var onload: ((this: Window, ev: Event) => any) | null;
/** @category DOM Events */
+declare var onbeforeunload: ((this: Window, ev: Event) => any) | null;
+/** @category DOM Events */
declare var onunload: ((this: Window, ev: Event) => any) | null;
/** @category Observability */
declare var onunhandledrejection:
diff --git a/cli/tests/testdata/run/onload/imported.ts b/cli/tests/testdata/run/onload/imported.ts
index 969f97e56..f4157b86f 100644
--- a/cli/tests/testdata/run/onload/imported.ts
+++ b/cli/tests/testdata/run/onload/imported.ts
@@ -3,10 +3,11 @@ import { assert } from "../../../../../test_util/std/testing/asserts.ts";
import "./nest_imported.ts";
const handler = (e: Event) => {
- assert(!e.cancelable);
+ assert(e.type === "beforeunload" ? e.cancelable : !e.cancelable);
console.log(`got ${e.type} event in event handler (imported)`);
};
window.addEventListener("load", handler);
+window.addEventListener("beforeunload", handler);
window.addEventListener("unload", handler);
console.log("log from imported script");
diff --git a/cli/tests/testdata/run/onload/main.out b/cli/tests/testdata/run/onload/main.out
index 9b1f454c9..b25d33fa8 100644
--- a/cli/tests/testdata/run/onload/main.out
+++ b/cli/tests/testdata/run/onload/main.out
@@ -5,6 +5,10 @@ got load event in event handler (nest_imported)
got load event in event handler (imported)
got load event in event handler (main)
got load event in onload function
+got beforeunload event in event handler (nest_imported)
+got beforeunload event in event handler (imported)
+got beforeunload event in event handler (main)
+got beforeunload event in onbeforeunload function
got unload event in event handler (nest_imported)
got unload event in event handler (imported)
got unload event in event handler (main)
diff --git a/cli/tests/testdata/run/onload/main.ts b/cli/tests/testdata/run/onload/main.ts
index 798b8aa7b..126627e34 100644
--- a/cli/tests/testdata/run/onload/main.ts
+++ b/cli/tests/testdata/run/onload/main.ts
@@ -6,12 +6,14 @@ assert(window.hasOwnProperty("onload"));
assert(window.onload === null);
const eventHandler = (e: Event) => {
- assert(!e.cancelable);
+ assert(e.type === "beforeunload" ? e.cancelable : !e.cancelable);
console.log(`got ${e.type} event in event handler (main)`);
};
window.addEventListener("load", eventHandler);
+window.addEventListener("beforeunload", eventHandler);
+
window.addEventListener("unload", eventHandler);
window.onload = (e: Event) => {
@@ -19,6 +21,11 @@ window.onload = (e: Event) => {
console.log(`got ${e.type} event in onload function`);
};
+window.onbeforeunload = (e: BeforeUnloadEvent) => {
+ assert(e.cancelable);
+ console.log(`got ${e.type} event in onbeforeunload function`);
+};
+
window.onunload = (e: Event) => {
assert(!e.cancelable);
console.log(`got ${e.type} event in onunload function`);
diff --git a/cli/tests/testdata/run/onload/nest_imported.ts b/cli/tests/testdata/run/onload/nest_imported.ts
index 351a3cb22..a942d2729 100644
--- a/cli/tests/testdata/run/onload/nest_imported.ts
+++ b/cli/tests/testdata/run/onload/nest_imported.ts
@@ -2,10 +2,11 @@
import { assert } from "../../../../../test_util/std/testing/asserts.ts";
const handler = (e: Event) => {
- assert(!e.cancelable);
+ assert(e.type === "beforeunload" ? e.cancelable : !e.cancelable);
console.log(`got ${e.type} event in event handler (nest_imported)`);
};
window.addEventListener("load", handler);
+window.addEventListener("beforeunload", handler);
window.addEventListener("unload", handler);
console.log("log from nest_imported script");