mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
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 PR-URL: https://github.com/nodejs/node/pull/43153 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
488474618c
commit
03fb789fb9
@ -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,
|
||||
@ -575,6 +575,8 @@ class EventTarget {
|
||||
}
|
||||
type = String(type);
|
||||
|
||||
validateAbortSignal(signal, 'options.signal');
|
||||
|
||||
if (signal) {
|
||||
if (signal.aborted) {
|
||||
return;
|
||||
|
@ -4,6 +4,7 @@ require('../common');
|
||||
|
||||
const {
|
||||
strictEqual,
|
||||
throws,
|
||||
} = require('assert');
|
||||
|
||||
// Manually ported from: wpt@dom/events/AddEventListenerOptions-signal.any.js
|
||||
@ -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',
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -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)"
|
||||
]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user