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 Mickael Meausoone committed Jul 20, 2021
1 parent 3cbaabc commit 23744d2
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 @@ -125,6 +125,10 @@ class Event {
}

stopImmediatePropagation() {
// 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 @@ -267,7 +267,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 23744d2

Please sign in to comment.