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.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>
  • Loading branch information
mikemadest authored and marco-ippolito committed Jun 17, 2024
1 parent a6a2dde commit a287134
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 @@ -172,6 +172,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 a287134

Please sign in to comment.