Skip to content

Commit

Permalink
fix: EventTarget.addEventListener throws an error passin null as the …
Browse files Browse the repository at this point in the history
…signal
  • Loading branch information
shisama committed May 19, 2022
1 parent 20268c7 commit cfc0a71
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/internal/event_target.js
Expand Up @@ -482,6 +482,10 @@ class EventTarget {
}
type = String(type);

if (signal === null) {
throw new ERR_INVALID_ARG_TYPE('options.signal', 'AbortSignal', signal);
}

if (signal) {
if (signal.aborted) {
return;
Expand Down
5 changes: 5 additions & 0 deletions test/parallel/test-eventtarget-whatwg-signal.js
Expand Up @@ -4,6 +4,7 @@ require('../common');

const {
strictEqual,
throws
} = require('assert');

// Manually ported from: wpt@dom/events/AddEventListenerOptions-signal.any.js
Expand Down Expand Up @@ -157,3 +158,7 @@ const {
}, { once: true });
et.dispatchEvent(new Event('foo'));
}
{
const et = new EventTarget();
throws(() => et.addEventListener('foo', () => {}, {signal: null}));
}

0 comments on commit cfc0a71

Please sign in to comment.