From a3ef2b7335c4f1954f03776defc9982e7f17c3d4 Mon Sep 17 00:00:00 2001 From: Benjamin Gruenbaum Date: Thu, 28 May 2020 19:08:43 +0300 Subject: [PATCH] events: support useCapture boolean MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/33618 Reviewed-By: James M Snell Reviewed-By: Ruben Bridgewater Reviewed-By: Michaƫl Zasso Reviewed-By: Anna Henningsen --- lib/internal/event_target.js | 3 +++ test/parallel/test-eventtarget.js | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) 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);