From 33c4ebcdda7e20b09939d00afb0044d69f5365d2 Mon Sep 17 00:00:00 2001 From: Mickael Meausoone Date: Tue, 20 Jul 2021 08:28:28 +0100 Subject: [PATCH] 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 --- lib/internal/event_target.js | 4 ++++ test/parallel/test-eventtarget.js | 2 ++ 2 files changed, 6 insertions(+) diff --git a/lib/internal/event_target.js b/lib/internal/event_target.js index 825e1e8b2597ab..b7e49a08245b95 100644 --- a/lib/internal/event_target.js +++ b/lib/internal/event_target.js @@ -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; } diff --git a/test/parallel/test-eventtarget.js b/test/parallel/test-eventtarget.js index a85e2cd7f1b9f9..747a1e87f33792 100644 --- a/test/parallel/test-eventtarget.js +++ b/test/parallel/test-eventtarget.js @@ -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); }