Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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
  • Loading branch information
shisama committed Oct 11, 2022
commit 21cb08f95d35d9ef72e1df0fd0b3f618b90aa3ea
4 changes: 4 additions & 0 deletions lib/internal/event_target.js
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,10 @@ class EventTarget {
}
type = String(type);

if (signal === null) {
Comment thread
aduh95 marked this conversation as resolved.
Outdated
throw new ERR_INVALID_ARG_TYPE('options.signal', 'AbortSignal', signal);
}

if (signal) {
if (signal.aborted) {
return;
Expand Down
Original file line number Diff line number Diff line change
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}));
}