Skip to content

Commit 6f2989c

Browse files
lpincaBethGriggs
authored andcommitted
events: allow the options argument to be null
Make `EventTarget.prototype.addEventListener()` accept `null` as a valid value for the `options` argument. PR-URL: #39486 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Robert Nagy <[email protected]>
1 parent 487c45f commit 6f2989c

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/internal/event_target.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,9 @@ function shouldAddListener(listener) {
598598
function validateEventListenerOptions(options) {
599599
if (typeof options === 'boolean')
600600
return { capture: options };
601+
602+
if (options === null)
603+
return {};
601604
validateObject(options, 'options', {
602605
allowArray: true, allowFunction: true,
603606
});

test/parallel/test-eventtarget.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,15 @@ let asyncTest = Promise.resolve();
177177
eventTarget.dispatchEvent(event);
178178
}
179179

180+
{
181+
// The `options` argument can be `null`.
182+
const eventTarget = new EventTarget();
183+
const event = new Event('foo');
184+
const fn = common.mustCall((event) => strictEqual(event.type, 'foo'));
185+
eventTarget.addEventListener('foo', fn, null);
186+
eventTarget.dispatchEvent(event);
187+
}
188+
180189
{
181190
const uncaughtException = common.mustCall((err, origin) => {
182191
strictEqual(err.message, 'boom');

0 commit comments

Comments
 (0)