Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

events: add null check for the signal of EventTarget #43153

Merged
merged 7 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion lib/internal/event_target.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const {
ERR_INVALID_THIS,
}
} = require('internal/errors');
const { validateObject, validateString, validateInternalField } = require('internal/validators');
const { validateAbortSignal, validateObject, validateString, validateInternalField } = require('internal/validators');

const {
customInspectSymbol,
Expand Down Expand Up @@ -575,6 +575,8 @@ class EventTarget {
}
type = String(type);

validateAbortSignal(signal, 'options.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,11 @@ const {
}, { once: true });
et.dispatchEvent(new Event('foo'));
}
{
const et = new EventTarget();
[1, 1n, {}, [], null, true, 'hi', Symbol(), () => {}].forEach((signal) => {
throws(() => et.addEventListener('foo', () => {}, { signal }), {
name: 'TypeError',
});
});
}
1 change: 0 additions & 1 deletion test/wpt/status/dom/events.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"AddEventListenerOptions-signal.any.js": {
"fail": {
"expected": [
"Passing null as the signal should throw",
"Passing null as the signal should throw (listener is also null)"
]
}
Expand Down