From 4d18f558e4cfebc5b8d9d594401e3ce74fc3226b Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Wed, 13 Apr 2022 10:50:57 +0100 Subject: feat(ext/web): Add error events for event listener and timer errors (#14159) - feat: Add handleable error event for even listener errors - feat: Add handleable error event for setTimeout()/setInterval() errors - feat: Add Deno.core.destructureError() - feat: Add Deno.core.terminate() - fix: Don't throw listener errors from dispatchEvent() - fix: Use biased mode when selecting between mod_evaluate() and run_event_loop() results --- cli/dts/lib.deno.window.d.ts | 55 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 4 deletions(-) (limited to 'cli/dts/lib.deno.window.d.ts') diff --git a/cli/dts/lib.deno.window.d.ts b/cli/dts/lib.deno.window.d.ts index fbd0a967b..d0e04a7a8 100644 --- a/cli/dts/lib.deno.window.d.ts +++ b/cli/dts/lib.deno.window.d.ts @@ -7,10 +7,15 @@ /// /// +interface WindowEventMap { + "error": ErrorEvent; +} + declare class Window extends EventTarget { new(): Window; readonly window: Window & typeof globalThis; readonly self: Window & typeof globalThis; + onerror: ((this: Window, ev: ErrorEvent) => any) | null; onload: ((this: Window, ev: Event) => any) | null; onunload: ((this: Window, ev: Event) => any) | null; close: () => void; @@ -25,10 +30,38 @@ declare class Window extends EventTarget { location: Location; localStorage: Storage; sessionStorage: Storage; + + addEventListener( + type: K, + listener: ( + this: Window, + ev: WindowEventMap[K], + ) => any, + options?: boolean | AddEventListenerOptions, + ): void; + addEventListener( + type: string, + listener: EventListenerOrEventListenerObject, + options?: boolean | AddEventListenerOptions, + ): void; + removeEventListener( + type: K, + listener: ( + this: Window, + ev: WindowEventMap[K], + ) => any, + options?: boolean | EventListenerOptions, + ): void; + removeEventListener( + type: string, + listener: EventListenerOrEventListenerObject, + options?: boolean | EventListenerOptions, + ): void; } declare var window: Window & typeof globalThis; declare var self: Window & typeof globalThis; +declare var onerror: ((this: Window, ev: ErrorEvent) => any) | null; declare var onload: ((this: Window, ev: Event) => any) | null; declare var onunload: ((this: Window, ev: Event) => any) | null; declare var localStorage: Storage; @@ -77,10 +110,17 @@ declare function prompt(message?: string, defaultValue?: string): string | null; * dispatchEvent(new Event('unload')); * ``` */ +declare function addEventListener< + K extends keyof WindowEventMap, +>( + type: K, + listener: (this: Window, ev: WindowEventMap[K]) => any, + options?: boolean | AddEventListenerOptions, +): void; declare function addEventListener( type: string, - callback: EventListenerOrEventListenerObject | null, - options?: boolean | AddEventListenerOptions | undefined, + listener: EventListenerOrEventListenerObject, + options?: boolean | AddEventListenerOptions, ): void; /** Remove a previously registered event listener from the global scope @@ -91,10 +131,17 @@ declare function addEventListener( * removeEventListener('load', listener); * ``` */ +declare function removeEventListener< + K extends keyof WindowEventMap, +>( + type: K, + listener: (this: Window, ev: WindowEventMap[K]) => any, + options?: boolean | EventListenerOptions, +): void; declare function removeEventListener( type: string, - callback: EventListenerOrEventListenerObject | null, - options?: boolean | EventListenerOptions | undefined, + listener: EventListenerOrEventListenerObject, + options?: boolean | EventListenerOptions, ): void; // TODO(nayeemrmn): Move this to `extensions/web` where its implementation is. -- cgit v1.2.3