From 91a2bbcfe377feb5d8f5689933e0564327e1eb3b Mon Sep 17 00:00:00 2001 From: Francis Bouvier Date: Sat, 11 Jul 2026 21:26:29 +0200 Subject: [PATCH] webapi: Attr.ownerDocument follows the owning element Fixes the failing subtest of WPT /dom/nodes/Node-mutation-adoptNode.html ("Adopting an element ... owner docs of it's attributes"): after adopting an element into another document, its attribute nodes' ownerDocument must report the new document. Attribute nodes are parent-less, so ownerDocument fell through to the detached-node fallback (the per-frame owner map / main document), which never changes on adoption. An attribute node with an owning element now delegates to that element's ownerDocument; detached Attr nodes keep the old resolution. Coverage: - /dom/nodes/Node-mutation-adoptNode.html 1/2 -> 2/2 (fully green) - /dom/nodes/attributes-namednodemap-cross-document.window.html 0/2 -> 1/2 Co-Authored-By: Claude Fable 5 --- src/browser/webapi/Node.zig | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/browser/webapi/Node.zig b/src/browser/webapi/Node.zig index 8544cea0a..1be03fe94 100644 --- a/src/browser/webapi/Node.zig +++ b/src/browser/webapi/Node.zig @@ -650,6 +650,14 @@ pub fn ownerDocument(self: *const Node, frame: *const Frame) ?*Document { return null; } + // An attribute node has no parent; its owner follows its element's + // (including across adoption into another document). + if (self._type == .attribute) { + if (self._type.attribute._element) |element| { + return element.asNode().ownerDocument(frame); + } + } + // The root of the tree that a node belongs to is its owner. var current = self; while (current._parent) |parent| {