Skip to content

Commit 03fb789

Browse files
authored
events: add null check for the signal of EventTarget
This will improve the Web compatibility. Passing null as the signal should throw an error. WPT says "Passing null as the signal should throw". Please see https://github.com/web-platform-tests/wpt/blob/master/dom/events/AddEventListenerOptions-signal.any.js PR-URL: #43153 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 4884746 commit 03fb789

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

lib/internal/event_target.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const {
3434
ERR_INVALID_THIS,
3535
}
3636
} = require('internal/errors');
37-
const { validateObject, validateString, validateInternalField } = require('internal/validators');
37+
const { validateAbortSignal, validateObject, validateString, validateInternalField } = require('internal/validators');
3838

3939
const {
4040
customInspectSymbol,
@@ -575,6 +575,8 @@ class EventTarget {
575575
}
576576
type = String(type);
577577

578+
validateAbortSignal(signal, 'options.signal');
579+
578580
if (signal) {
579581
if (signal.aborted) {
580582
return;

test/parallel/test-whatwg-events-add-event-listener-options-signal.js

+9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ require('../common');
44

55
const {
66
strictEqual,
7+
throws,
78
} = require('assert');
89

910
// Manually ported from: wpt@dom/events/AddEventListenerOptions-signal.any.js
@@ -157,3 +158,11 @@ const {
157158
}, { once: true });
158159
et.dispatchEvent(new Event('foo'));
159160
}
161+
{
162+
const et = new EventTarget();
163+
[1, 1n, {}, [], null, true, 'hi', Symbol(), () => {}].forEach((signal) => {
164+
throws(() => et.addEventListener('foo', () => {}, { signal }), {
165+
name: 'TypeError',
166+
});
167+
});
168+
}

test/wpt/status/dom/events.json

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
"AddEventListenerOptions-signal.any.js": {
1212
"fail": {
1313
"expected": [
14-
"Passing null as the signal should throw",
1514
"Passing null as the signal should throw (listener is also null)"
1615
]
1716
}

0 commit comments

Comments
 (0)