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 Benjamin Gruenbaum committed May 31, 2020
1 parent f643cf4 commit 07dcb75
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 @@ -412,6 +412,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 @@ -151,7 +151,14 @@ const ev = new Event('foo');
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 07dcb75

Please sign in to comment.