webapi: only HTML-namespace elements are named by their name attribute

Fixes the failing subtest "hasOwnProperty, getOwnPropertyDescriptor,
getOwnPropertyNames" in WPT /dom/nodes/Document-getElementsByTagName.html
(17/18 -> 18/18) and /dom/nodes/Element-getElementsByTagName.html
(18/19 -> 19/19).

Per the DOM spec's supported property names for HTMLCollection, the
name attribute only exposes elements in the HTML namespace (ids expose
any element). The live-collection getByName fallback matched any
element with a name attribute; it now skips non-HTML elements, matching
the enumerator which already had the guard.

Coverage: Document-getElementsByTagName.html 17/18 -> 18/18,
Element-getElementsByTagName.html 18/19 -> 19/19. /dom/collections
stays fully green.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Francis Bouvier
2026-07-10 22:32:11 +02:00
parent ce53a3b48c
commit ffdc1a7157

View File

@@ -194,6 +194,11 @@ pub fn NodeLive(comptime mode: Mode) type {
// (like length or getAtIndex)
var tw = self._tw.clone();
while (self.nextTw(&tw)) |element| {
// Per spec, only HTML-namespace elements are exposed via
// their name attribute (ids expose any element).
if (element._namespace != .html) {
continue;
}
const element_name = element.getAttributeSafe(comptime .wrap("name")) orelse continue;
if (std.mem.eql(u8, element_name, name)) {
return element;