Skip to content

Commit c1782ea

Browse files
lpincatargos
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 695569f commit c1782ea

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
@@ -541,6 +541,9 @@ function shouldAddListener(listener) {
541541
function validateEventListenerOptions(options) {
542542
if (typeof options === 'boolean')
543543
return { capture: options };
544+
545+
if (options === null)
546+
return {};
544547
validateObject(options, 'options', {
545548
allowArray: true, allowFunction: true,
546549
});

test/parallel/test-eventtarget.js

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

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

0 commit comments

Comments
 (0)