mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 07:14:47 -05:00
chore: Added onbeforeunload to window type definition (#16251)
This commit is contained in:
parent
ba3d0da6ab
commit
06ccb6d41e
5 changed files with 19 additions and 3 deletions
3
cli/dts/lib.deno.window.d.ts
vendored
3
cli/dts/lib.deno.window.d.ts
vendored
|
@ -21,6 +21,7 @@ declare class Window extends EventTarget {
|
||||||
readonly self: Window & typeof globalThis;
|
readonly self: Window & typeof globalThis;
|
||||||
onerror: ((this: Window, ev: ErrorEvent) => any) | null;
|
onerror: ((this: Window, ev: ErrorEvent) => any) | null;
|
||||||
onload: ((this: Window, ev: Event) => any) | null;
|
onload: ((this: Window, ev: Event) => any) | null;
|
||||||
|
onbeforeunload: ((this: Window, ev: Event) => any) | null;
|
||||||
onunload: ((this: Window, ev: Event) => any) | null;
|
onunload: ((this: Window, ev: Event) => any) | null;
|
||||||
onunhandledrejection:
|
onunhandledrejection:
|
||||||
| ((this: Window, ev: PromiseRejectionEvent) => any)
|
| ((this: Window, ev: PromiseRejectionEvent) => any)
|
||||||
|
@ -76,6 +77,8 @@ declare var onerror: ((this: Window, ev: ErrorEvent) => any) | null;
|
||||||
/** @category DOM Events */
|
/** @category DOM Events */
|
||||||
declare var onload: ((this: Window, ev: Event) => any) | null;
|
declare var onload: ((this: Window, ev: Event) => any) | null;
|
||||||
/** @category DOM Events */
|
/** @category DOM Events */
|
||||||
|
declare var onbeforeunload: ((this: Window, ev: Event) => any) | null;
|
||||||
|
/** @category DOM Events */
|
||||||
declare var onunload: ((this: Window, ev: Event) => any) | null;
|
declare var onunload: ((this: Window, ev: Event) => any) | null;
|
||||||
/** @category Observability */
|
/** @category Observability */
|
||||||
declare var onunhandledrejection:
|
declare var onunhandledrejection:
|
||||||
|
|
3
cli/tests/testdata/run/onload/imported.ts
vendored
3
cli/tests/testdata/run/onload/imported.ts
vendored
|
@ -3,10 +3,11 @@ import { assert } from "../../../../../test_util/std/testing/asserts.ts";
|
||||||
import "./nest_imported.ts";
|
import "./nest_imported.ts";
|
||||||
|
|
||||||
const handler = (e: Event) => {
|
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)`);
|
console.log(`got ${e.type} event in event handler (imported)`);
|
||||||
};
|
};
|
||||||
|
|
||||||
window.addEventListener("load", handler);
|
window.addEventListener("load", handler);
|
||||||
|
window.addEventListener("beforeunload", handler);
|
||||||
window.addEventListener("unload", handler);
|
window.addEventListener("unload", handler);
|
||||||
console.log("log from imported script");
|
console.log("log from imported script");
|
||||||
|
|
4
cli/tests/testdata/run/onload/main.out
vendored
4
cli/tests/testdata/run/onload/main.out
vendored
|
@ -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 (imported)
|
||||||
got load event in event handler (main)
|
got load event in event handler (main)
|
||||||
got load event in onload function
|
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 (nest_imported)
|
||||||
got unload event in event handler (imported)
|
got unload event in event handler (imported)
|
||||||
got unload event in event handler (main)
|
got unload event in event handler (main)
|
||||||
|
|
9
cli/tests/testdata/run/onload/main.ts
vendored
9
cli/tests/testdata/run/onload/main.ts
vendored
|
@ -6,12 +6,14 @@ assert(window.hasOwnProperty("onload"));
|
||||||
assert(window.onload === null);
|
assert(window.onload === null);
|
||||||
|
|
||||||
const eventHandler = (e: Event) => {
|
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)`);
|
console.log(`got ${e.type} event in event handler (main)`);
|
||||||
};
|
};
|
||||||
|
|
||||||
window.addEventListener("load", eventHandler);
|
window.addEventListener("load", eventHandler);
|
||||||
|
|
||||||
|
window.addEventListener("beforeunload", eventHandler);
|
||||||
|
|
||||||
window.addEventListener("unload", eventHandler);
|
window.addEventListener("unload", eventHandler);
|
||||||
|
|
||||||
window.onload = (e: Event) => {
|
window.onload = (e: Event) => {
|
||||||
|
@ -19,6 +21,11 @@ window.onload = (e: Event) => {
|
||||||
console.log(`got ${e.type} event in onload function`);
|
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) => {
|
window.onunload = (e: Event) => {
|
||||||
assert(!e.cancelable);
|
assert(!e.cancelable);
|
||||||
console.log(`got ${e.type} event in onunload function`);
|
console.log(`got ${e.type} event in onunload function`);
|
||||||
|
|
|
@ -2,10 +2,11 @@
|
||||||
import { assert } from "../../../../../test_util/std/testing/asserts.ts";
|
import { assert } from "../../../../../test_util/std/testing/asserts.ts";
|
||||||
|
|
||||||
const handler = (e: Event) => {
|
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)`);
|
console.log(`got ${e.type} event in event handler (nest_imported)`);
|
||||||
};
|
};
|
||||||
|
|
||||||
window.addEventListener("load", handler);
|
window.addEventListener("load", handler);
|
||||||
|
window.addEventListener("beforeunload", handler);
|
||||||
window.addEventListener("unload", handler);
|
window.addEventListener("unload", handler);
|
||||||
console.log("log from nest_imported script");
|
console.log("log from nest_imported script");
|
||||||
|
|
Loading…
Reference in a new issue