Skip to content

Commit cfc0a71

Browse files
committed
fix: EventTarget.addEventListener throws an error passin null as the signal
1 parent 20268c7 commit cfc0a71

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)