diff --git a/lib/internal/event_target.js b/lib/internal/event_target.js index df25200f1b09d8..8641129b132914 100644 --- a/lib/internal/event_target.js +++ b/lib/internal/event_target.js @@ -413,6 +413,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 8d4be41df55c73..3e652e1e3396b4 100644 --- a/test/parallel/test-eventtarget.js +++ b/test/parallel/test-eventtarget.js @@ -152,7 +152,14 @@ ok(EventTarget); 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);