From 74753ed1fec081858c00d9c8f73172b994dc8561 Mon Sep 17 00:00:00 2001 From: Mickael Meausoone Date: Sun, 12 May 2024 09:18:03 +0200 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.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: https://github.com/nodejs/node/pull/39463 Reviewed-By: James M Snell Reviewed-By: Benjamin Gruenbaum --- 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 2d32b2804c4b00..94a257062147f8 100644 --- a/lib/internal/event_target.js +++ b/lib/internal/event_target.js @@ -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; } diff --git a/test/parallel/test-eventtarget.js b/test/parallel/test-eventtarget.js index aaead823d032b8..72389a589056e4 100644 --- a/test/parallel/test-eventtarget.js +++ b/test/parallel/test-eventtarget.js @@ -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); }