Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
11 changes: 7 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,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
*
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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) */
Expand Down
11 changes: 7 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,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
*
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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) */
Expand Down
11 changes: 7 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,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
*
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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) */
Expand Down
11 changes: 7 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,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
*
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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) */
Expand Down
5 changes: 3 additions & 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 Expand Up @@ -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 {
Expand Down
26 changes: 21 additions & 5 deletions src/build/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -996,13 +996,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 +1155,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 +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<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;
}
});
40 changes: 40 additions & 0 deletions unittests/files/onerror.ts
Original file line number Diff line number Diff line change
@@ -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;