From d00adabc3c13f18ca46e9c8ab329551fdc3fdef3 Mon Sep 17 00:00:00 2001 From: scorpion-26 Date: Thu, 3 Oct 2024 23:12:15 +0200 Subject: [PATCH] LibWeb: Preserve order of HTMLCollection property names The supported property names should be ordered in "tree order", though m_cached_name_to_element_mappings doesn't preserve this ordering, which breaks Object.getOwnPropertyNames. Fixes at least the following WPT tests: - https://wpt.live/dom/nodes/Element-children.html - https://wpt.live/dom/collections/HTMLCollection-live-mutations.window.html - https://wpt.live/dom/collections/HTMLCollection-supported-property-names.html --- .../HTMLCollection-property-names-iteration-order.txt | 1 + .../HTMLCollection-property-names-iteration-order.html | 10 ++++++++++ Userland/Libraries/LibWeb/DOM/HTMLCollection.cpp | 2 +- Userland/Libraries/LibWeb/DOM/HTMLCollection.h | 2 +- 4 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/DOM/HTMLCollection-property-names-iteration-order.txt create mode 100644 Tests/LibWeb/Text/input/DOM/HTMLCollection-property-names-iteration-order.html diff --git a/Tests/LibWeb/Text/expected/DOM/HTMLCollection-property-names-iteration-order.txt b/Tests/LibWeb/Text/expected/DOM/HTMLCollection-property-names-iteration-order.txt new file mode 100644 index 00000000000..dd3ca6e56a7 --- /dev/null +++ b/Tests/LibWeb/Text/expected/DOM/HTMLCollection-property-names-iteration-order.txt @@ -0,0 +1 @@ +0,1,2,foo,bar,baz diff --git a/Tests/LibWeb/Text/input/DOM/HTMLCollection-property-names-iteration-order.html b/Tests/LibWeb/Text/input/DOM/HTMLCollection-property-names-iteration-order.html new file mode 100644 index 00000000000..7d9205c3b94 --- /dev/null +++ b/Tests/LibWeb/Text/input/DOM/HTMLCollection-property-names-iteration-order.html @@ -0,0 +1,10 @@ + + + + + + diff --git a/Userland/Libraries/LibWeb/DOM/HTMLCollection.cpp b/Userland/Libraries/LibWeb/DOM/HTMLCollection.cpp index 021d2b9763f..19a9d2a4c79 100644 --- a/Userland/Libraries/LibWeb/DOM/HTMLCollection.cpp +++ b/Userland/Libraries/LibWeb/DOM/HTMLCollection.cpp @@ -57,7 +57,7 @@ void HTMLCollection::update_name_to_element_mappings_if_needed() const update_cache_if_needed(); if (m_cached_name_to_element_mappings) return; - m_cached_name_to_element_mappings = make>>(); + m_cached_name_to_element_mappings = make>>(); for (auto const& element : m_cached_elements) { // 1. If element has an ID which is not in result, append element’s ID to result. if (auto const& id = element->id(); id.has_value()) { diff --git a/Userland/Libraries/LibWeb/DOM/HTMLCollection.h b/Userland/Libraries/LibWeb/DOM/HTMLCollection.h index 5b08fc43f5c..5ebafa79772 100644 --- a/Userland/Libraries/LibWeb/DOM/HTMLCollection.h +++ b/Userland/Libraries/LibWeb/DOM/HTMLCollection.h @@ -61,7 +61,7 @@ private: mutable u64 m_cached_dom_tree_version { 0 }; mutable Vector> m_cached_elements; - mutable OwnPtr>> m_cached_name_to_element_mappings; + mutable OwnPtr>> m_cached_name_to_element_mappings; JS::NonnullGCPtr m_root; Function m_filter;