node: don't call owner twice in _insertBefore

When the ref_node_ is null, call directly _appendChild w/o fixing the
node's owner.
This commit is contained in:
Pierre Tachoire
2025-08-05 14:45:25 +02:00
parent 0a5f060d1b
commit bd9e4dbc79

View File

@@ -307,6 +307,10 @@ pub const Node = struct {
}
pub fn _insertBefore(self: *parser.Node, new_node: *parser.Node, ref_node_: ?*parser.Node) !Union {
if (ref_node_ == null) {
return _appendChild(self, new_node);
}
const self_owner = try parser.nodeOwnerDocument(self);
const new_node_owner = try parser.nodeOwnerDocument(new_node);
@@ -318,16 +322,13 @@ pub const Node = struct {
if (new_node_owner == null or (new_node_owner.? != self_owner.?)) {
const w = Walker{};
var current = new_node;
while(true) {
while (true) {
current.owner = self_owner;
current = try w.get_next(new_node, current) orelse break;
}
}
if (ref_node_) |ref_node| {
return Node.toInterface(try parser.nodeInsertBefore(self, new_node, ref_node));
}
return _appendChild(self, new_node);
return Node.toInterface(try parser.nodeInsertBefore(self, new_node, ref_node_.?));
}
pub fn _isDefaultNamespace(self: *parser.Node, namespace: ?[]const u8) !bool {