mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 15:13:28 +00:00
Merge pull request #923 from lightpanda-io/doc-owner-next
Some checks failed
e2e-test / zig build release (push) Has been cancelled
e2e-test / demo-scripts (push) Has been cancelled
e2e-test / cdp-and-hyperfine-bench (push) Has been cancelled
e2e-test / perf-fmt (push) Has been cancelled
zig-test / zig build dev (push) Has been cancelled
zig-test / browser fetch (push) Has been cancelled
zig-test / zig test (push) Has been cancelled
zig-test / perf-fmt (push) Has been cancelled
nightly build / build-linux-x86_64 (push) Has been cancelled
nightly build / build-linux-aarch64 (push) Has been cancelled
nightly build / build-macos-aarch64 (push) Has been cancelled
nightly build / build-macos-x86_64 (push) Has been cancelled
wpt / web platform tests json output (push) Has been cancelled
wpt / perf-fmt (push) Has been cancelled
Some checks failed
e2e-test / zig build release (push) Has been cancelled
e2e-test / demo-scripts (push) Has been cancelled
e2e-test / cdp-and-hyperfine-bench (push) Has been cancelled
e2e-test / perf-fmt (push) Has been cancelled
zig-test / zig build dev (push) Has been cancelled
zig-test / browser fetch (push) Has been cancelled
zig-test / zig test (push) Has been cancelled
zig-test / perf-fmt (push) Has been cancelled
nightly build / build-linux-x86_64 (push) Has been cancelled
nightly build / build-linux-aarch64 (push) Has been cancelled
nightly build / build-macos-aarch64 (push) Has been cancelled
nightly build / build-macos-x86_64 (push) Has been cancelled
wpt / web platform tests json output (push) Has been cancelled
wpt / perf-fmt (push) Has been cancelled
node: don't call owner twice in _insertBefore
This commit is contained in:
@@ -201,11 +201,11 @@ pub const Node = struct {
|
|||||||
const self_owner = try parser.nodeOwnerDocument(self);
|
const self_owner = try parser.nodeOwnerDocument(self);
|
||||||
const child_owner = try parser.nodeOwnerDocument(child);
|
const child_owner = try parser.nodeOwnerDocument(child);
|
||||||
|
|
||||||
// If the node to be inserted has a different ownerDocument than the parent node,
|
// If the node to be inserted has a different ownerDocument than the parent node,
|
||||||
// modern browsers automatically adopt the node and its descendants into
|
// modern browsers automatically adopt the node and its descendants into
|
||||||
// the parent's ownerDocument.
|
// the parent's ownerDocument.
|
||||||
// This process is known as adoption.
|
// This process is known as adoption.
|
||||||
// (7.1) https://dom.spec.whatwg.org/#concept-node-insert
|
// (7.1) https://dom.spec.whatwg.org/#concept-node-insert
|
||||||
if (child_owner == null or (child_owner.? != self_owner.?)) {
|
if (child_owner == null or (child_owner.? != self_owner.?)) {
|
||||||
const w = Walker{};
|
const w = Walker{};
|
||||||
var current = child;
|
var current = child;
|
||||||
@@ -307,27 +307,28 @@ pub const Node = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn _insertBefore(self: *parser.Node, new_node: *parser.Node, ref_node_: ?*parser.Node) !Union {
|
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 self_owner = try parser.nodeOwnerDocument(self);
|
||||||
const new_node_owner = try parser.nodeOwnerDocument(new_node);
|
const new_node_owner = try parser.nodeOwnerDocument(new_node);
|
||||||
|
|
||||||
// If the node to be inserted has a different ownerDocument than the parent node,
|
// If the node to be inserted has a different ownerDocument than the parent node,
|
||||||
// modern browsers automatically adopt the node and its descendants into
|
// modern browsers automatically adopt the node and its descendants into
|
||||||
// the parent's ownerDocument.
|
// the parent's ownerDocument.
|
||||||
// This process is known as adoption.
|
// This process is known as adoption.
|
||||||
// (7.1) https://dom.spec.whatwg.org/#concept-node-insert
|
// (7.1) https://dom.spec.whatwg.org/#concept-node-insert
|
||||||
if (new_node_owner == null or (new_node_owner.? != self_owner.?)) {
|
if (new_node_owner == null or (new_node_owner.? != self_owner.?)) {
|
||||||
const w = Walker{};
|
const w = Walker{};
|
||||||
var current = new_node;
|
var current = new_node;
|
||||||
while(true) {
|
while (true) {
|
||||||
current.owner = self_owner;
|
current.owner = self_owner;
|
||||||
current = try w.get_next(new_node, current) orelse break;
|
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 Node.toInterface(try parser.nodeInsertBefore(self, new_node, ref_node));
|
|
||||||
}
|
|
||||||
return _appendChild(self, new_node);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn _isDefaultNamespace(self: *parser.Node, namespace: ?[]const u8) !bool {
|
pub fn _isDefaultNamespace(self: *parser.Node, namespace: ?[]const u8) !bool {
|
||||||
@@ -756,7 +757,7 @@ test "Browser.DOM.node" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test "Browser.DOM.node.owner" {
|
test "Browser.DOM.node.owner" {
|
||||||
var runner = try testing.jsRunner(testing.tracking_allocator, .{ .html=
|
var runner = try testing.jsRunner(testing.tracking_allocator, .{ .html =
|
||||||
\\ <div id="target-container">
|
\\ <div id="target-container">
|
||||||
\\ <p id="reference-node">
|
\\ <p id="reference-node">
|
||||||
\\ I am the original reference node.
|
\\ I am the original reference node.
|
||||||
@@ -770,12 +771,9 @@ test "Browser.DOM.node.owner" {
|
|||||||
.{
|
.{
|
||||||
\\ const parser = new DOMParser();
|
\\ const parser = new DOMParser();
|
||||||
\\ const newDoc = parser.parseFromString('<div id="new-node"><p>Hey</p><span>Marked</span></div>', 'text/html');
|
\\ const newDoc = parser.parseFromString('<div id="new-node"><p>Hey</p><span>Marked</span></div>', 'text/html');
|
||||||
|
|
||||||
\\ const newNode = newDoc.getElementById('new-node');
|
\\ const newNode = newDoc.getElementById('new-node');
|
||||||
|
|
||||||
\\ const parent = document.getElementById('target-container');
|
\\ const parent = document.getElementById('target-container');
|
||||||
\\ const referenceNode = document.getElementById('reference-node');
|
\\ const referenceNode = document.getElementById('reference-node');
|
||||||
|
|
||||||
\\ parent.insertBefore(newNode, referenceNode);
|
\\ parent.insertBefore(newNode, referenceNode);
|
||||||
\\ const k = document.getElementById('new-node');
|
\\ const k = document.getElementById('new-node');
|
||||||
\\ const ptag = k.querySelector('p');
|
\\ const ptag = k.querySelector('p');
|
||||||
@@ -784,18 +782,18 @@ test "Browser.DOM.node.owner" {
|
|||||||
\\ const anotherNewNode = anotherDoc.getElementById('another-new-node');
|
\\ const anotherNewNode = anotherDoc.getElementById('another-new-node');
|
||||||
\\
|
\\
|
||||||
\\ parent.appendChild(anotherNewNode)
|
\\ parent.appendChild(anotherNewNode)
|
||||||
,
|
,
|
||||||
"[object HTMLDivElement]",
|
"[object HTMLDivElement]",
|
||||||
},
|
},
|
||||||
|
|
||||||
.{"parent.ownerDocument === newNode.ownerDocument", "true" },
|
.{ "parent.ownerDocument === newNode.ownerDocument", "true" },
|
||||||
.{"parent.ownerDocument === anotherNewNode.ownerDocument", "true"},
|
.{ "parent.ownerDocument === anotherNewNode.ownerDocument", "true" },
|
||||||
.{"newNode.firstChild.nodeName", "P"},
|
.{ "newNode.firstChild.nodeName", "P" },
|
||||||
.{"ptag.ownerDocument === parent.ownerDocument", "true"},
|
.{ "ptag.ownerDocument === parent.ownerDocument", "true" },
|
||||||
.{"spanTag.ownerDocument === parent.ownerDocument", "true"},
|
.{ "spanTag.ownerDocument === parent.ownerDocument", "true" },
|
||||||
.{"parent.contains(newNode)", "true"},
|
.{ "parent.contains(newNode)", "true" },
|
||||||
.{"parent.contains(anotherNewNode)", "true"},
|
.{ "parent.contains(anotherNewNode)", "true" },
|
||||||
.{"anotherDoc.contains(anotherNewNode)", "false"},
|
.{ "anotherDoc.contains(anotherNewNode)", "false" },
|
||||||
.{"newDoc.contains(newNode)", "false"},
|
.{ "newDoc.contains(newNode)", "false" },
|
||||||
}, .{});
|
}, .{});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user