Skip to content

Commit

Permalink
events: add stop propagation flag to Event.stopImmediatePropagation
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Mickael Meausoone authored and mikemadest committed Jun 27, 2023
1 parent fddd3ff commit 53f073d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/internal/event_target.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ class Event {
stopImmediatePropagation() {
if (!isEvent(this))
throw new ERR_INVALID_THIS('Event');
// Spec mention "stopImmediatePropagation should set both "stop propagation"
// and "stop immediate propagation" flags"
// cf: from https://dom.spec.whatwg.org/#dom-event-stopimmediatepropagation
this.stopPropagation();
this[kStop] = true;
}

Expand Down
2 changes: 2 additions & 0 deletions test/parallel/test-eventtarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,9 @@ let asyncTest = Promise.resolve();
{
const target = new EventTarget();
const event = new Event('foo');
strictEqual(event.cancelBubble, false);
event.stopImmediatePropagation();
strictEqual(event.cancelBubble, true);
target.addEventListener('foo', common.mustNotCall());
target.dispatchEvent(event);
}
Expand Down

0 comments on commit 53f073d

Please sign in to comment.