node: add contains method

Signed-off-by: Francis Bouvier <francis.bouvier@gmail.com>
This commit is contained in:
Francis Bouvier
2023-09-26 17:32:13 +02:00
parent a0751e07e3
commit 70a66a95da
2 changed files with 16 additions and 0 deletions

View File

@@ -141,6 +141,10 @@ pub const Node = struct {
_ = self;
@panic("Not implemented node.compareDocumentPosition()");
}
pub fn _contains(self: *parser.Node, other: *parser.Node) bool {
return parser.nodeContains(self, other);
}
};
pub const Types = generate.Tuple(.{
@@ -275,4 +279,10 @@ pub fn testExecFn(
.{ .src = "clone_deep.firstChild.nodeName === '#text'", .ex = "true" },
};
try checkCases(js_env, &node_clone);
var node_contains = [_]Case{
.{ .src = "link.contains(text)", .ex = "true" },
.{ .src = "text.contains(link)", .ex = "false" },
};
try checkCases(js_env, &node_contains);
}

View File

@@ -346,6 +346,12 @@ pub fn nodeCloneNode(node: *Node, is_deep: bool) *Node {
return res.?;
}
pub fn nodeContains(node: *Node, other: *Node) bool {
var res: bool = undefined;
_ = c._dom_node_contains(node, other, &res);
return res;
}
// CharacterData
pub const CharacterData = c.dom_characterdata;