diff --git a/baselines/dom.generated.d.ts b/baselines/dom.generated.d.ts index 4c6832a09..c29e71393 100644 --- a/baselines/dom.generated.d.ts +++ b/baselines/dom.generated.d.ts @@ -15096,7 +15096,7 @@ interface GlobalEventHandlersEventMap { "durationchange": Event; "emptied": Event; "ended": Event; - "error": ErrorEvent; + "error": Event; "focus": FocusEvent; "focusin": FocusEvent; "focusout": FocusEvent; @@ -15237,7 +15237,7 @@ interface GlobalEventHandlers { /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/ended_event) */ onended: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/error_event) */ - onerror: OnErrorEventHandler; + onerror: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/focus_event) */ onfocus: ((this: GlobalEventHandlers, ev: FocusEvent) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLFormElement/formdata_event) */ @@ -39460,6 +39460,7 @@ interface WindowEventMap extends GlobalEventHandlersEventMap, WindowEventHandler "devicemotion": DeviceMotionEvent; "deviceorientation": DeviceOrientationEvent; "deviceorientationabsolute": DeviceOrientationEvent; + "error": ErrorEvent; "gamepadconnected": GamepadEvent; "gamepaddisconnected": GamepadEvent; "orientationchange": Event; @@ -39612,6 +39613,8 @@ interface Window extends EventTarget, AnimationFrameProvider, GlobalEventHandler * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/deviceorientationabsolute_event) */ ondeviceorientationabsolute: ((this: Window, ev: DeviceOrientationEvent) => any) | null; + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/error_event) */ + onerror: OnErrorEventHandler; /** * @deprecated * @@ -41794,6 +41797,8 @@ declare var ondeviceorientation: ((this: Window, ev: DeviceOrientationEvent) => * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/deviceorientationabsolute_event) */ declare var ondeviceorientationabsolute: ((this: Window, ev: DeviceOrientationEvent) => any) | null; +/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/error_event) */ +declare var onerror: OnErrorEventHandler; /** * @deprecated * @@ -42174,8 +42179,6 @@ declare var ondurationchange: ((this: Window, ev: Event) => any) | null; declare var onemptied: ((this: Window, ev: Event) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/ended_event) */ declare var onended: ((this: Window, ev: Event) => any) | null; -/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/error_event) */ -declare var onerror: OnErrorEventHandler; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/focus_event) */ declare var onfocus: ((this: Window, ev: FocusEvent) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLFormElement/formdata_event) */ diff --git a/baselines/ts5.5/dom.generated.d.ts b/baselines/ts5.5/dom.generated.d.ts index c3864e232..4767e26e2 100644 --- a/baselines/ts5.5/dom.generated.d.ts +++ b/baselines/ts5.5/dom.generated.d.ts @@ -15082,7 +15082,7 @@ interface GlobalEventHandlersEventMap { "durationchange": Event; "emptied": Event; "ended": Event; - "error": ErrorEvent; + "error": Event; "focus": FocusEvent; "focusin": FocusEvent; "focusout": FocusEvent; @@ -15223,7 +15223,7 @@ interface GlobalEventHandlers { /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/ended_event) */ onended: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/error_event) */ - onerror: OnErrorEventHandler; + onerror: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/focus_event) */ onfocus: ((this: GlobalEventHandlers, ev: FocusEvent) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLFormElement/formdata_event) */ @@ -39434,6 +39434,7 @@ interface WindowEventMap extends GlobalEventHandlersEventMap, WindowEventHandler "devicemotion": DeviceMotionEvent; "deviceorientation": DeviceOrientationEvent; "deviceorientationabsolute": DeviceOrientationEvent; + "error": ErrorEvent; "gamepadconnected": GamepadEvent; "gamepaddisconnected": GamepadEvent; "orientationchange": Event; @@ -39586,6 +39587,8 @@ interface Window extends EventTarget, AnimationFrameProvider, GlobalEventHandler * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/deviceorientationabsolute_event) */ ondeviceorientationabsolute: ((this: Window, ev: DeviceOrientationEvent) => any) | null; + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/error_event) */ + onerror: OnErrorEventHandler; /** * @deprecated * @@ -41768,6 +41771,8 @@ declare var ondeviceorientation: ((this: Window, ev: DeviceOrientationEvent) => * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/deviceorientationabsolute_event) */ declare var ondeviceorientationabsolute: ((this: Window, ev: DeviceOrientationEvent) => any) | null; +/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/error_event) */ +declare var onerror: OnErrorEventHandler; /** * @deprecated * @@ -42148,8 +42153,6 @@ declare var ondurationchange: ((this: Window, ev: Event) => any) | null; declare var onemptied: ((this: Window, ev: Event) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/ended_event) */ declare var onended: ((this: Window, ev: Event) => any) | null; -/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/error_event) */ -declare var onerror: OnErrorEventHandler; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/focus_event) */ declare var onfocus: ((this: Window, ev: FocusEvent) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLFormElement/formdata_event) */ diff --git a/baselines/ts5.6/dom.generated.d.ts b/baselines/ts5.6/dom.generated.d.ts index a45b90495..f5b0586db 100644 --- a/baselines/ts5.6/dom.generated.d.ts +++ b/baselines/ts5.6/dom.generated.d.ts @@ -15093,7 +15093,7 @@ interface GlobalEventHandlersEventMap { "durationchange": Event; "emptied": Event; "ended": Event; - "error": ErrorEvent; + "error": Event; "focus": FocusEvent; "focusin": FocusEvent; "focusout": FocusEvent; @@ -15234,7 +15234,7 @@ interface GlobalEventHandlers { /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/ended_event) */ onended: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/error_event) */ - onerror: OnErrorEventHandler; + onerror: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/focus_event) */ onfocus: ((this: GlobalEventHandlers, ev: FocusEvent) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLFormElement/formdata_event) */ @@ -39457,6 +39457,7 @@ interface WindowEventMap extends GlobalEventHandlersEventMap, WindowEventHandler "devicemotion": DeviceMotionEvent; "deviceorientation": DeviceOrientationEvent; "deviceorientationabsolute": DeviceOrientationEvent; + "error": ErrorEvent; "gamepadconnected": GamepadEvent; "gamepaddisconnected": GamepadEvent; "orientationchange": Event; @@ -39609,6 +39610,8 @@ interface Window extends EventTarget, AnimationFrameProvider, GlobalEventHandler * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/deviceorientationabsolute_event) */ ondeviceorientationabsolute: ((this: Window, ev: DeviceOrientationEvent) => any) | null; + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/error_event) */ + onerror: OnErrorEventHandler; /** * @deprecated * @@ -41791,6 +41794,8 @@ declare var ondeviceorientation: ((this: Window, ev: DeviceOrientationEvent) => * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/deviceorientationabsolute_event) */ declare var ondeviceorientationabsolute: ((this: Window, ev: DeviceOrientationEvent) => any) | null; +/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/error_event) */ +declare var onerror: OnErrorEventHandler; /** * @deprecated * @@ -42171,8 +42176,6 @@ declare var ondurationchange: ((this: Window, ev: Event) => any) | null; declare var onemptied: ((this: Window, ev: Event) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/ended_event) */ declare var onended: ((this: Window, ev: Event) => any) | null; -/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/error_event) */ -declare var onerror: OnErrorEventHandler; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/focus_event) */ declare var onfocus: ((this: Window, ev: FocusEvent) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLFormElement/formdata_event) */ diff --git a/baselines/ts5.9/dom.generated.d.ts b/baselines/ts5.9/dom.generated.d.ts index ff1be1358..294332547 100644 --- a/baselines/ts5.9/dom.generated.d.ts +++ b/baselines/ts5.9/dom.generated.d.ts @@ -15093,7 +15093,7 @@ interface GlobalEventHandlersEventMap { "durationchange": Event; "emptied": Event; "ended": Event; - "error": ErrorEvent; + "error": Event; "focus": FocusEvent; "focusin": FocusEvent; "focusout": FocusEvent; @@ -15234,7 +15234,7 @@ interface GlobalEventHandlers { /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/ended_event) */ onended: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/error_event) */ - onerror: OnErrorEventHandler; + onerror: ((this: GlobalEventHandlers, ev: Event) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/focus_event) */ onfocus: ((this: GlobalEventHandlers, ev: FocusEvent) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLFormElement/formdata_event) */ @@ -39457,6 +39457,7 @@ interface WindowEventMap extends GlobalEventHandlersEventMap, WindowEventHandler "devicemotion": DeviceMotionEvent; "deviceorientation": DeviceOrientationEvent; "deviceorientationabsolute": DeviceOrientationEvent; + "error": ErrorEvent; "gamepadconnected": GamepadEvent; "gamepaddisconnected": GamepadEvent; "orientationchange": Event; @@ -39609,6 +39610,8 @@ interface Window extends EventTarget, AnimationFrameProvider, GlobalEventHandler * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/deviceorientationabsolute_event) */ ondeviceorientationabsolute: ((this: Window, ev: DeviceOrientationEvent) => any) | null; + /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/error_event) */ + onerror: OnErrorEventHandler; /** * @deprecated * @@ -41791,6 +41794,8 @@ declare var ondeviceorientation: ((this: Window, ev: DeviceOrientationEvent) => * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/deviceorientationabsolute_event) */ declare var ondeviceorientationabsolute: ((this: Window, ev: DeviceOrientationEvent) => any) | null; +/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/error_event) */ +declare var onerror: OnErrorEventHandler; /** * @deprecated * @@ -42171,8 +42176,6 @@ declare var ondurationchange: ((this: Window, ev: Event) => any) | null; declare var onemptied: ((this: Window, ev: Event) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/ended_event) */ declare var onended: ((this: Window, ev: Event) => any) | null; -/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLElement/error_event) */ -declare var onerror: OnErrorEventHandler; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/focus_event) */ declare var onfocus: ((this: Window, ev: FocusEvent) => any) | null; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLFormElement/formdata_event) */ diff --git a/inputfiles/patches/events.kdl b/inputfiles/patches/events.kdl index 4d11ba797..0a790de2b 100644 --- a/inputfiles/patches/events.kdl +++ b/inputfiles/patches/events.kdl @@ -29,7 +29,7 @@ interface-mixin GlobalEventHandlers { event dragover type=DragEvent event dragstart type=DragEvent event drop type=DragEvent - event error type=ErrorEvent + event error type=Event event focus type=FocusEvent event focusin type=FocusEvent event focusout type=FocusEvent @@ -76,7 +76,6 @@ interface-mixin GlobalEventHandlers { event transitionstart type=TransitionEvent event transitionend type=TransitionEvent event transitioncancel type=TransitionEvent - property onerror overrideType=OnErrorEventHandler } interface-mixin MessageEventTarget { @@ -109,6 +108,8 @@ interface Window { event gamepadconnected type=GamepadEvent event gamepaddisconnected type=GamepadEvent event DOMContentLoaded type=Event + event error type=ErrorEvent + property onerror overrideType="OnErrorEventHandler" mdnUrl="https://developer.mozilla.org/docs/Web/API/Window/error_event" } interface WorkerGlobalScope { diff --git a/src/build/emitter.ts b/src/build/emitter.ts index d09597bdc..89486c319 100644 --- a/src/build/emitter.ts +++ b/src/build/emitter.ts @@ -996,13 +996,20 @@ export function emitWebIdl( prefix: string, emitScope: EmitScope, i: Browser.Interface, + emittedProperties?: Set, ) { if (i.properties) { mapToArray(i.properties.property) .filter((m) => matchScope(emitScope, m)) .filter((p) => !isCovariantEventHandler(i, p)) + .filter((p) => !emittedProperties || !emittedProperties.has(p.name)) .sort(compareName) - .forEach((p) => emitProperty(prefix, i, emitScope, p)); + .forEach((p) => { + emitProperty(prefix, i, emitScope, p); + if (emittedProperties) { + emittedProperties.add(p.name); + } + }); } } @@ -1148,11 +1155,12 @@ export function emitWebIdl( prefix: string, emitScope: EmitScope, i: Browser.Interface, + emittedProperties?: Set, ) { const conflictedMembers = extendConflictsBaseTypes[i.name] ? extendConflictsBaseTypes[i.name].memberNames : new Set(); - emitProperties(prefix, emitScope, i); + emitProperties(prefix, emitScope, i, emittedProperties); const methodPrefix = prefix.startsWith("declare var") ? "declare function " : ""; @@ -1164,13 +1172,21 @@ export function emitWebIdl( /// Emit all members of every interfaces at the root level. /// Called only once on the global polluter object - function emitAllMembers(i: Browser.Interface) { - emitMembers(/*prefix*/ "declare var ", "InstanceOnly", i); + function emitAllMembers( + i: Browser.Interface, + emittedProperties: Set = new Set(), + ) { + emitMembers( + /*prefix*/ "declare var ", + "InstanceOnly", + i, + emittedProperties, + ); for (const relatedIName of iNameToIDependList[i.name]) { const i = allInterfacesMap[relatedIName]; if (i) { - emitAllMembers(i); + emitAllMembers(i, emittedProperties); } } } diff --git a/unittests/files/eventlistener.ts b/unittests/files/eventlistener.ts index 021afbc3c..e79677e90 100644 --- a/unittests/files/eventlistener.ts +++ b/unittests/files/eventlistener.ts @@ -1,9 +1,54 @@ -document.addEventListener("arbitrary_invalid_event", (ev) => { - return ev.returnValue; -}); - document.addEventListener("arbitrary_invalid_event", { handleEvent(ev) { return ev.returnValue; + }, +}); +const divElement: HTMLElement = document.createElement("div"); + +/** + * addEventListener works with a single event arg, Event + */ +divElement.addEventListener( + "click", + (event: Event) => { + if (event) { + return; + } + }, + false, +); +/** + * HTMLElement addEventListener works with a custom string and single event arg, Event + */ +divElement.addEventListener("beep", (event: Event) => { + if (event) { + return; + } +}); + +const svgElement = document.createElementNS( + "http://www.w3.org/2000/svg", + "svg", +); + +/** + * SVGElement addEventListener works with a single event arg, Event + */ +svgElement.addEventListener( + "click", + (event: Event) => { + if (event) { + return; + } + }, + false, +); + +/** + * SVGElement addEventListener works with a custom string and single event arg, Event + */ +svgElement.addEventListener("beep", (event: Event) => { + if (event) { + return; } }); diff --git a/unittests/files/onerror.ts b/unittests/files/onerror.ts new file mode 100644 index 000000000..a524c2761 --- /dev/null +++ b/unittests/files/onerror.ts @@ -0,0 +1,40 @@ +/** + * window.onerror works as intended with global event handler + */ +window.onerror = (message, src, lineno, colno, error) => { + if (message && src && lineno && colno && error) { + return; + } +}; + +const div: HTMLElement = document.createElement("div"); + +/** + * HTMLElement.onerror works with a single event arg, Event + */ +div.onerror = (event: Event) => { + if (event) { + return; + } +}; + +/** + * HTMLElement onerror is nullable + */ +div.onerror = null; + +const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg"); + +/** + * SVGElement.onerror works with a single event arg, Event + */ +svg.onerror = (event: Event) => { + if (event) { + return; + } +}; + +/** + * SVGElement onerror is nullable + */ +svg.onerror = null; \ No newline at end of file