Skip to content

Commit

Permalink
events: support useCapture boolean
Browse files Browse the repository at this point in the history
PR-URL: #33618
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
benjamingr authored and codebytere committed Jun 18, 2020
1 parent 2e6ecea commit a3ef2b7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/internal/event_target.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 8 additions & 1 deletion test/parallel/test-eventtarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a3ef2b7

Please sign in to comment.