Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions baselines/dom.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15096,7 +15096,7 @@ interface GlobalEventHandlersEventMap {
"durationchange": Event;
"emptied": Event;
"ended": Event;
"error": ErrorEvent;
"error": Event;
"focus": FocusEvent;
"focusin": FocusEvent;
"focusout": FocusEvent;
Expand Down Expand Up @@ -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) */
Expand Down Expand Up @@ -39460,6 +39460,7 @@ interface WindowEventMap extends GlobalEventHandlersEventMap, WindowEventHandler
"devicemotion": DeviceMotionEvent;
"deviceorientation": DeviceOrientationEvent;
"deviceorientationabsolute": DeviceOrientationEvent;
"error": ErrorEvent;
"gamepadconnected": GamepadEvent;
"gamepaddisconnected": GamepadEvent;
"orientationchange": Event;
Expand Down Expand Up @@ -39612,6 +39613,7 @@ 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;
onerror: OnErrorEventHandler;
/**
* @deprecated
*
Expand Down Expand Up @@ -41794,6 +41796,7 @@ 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;
declare var onerror: OnErrorEventHandler;
/**
* @deprecated
*
Expand Down Expand Up @@ -42174,8 +42177,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) */
Expand Down
9 changes: 5 additions & 4 deletions baselines/ts5.5/dom.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15082,7 +15082,7 @@ interface GlobalEventHandlersEventMap {
"durationchange": Event;
"emptied": Event;
"ended": Event;
"error": ErrorEvent;
"error": Event;
"focus": FocusEvent;
"focusin": FocusEvent;
"focusout": FocusEvent;
Expand Down Expand Up @@ -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) */
Expand Down Expand Up @@ -39434,6 +39434,7 @@ interface WindowEventMap extends GlobalEventHandlersEventMap, WindowEventHandler
"devicemotion": DeviceMotionEvent;
"deviceorientation": DeviceOrientationEvent;
"deviceorientationabsolute": DeviceOrientationEvent;
"error": ErrorEvent;
"gamepadconnected": GamepadEvent;
"gamepaddisconnected": GamepadEvent;
"orientationchange": Event;
Expand Down Expand Up @@ -39586,6 +39587,7 @@ 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;
onerror: OnErrorEventHandler;
/**
* @deprecated
*
Expand Down Expand Up @@ -41768,6 +41770,7 @@ 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;
declare var onerror: OnErrorEventHandler;
/**
* @deprecated
*
Expand Down Expand Up @@ -42148,8 +42151,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) */
Expand Down
9 changes: 5 additions & 4 deletions baselines/ts5.6/dom.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15093,7 +15093,7 @@ interface GlobalEventHandlersEventMap {
"durationchange": Event;
"emptied": Event;
"ended": Event;
"error": ErrorEvent;
"error": Event;
"focus": FocusEvent;
"focusin": FocusEvent;
"focusout": FocusEvent;
Expand Down Expand Up @@ -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) */
Expand Down Expand Up @@ -39457,6 +39457,7 @@ interface WindowEventMap extends GlobalEventHandlersEventMap, WindowEventHandler
"devicemotion": DeviceMotionEvent;
"deviceorientation": DeviceOrientationEvent;
"deviceorientationabsolute": DeviceOrientationEvent;
"error": ErrorEvent;
"gamepadconnected": GamepadEvent;
"gamepaddisconnected": GamepadEvent;
"orientationchange": Event;
Expand Down Expand Up @@ -39609,6 +39610,7 @@ 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;
onerror: OnErrorEventHandler;
/**
* @deprecated
*
Expand Down Expand Up @@ -41791,6 +41793,7 @@ 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;
declare var onerror: OnErrorEventHandler;
/**
* @deprecated
*
Expand Down Expand Up @@ -42171,8 +42174,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) */
Expand Down
9 changes: 5 additions & 4 deletions baselines/ts5.9/dom.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15093,7 +15093,7 @@ interface GlobalEventHandlersEventMap {
"durationchange": Event;
"emptied": Event;
"ended": Event;
"error": ErrorEvent;
"error": Event;
"focus": FocusEvent;
"focusin": FocusEvent;
"focusout": FocusEvent;
Expand Down Expand Up @@ -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) */
Expand Down Expand Up @@ -39457,6 +39457,7 @@ interface WindowEventMap extends GlobalEventHandlersEventMap, WindowEventHandler
"devicemotion": DeviceMotionEvent;
"deviceorientation": DeviceOrientationEvent;
"deviceorientationabsolute": DeviceOrientationEvent;
"error": ErrorEvent;
"gamepadconnected": GamepadEvent;
"gamepaddisconnected": GamepadEvent;
"orientationchange": Event;
Expand Down Expand Up @@ -39609,6 +39610,7 @@ 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;
onerror: OnErrorEventHandler;
/**
* @deprecated
*
Expand Down Expand Up @@ -41791,6 +41793,7 @@ 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;
declare var onerror: OnErrorEventHandler;
/**
* @deprecated
*
Expand Down Expand Up @@ -42171,8 +42174,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) */
Expand Down
13 changes: 13 additions & 0 deletions inputfiles/overridingTypes.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,22 @@
// making it nullable breaks compatibility as it has historically been non-nullable in TS lib.
// See the example in https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-parent.
"nullable": false
},
"onerror": {
"name": "onerror",
"overrideType": "OnErrorEventHandler",
"eventHandler": "error"
}
}
},
"events": {
"event": [
{
"name": "error",
"type": "ErrorEvent"
}
]
},
"methods": {
"method": {
"alert": {
Expand Down
3 changes: 1 addition & 2 deletions inputfiles/patches/events.kdl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
31 changes: 26 additions & 5 deletions src/build/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,12 @@ export function emitWebIdl(
// A covariant EventHandler is one that is defined in a parent interface as then redefined in current interface with a more specific argument types
// These patterns are unsafe, and flagged as error under --strictFunctionTypes.
// Here we know the property is already defined on the interface, we elide its declaration if the parent has the same handler defined
// Exception: if the property has an overrideType, we should emit it as an intentional override
function isCovariantEventHandler(i: Browser.Interface, p: Browser.Property) {
// If this property has an explicit overrideType, emit it (it's an intentional override)
if (p.overrideType) {
return false;
}
return (
isEventHandler(p) &&
iNameToEhParents[i.name].some((parent) =>
Expand Down Expand Up @@ -996,13 +1001,20 @@ export function emitWebIdl(
prefix: string,
emitScope: EmitScope,
i: Browser.Interface,
emittedProperties?: Set<string>,
) {
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);
}
});
}
}

Expand Down Expand Up @@ -1148,11 +1160,12 @@ export function emitWebIdl(
prefix: string,
emitScope: EmitScope,
i: Browser.Interface,
emittedProperties?: Set<string>,
) {
const conflictedMembers = extendConflictsBaseTypes[i.name]
? extendConflictsBaseTypes[i.name].memberNames
: new Set<string>();
emitProperties(prefix, emitScope, i);
emitProperties(prefix, emitScope, i, emittedProperties);
const methodPrefix = prefix.startsWith("declare var")
? "declare function "
: "";
Expand All @@ -1164,13 +1177,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<string> = 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);
}
}
}
Expand Down
53 changes: 49 additions & 4 deletions unittests/files/eventlistener.ts
Original file line number Diff line number Diff line change
@@ -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;
}
});
Loading