events: check signal before listener

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: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Deokjin Kim
2023-01-04 13:28:54 +09:00
committed by GitHub
parent 57048acedc
commit 5d4cb8464d
2 changed files with 2 additions and 9 deletions

View File

@@ -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
@@ -575,8 +577,6 @@ class EventTarget {
}
type = String(type);
validateAbortSignal(signal, 'options.signal');
if (signal) {
if (signal.aborted) {
return;

View File

@@ -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": [