Skip to content

Truly independent web browser

LibWeb: List id values before name values in Document named properties

Andreas Kling0c5844f08e45
diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp
index 791cde75d85..ad6d7bfbe28 100644
--- a/Libraries/LibWeb/DOM/Document.cpp
+++ b/Libraries/LibWeb/DOM/Document.cpp
@@ -9700,18 +9700,8 @@ Vector<Utf16FlyString> Document::supported_property_names() const
OrderedHashTable<Utf16FlyString> names;
for (auto const& element : m_potentially_named_elements) {
- // - the value of the name content attribute for all exposed embed, form, iframe, img, and exposed object elements
- // that have a non-empty name content attribute and are in a document tree with document as their root;
- if ((is<HTML::HTMLEmbedElement>(*element) && is_exposed(element))
- || is<HTML::HTMLFormElement>(*element)
- || is<HTML::HTMLIFrameElement>(*element)
- || is<HTML::HTMLImageElement>(*element)
- || (is<HTML::HTMLObjectElement>(*element) && is_exposed(element))) {
- if (auto name = element->name(); name.has_value()) {
- names.set(name.value());
- }
- }
-
+ // NB: Values from id attributes come before values from name attributes when the same element contributes
+ // both, so the id values are collected first.
// - the value of the id content attribute for all exposed object elements that have a non-empty id content attribute
// and are in a document tree with document as their root; and
if (is<HTML::HTMLObjectElement>(*element) && is_exposed(element)) {
@@ -9727,6 +9717,18 @@ Vector<Utf16FlyString> Document::supported_property_names() const
names.set(id.value());
}
}
+
+ // - the value of the name content attribute for all exposed embed, form, iframe, img, and exposed object elements
+ // that have a non-empty name content attribute and are in a document tree with document as their root;
+ if ((is<HTML::HTMLEmbedElement>(*element) && is_exposed(element))
+ || is<HTML::HTMLFormElement>(*element)
+ || is<HTML::HTMLIFrameElement>(*element)
+ || is<HTML::HTMLImageElement>(*element)
+ || (is<HTML::HTMLObjectElement>(*element) && is_exposed(element))) {
+ if (auto name = element->name(); name.has_value()) {
+ names.set(name.value());
+ }
+ }
}
Vector<Utf16FlyString> result;
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/dom/documents/dom-tree-accessors/nameditem-supported-property-names-order.txt b/Tests/LibWeb/Text/expected/wpt-import/html/dom/documents/dom-tree-accessors/nameditem-supported-property-names-order.txt
index 2f745be3082..1c9987bcc37 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/html/dom/documents/dom-tree-accessors/nameditem-supported-property-names-order.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/html/dom/documents/dom-tree-accessors/nameditem-supported-property-names-order.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail Values from id attributes precede values from name attributes when the same element contributes both
\ No newline at end of file
+1 Pass
+Pass Values from id attributes precede values from name attributes when the same element contributes both
\ No newline at end of file