1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-21 23:04:45 -05:00

chore: Added onbeforeunload to window type definition (#16251)

This commit is contained in:
Matt Ezell 2022-10-13 03:47:47 -05:00 committed by GitHub
parent ba3d0da6ab
commit 06ccb6d41e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 3 deletions

View file

@ -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:

View file

@ -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");

View file

@ -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)

View file

@ -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`);

View file

@ -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");