Skip to content

Commit 68d5c2e

Browse files
committed
events: add null check for the signal of EventTarget
To improve 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
1 parent 20268c7 commit 68d5c2e

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

lib/internal/event_target.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,10 @@ class EventTarget {
482482
}
483483
type = String(type);
484484

485+
if (signal === null) {
486+
throw new ERR_INVALID_ARG_TYPE('options.signal', 'AbortSignal', signal);
487+
}
488+
485489
if (signal) {
486490
if (signal.aborted) {
487491
return;

test/parallel/test-eventtarget-whatwg-signal.js

Lines changed: 5 additions & 0 deletions
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,7 @@ const {
157158
}, { once: true });
158159
et.dispatchEvent(new Event('foo'));
159160
}
161+
{
162+
const et = new EventTarget();
163+
throws(() => et.addEventListener('foo', () => {}, {signal: null}));
164+
}

0 commit comments

Comments
 (0)