Skip to content

Commit 74753ed

Browse files
mikemadestmarco-ippolito
authored andcommittedJun 17, 2024
events: add stop propagation flag to Event.stopImmediatePropagation
Spec mention stopImmediatePropagation should set both flags: "stop propagation" and "stop immediate propagation". So the second is not supported by Node.js as there is no hierarchy and bubbling, but the flags are both present as well as stopPropagation. It would makes sense to follow specs on that. Refs: https://dom.spec.whatwg.org/#dom-event-stopimmediatepropagation PR-URL: #39463 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent f6290bc commit 74753ed

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed
 

‎lib/internal/event_target.js

+4
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ class Event {
172172
stopImmediatePropagation() {
173173
if (!isEvent(this))
174174
throw new ERR_INVALID_THIS('Event');
175+
// Spec mention "stopImmediatePropagation should set both "stop propagation"
176+
// and "stop immediate propagation" flags"
177+
// cf: from https://dom.spec.whatwg.org/#dom-event-stopimmediatepropagation
178+
this.stopPropagation();
175179
this[kStop] = true;
176180
}
177181

‎test/parallel/test-eventtarget.js

+2
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,9 @@ let asyncTest = Promise.resolve();
345345
{
346346
const target = new EventTarget();
347347
const event = new Event('foo');
348+
strictEqual(event.cancelBubble, false);
348349
event.stopImmediatePropagation();
350+
strictEqual(event.cancelBubble, true);
349351
target.addEventListener('foo', common.mustNotCall());
350352
target.dispatchEvent(event);
351353
}

0 commit comments

Comments
 (0)
Please sign in to comment.