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
This commit is contained in:
scorpion-26 2024-10-03 23:12:15 +02:00 committed by Tim Ledbetter
commit d00adabc3c
Notes: github-actions[bot] 2024-10-04 21:44:52 +00:00
4 changed files with 13 additions and 2 deletions

View file

@ -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<HashMap<FlyString, JS::NonnullGCPtr<Element>>>();
m_cached_name_to_element_mappings = make<OrderedHashMap<FlyString, JS::NonnullGCPtr<Element>>>();
for (auto const& element : m_cached_elements) {
// 1. If element has an ID which is not in result, append elements ID to result.
if (auto const& id = element->id(); id.has_value()) {