mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
events: support useCapture boolean
PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
1 parent
1969ada982
commit
bf33b61be0
2 files changed
+11
-1
No files matched your search
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user