Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 03fb789

Browse filesBrowse files
authored
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: #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>
1 parent 4884746 commit 03fb789
Copy full SHA for 03fb789

File tree

Expand file treeCollapse file tree

3 files changed

+12
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+12
-2
lines changed
Open diff view settings
Collapse file

‎lib/internal/event_target.js‎

Copy file name to clipboardExpand all lines: lib/internal/event_target.js
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const {
3434
ERR_INVALID_THIS,
3535
}
3636
} = require('internal/errors');
37-
const { validateObject, validateString, validateInternalField } = require('internal/validators');
37+
const { validateAbortSignal, validateObject, validateString, validateInternalField } = require('internal/validators');
3838

3939
const {
4040
customInspectSymbol,
@@ -575,6 +575,8 @@ class EventTarget {
575575
}
576576
type = String(type);
577577

578+
validateAbortSignal(signal, 'options.signal');
579+
578580
if (signal) {
579581
if (signal.aborted) {
580582
return;
Collapse file

‎test/parallel/test-whatwg-events-add-event-listener-options-signal.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-whatwg-events-add-event-listener-options-signal.js
+9Lines changed: 9 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,11 @@ const {
157158
}, { once: true });
158159
et.dispatchEvent(new Event('foo'));
159160
}
161+
{
162+
const et = new EventTarget();
163+
[1, 1n, {}, [], null, true, 'hi', Symbol(), () => {}].forEach((signal) => {
164+
throws(() => et.addEventListener('foo', () => {}, { signal }), {
165+
name: 'TypeError',
166+
});
167+
});
168+
}
Collapse file

‎test/wpt/status/dom/events.json‎

Copy file name to clipboardExpand all lines: test/wpt/status/dom/events.json
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
"AddEventListenerOptions-signal.any.js": {
1212
"fail": {
1313
"expected": [
14-
"Passing null as the signal should throw",
1514
"Passing null as the signal should throw (listener is also null)"
1615
]
1716
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.