node: add isSameNode method

Signed-off-by: Francis Bouvier <francis.bouvier@gmail.com>
This commit is contained in:
Francis Bouvier
2023-09-28 17:49:07 +02:00
parent 9b544db2a9
commit 24dc25391e
2 changed files with 17 additions and 0 deletions

View File

@@ -169,6 +169,12 @@ pub const Node = struct {
return parser.nodeIsEqualNode(self, other);
}
pub fn _isSameNode(self: *parser.Node, other: *parser.Node) bool {
// TODO: other is not an optional parameter, but can be null.
// NOTE: there is no need to use isSameNode(); instead use the === strict equality operator
return parser.nodeIsSameNode(self, other);
}
pub fn _normalize(self: *parser.Node) void {
return parser.nodeNormalize(self);
}
@@ -353,6 +359,11 @@ pub fn testExecFn(
};
try checkCases(js_env, &node_is_equal_node);
var node_is_same_node = [_]Case{
.{ .src = "document.body.isSameNode(document.body)", .ex = "true" },
};
try checkCases(js_env, &node_is_same_node);
var node_normalize = [_]Case{
// TODO: no test
.{ .src = "link.normalize()", .ex = "undefined" },

View File

@@ -377,6 +377,12 @@ pub fn nodeIsEqualNode(node: *Node, other: *Node) bool {
return res;
}
pub fn nodeIsSameNode(node: *Node, other: *Node) bool {
var res: bool = undefined;
_ = nodeVtable(node).dom_node_is_same.?(node, other, &res);
return res;
}
pub fn nodeNormalize(node: *Node) void {
_ = nodeVtable(node).dom_node_normalize.?(node);
}