Truly independent web browser
LibWeb: Do not assign a node twice in HTMLSlotElement.assign()
Andreas Kling7f7c8814f37c
diff --git a/Libraries/LibWeb/HTML/HTMLSlotElement.cpp b/Libraries/LibWeb/HTML/HTMLSlotElement.cppindex 84125bda743..cf652938c72 100644--- a/Libraries/LibWeb/HTML/HTMLSlotElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLSlotElement.cpp@@ -6,6 +6,7 @@* SPDX-License-Identifier: BSD-2-Clause*/+#include <LibGC/ConservativeHashTable.h>#include <LibWeb/Bindings/HTMLSlotElement.h>#include <LibWeb/DOM/Element.h>#include <LibWeb/DOM/ShadowRoot.h>@@ -123,6 +124,7 @@ void HTMLSlotElement::assign(GC::ConservativeVector<SlottableHandle> nodes)// 2. Let nodesSet be a new ordered set.GC::ConservativeVector<DOM::Slottable> nodes_set;+ GC::ConservativeHashTable<GC::Ref<DOM::Node const>> nodes_in_nodes_set;// 3. For each node of nodes:for (auto& node_handle : nodes) {@@ -140,7 +142,9 @@ void HTMLSlotElement::assign(GC::ConservativeVector<SlottableHandle> nodes)node.set_manual_slot_assignment(this);// 3. Append node to nodesSet.- nodes_set.append(slottable);+ // NB: nodesSet is an ordered set, so a node that is already in it is not appended again.+ if (nodes_in_nodes_set.set(node_handle.visit([](auto& node) -> GC::Ref<DOM::Node const> { return *node; })) == HashSetResult::InsertedNewEntry)+ nodes_set.append(slottable);}// 4. Set this's manually assigned nodes to nodesSet.diff --git a/Tests/LibWeb/Text/expected/wpt-import/shadow-dom/imperative-slot-api-slotchange.txt b/Tests/LibWeb/Text/expected/wpt-import/shadow-dom/imperative-slot-api-slotchange.txtindex e6b7403b841..bc4fa8a420b 100644--- a/Tests/LibWeb/Text/expected/wpt-import/shadow-dom/imperative-slot-api-slotchange.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/shadow-dom/imperative-slot-api-slotchange.txt@@ -2,11 +2,10 @@ Harness status: OKFound 13 tests-12 Pass-1 Fail+13 PassPass slotchange event must not fire synchronously.Pass slotchange event should not fire when assignments do not change assignedNodes.-Fail slotchange event should not fire when same node is assigned.+Pass slotchange event should not fire when same node is assigned.Pass Fire slotchange event when slot's assigned nodes changes.Pass Fire slotchange event on previous slot and new slot when node is reassigned.Pass Fire slotchange event on node assignment and when assigned node is removed.