Skip to content

Commit d7de14d

Browse files
Mickael Meausoonemikemadest
authored andcommitted
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 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
1 parent 50477fa commit d7de14d

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

lib/internal/event_target.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ class Event {
164164
stopImmediatePropagation() {
165165
if (!isEvent(this))
166166
throw new ERR_INVALID_THIS('Event');
167+
// Spec mention "stopImmediatePropagation should set both "stop propagation"
168+
// and "stop immediate propagation" flags"
169+
// cf: from https://dom.spec.whatwg.org/#dom-event-stopimmediatepropagation
170+
this.stopPropagation();
167171
this[kStop] = true;
168172
}
169173

test/parallel/test-eventtarget.js

Lines changed: 2 additions & 0 deletions
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)