Skip to content

Commit 07dcb75

Browse files
benjamingrBenjamin Gruenbaum
authored andcommitted
events: support useCapture boolean
PR-URL: #33618 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent f643cf4 commit 07dcb75

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/internal/event_target.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,9 @@ function validateListener(listener) {
412412
}
413413

414414
function validateEventListenerOptions(options) {
415+
if (typeof options === 'boolean') {
416+
options = { capture: options };
417+
}
415418
if (options == null || typeof options !== 'object')
416419
throw new ERR_INVALID_ARG_TYPE('options', 'object', options);
417420
const {

test/parallel/test-eventtarget.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,14 @@ const ev = new Event('foo');
151151
eventTarget.addEventListener('foo', (event) => event.preventDefault());
152152
ok(!eventTarget.dispatchEvent(event));
153153
}
154-
154+
{
155+
// Adding event listeners with a boolean useCapture
156+
const eventTarget = new EventTarget();
157+
const event = new Event('foo');
158+
const fn = common.mustCall((event) => strictEqual(event.type, 'foo'));
159+
eventTarget.addEventListener('foo', fn, false);
160+
eventTarget.dispatchEvent(event);
161+
}
155162
{
156163
const eventTarget = new NodeEventTarget();
157164
strictEqual(eventTarget.listenerCount('foo'), 0);

0 commit comments

Comments
 (0)