Skip to content

Commit

Permalink
events: check signal before listener
Browse files Browse the repository at this point in the history
In WPT Events, TypeError is expected if both listener and
signal are null. But checking listener doesn't throw TypeError.
So check signal before listener because checking signal throws
TypeError if signal is null.

PR-URL: #46054
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
  • Loading branch information
deokjinkim authored and RafaelGSS committed Jan 20, 2023
1 parent 8684dae commit 3dcdab3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/internal/event_target.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,8 @@ class EventTarget {
weak,
} = validateEventListenerOptions(options);

validateAbortSignal(signal, 'options.signal');

if (!validateEventListener(listener)) {
// The DOM silently allows passing undefined as a second argument
// No error code for this since it is a Warning
Expand All @@ -575,8 +577,6 @@ class EventTarget {
}
type = String(type);

validateAbortSignal(signal, 'options.signal');

if (signal) {
if (signal.aborted) {
return;
Expand Down
7 changes: 0 additions & 7 deletions test/wpt/status/dom/events.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@
]
}
},
"AddEventListenerOptions-signal.any.js": {
"fail": {
"expected": [
"Passing null as the signal should throw (listener is also null)"
]
}
},
"Event-constructors.any.js": {
"fail": {
"expected": [
Expand Down

0 comments on commit 3dcdab3

Please sign in to comment.