From c920c5f62aba7eee0f6fa70f68f701e204ac1a9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 2 Oct 2019 17:32:51 +0200 Subject: feat: window.onunload (#3023) --- js/globals.ts | 11 +++++++++++ js/lib.deno_runtime.d.ts | 2 ++ 2 files changed, 13 insertions(+) (limited to 'js') diff --git a/js/globals.ts b/js/globals.ts index 50f119971..b734b8da3 100644 --- a/js/globals.ts +++ b/js/globals.ts @@ -84,6 +84,7 @@ window.setTimeout = timers.setTimeout; window.setInterval = timers.setInterval; window.location = (undefined as unknown) as domTypes.Location; window.onload = undefined as undefined | Function; +window.onunload = undefined as undefined | Function; // The following Crypto interface implementation is not up to par with the // standard https://www.w3.org/TR/WebCryptoAPI/#crypto-interface as it does not // yet incorporate the SubtleCrypto interface as its "subtle" property. @@ -171,6 +172,16 @@ window.addEventListener( } } ); +// Registers the handler for window.onunload function. +window.addEventListener( + "unload", + (e: domTypes.Event): void => { + const onunload = window.onunload; + if (typeof onunload === "function") { + onunload(e); + } + } +); // below are interfaces that are available in TypeScript but // have different signatures diff --git a/js/lib.deno_runtime.d.ts b/js/lib.deno_runtime.d.ts index 1e220a29d..d0a720769 100644 --- a/js/lib.deno_runtime.d.ts +++ b/js/lib.deno_runtime.d.ts @@ -1248,6 +1248,7 @@ declare interface Window { setInterval: typeof timers.setInterval; location: domTypes.Location; onload: Function | undefined; + onunload: Function | undefined; crypto: Crypto; Blob: typeof blob.DenoBlob; File: domTypes.DomFileConstructor; @@ -1294,6 +1295,7 @@ declare const setTimeout: typeof timers.setTimeout; declare const setInterval: typeof timers.setInterval; declare const location: domTypes.Location; declare const onload: Function | undefined; +declare const onunload: Function | undefined; declare const crypto: Crypto; declare const Blob: typeof blob.DenoBlob; declare const File: domTypes.DomFileConstructor; -- cgit v1.2.3