diff --git a/lib/internal/event_target.js b/lib/internal/event_target.js index d1af4db3c58dd9..cf94bcbe7bf387 100644 --- a/lib/internal/event_target.js +++ b/lib/internal/event_target.js @@ -412,6 +412,9 @@ function validateListener(listener) { } function validateEventListenerOptions(options) { + if (typeof options === 'boolean') { + options = { capture: options }; + } if (options == null || typeof options !== 'object') throw new ERR_INVALID_ARG_TYPE('options', 'object', options); const { diff --git a/test/parallel/test-eventtarget.js b/test/parallel/test-eventtarget.js index f9a95a8983cddd..f032b2fedb715a 100644 --- a/test/parallel/test-eventtarget.js +++ b/test/parallel/test-eventtarget.js @@ -151,7 +151,14 @@ const ev = new Event('foo'); eventTarget.addEventListener('foo', (event) => event.preventDefault()); ok(!eventTarget.dispatchEvent(event)); } - +{ + // Adding event listeners with a boolean useCapture + const eventTarget = new EventTarget(); + const event = new Event('foo'); + const fn = common.mustCall((event) => strictEqual(event.type, 'foo')); + eventTarget.addEventListener('foo', fn, false); + eventTarget.dispatchEvent(event); +} { const eventTarget = new NodeEventTarget(); strictEqual(eventTarget.listenerCount('foo'), 0);