From 69c84d3f630c0016a4eeb986a392b37effcfae8f Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 17 Nov 2024 11:30:19 +0100 Subject: [PATCH] LibWeb: Make sure we don't fire "once" event listeners twice Spec bug: https://github.com/whatwg/dom/issues/1323 --- Libraries/LibWeb/DOM/EventTarget.cpp | 4 ++++ .../expected/wpt-import/dom/events/remove-all-listeners.txt | 5 ++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Libraries/LibWeb/DOM/EventTarget.cpp b/Libraries/LibWeb/DOM/EventTarget.cpp index 1427158d5dd..39f622b9af9 100644 --- a/Libraries/LibWeb/DOM/EventTarget.cpp +++ b/Libraries/LibWeb/DOM/EventTarget.cpp @@ -254,6 +254,10 @@ void EventTarget::remove_from_event_listener_list(DOMEventListener& listener) if (!m_data) return; m_data->event_listener_list.remove_first_matching([&](auto& entry) { return entry.ptr() == &listener; }); + + // FIXME: Update this when the spec is updated. + // Spec bug: https://github.com/whatwg/dom/issues/1323 + listener.removed = true; } // https://dom.spec.whatwg.org/#dom-eventtarget-dispatchevent diff --git a/Tests/LibWeb/Text/expected/wpt-import/dom/events/remove-all-listeners.txt b/Tests/LibWeb/Text/expected/wpt-import/dom/events/remove-all-listeners.txt index 619c33ed3a7..167bea54847 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/dom/events/remove-all-listeners.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/dom/events/remove-all-listeners.txt @@ -6,8 +6,7 @@ Rerun Found 2 tests -1 Pass -1 Fail +2 Pass Details Result Test Name MessagePass Removing all listeners and then adding a new one should work. -Fail Nested usage of once listeners should work. \ No newline at end of file +Pass Nested usage of once listeners should work. \ No newline at end of file