GeezerVison is showing github.com — events: add null check for the signal of EventTarget · nodejs/node@03fb789
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/event_target.js +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -34,7 +34,7 @@ const { | 34 | 34 | ERR_INVALID_THIS, | 35 | 35 | } | 36 | 36 | } = require('internal/errors'); | 37 | | -const { validateObject, validateString, validateInternalField } = require('internal/validators'); | | 37 | +const { validateAbortSignal, validateObject, validateString, validateInternalField } = require('internal/validators'); | 38 | 38 |
| 39 | 39 | const { | 40 | 40 | customInspectSymbol, | @@ -575,6 +575,8 @@ class EventTarget { | 575 | 575 | } | 576 | 576 | type = String(type); | 577 | 577 |
| | 578 | + validateAbortSignal(signal, 'options.signal'); | | 579 | + | 578 | 580 | if (signal) { | 579 | 581 | if (signal.aborted) { | 580 | 582 | return; | |
Collapse file 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 number | Diff line number | Diff line change |
|---|
@@ -4,6 +4,7 @@ require('../common'); | 4 | 4 |
| 5 | 5 | const { | 6 | 6 | strictEqual, | | 7 | + throws, | 7 | 8 | } = require('assert'); | 8 | 9 |
| 9 | 10 | // Manually ported from: wpt@dom/events/AddEventListenerOptions-signal.any.js | @@ -157,3 +158,11 @@ const { | 157 | 158 | }, { once: true }); | 158 | 159 | et.dispatchEvent(new Event('foo')); | 159 | 160 | } | | 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 Copy file name to clipboardExpand all lines: test/wpt/status/dom/events.json -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 11 | 11 | "AddEventListenerOptions-signal.any.js": { | 12 | 12 | "fail": { | 13 | 13 | "expected": [ | 14 | | - "Passing null as the signal should throw", | 15 | 14 | "Passing null as the signal should throw (listener is also null)" | 16 | 15 | ] | 17 | 16 | } | |
|