Skip to content

Commit a3ef2b7

Browse files
benjamingrcodebytere
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 2e6ecea commit a3ef2b7

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/internal/event_target.js

+3
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,9 @@ function validateListener(listener) {
413413
}
414414

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

test/parallel/test-eventtarget.js

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

0 commit comments

Comments
 (0)