diff --git a/lib/internal/event_target.js b/lib/internal/event_target.js index f5bc4844166342..fc814b87c36138 100644 --- a/lib/internal/event_target.js +++ b/lib/internal/event_target.js @@ -541,6 +541,9 @@ function shouldAddListener(listener) { function validateEventListenerOptions(options) { if (typeof options === 'boolean') return { capture: options }; + + if (options === null) + return {}; validateObject(options, 'options', { allowArray: true, allowFunction: true, }); diff --git a/test/parallel/test-eventtarget.js b/test/parallel/test-eventtarget.js index 63e20513a4c9b2..2a013875dc3225 100644 --- a/test/parallel/test-eventtarget.js +++ b/test/parallel/test-eventtarget.js @@ -178,6 +178,15 @@ let asyncTest = Promise.resolve(); eventTarget.dispatchEvent(event); } +{ + // The `options` argument can be `null`. + const eventTarget = new EventTarget(); + const event = new Event('foo'); + const fn = common.mustCall((event) => strictEqual(event.type, 'foo')); + eventTarget.addEventListener('foo', fn, null); + eventTarget.dispatchEvent(event); +} + { const uncaughtException = common.mustCall((err, event) => { strictEqual(err.message, 'boom');