node: add hasChildnodes method

Signed-off-by: Francis Bouvier <francis.bouvier@gmail.com>
This commit is contained in:
Francis Bouvier
2023-09-26 17:55:21 +02:00
parent 97b2435a13
commit 1e352c48ac
2 changed files with 16 additions and 0 deletions

View File

@@ -150,6 +150,10 @@ pub const Node = struct {
_ = self;
@panic("Not implemented node.getRootNode()");
}
pub fn _hasChildNodes(self: *parser.Node) bool {
return parser.nodeHasChildNodes(self);
}
};
pub const Types = generate.Tuple(.{
@@ -290,4 +294,10 @@ pub fn testExecFn(
.{ .src = "text.contains(link)", .ex = "false" },
};
try checkCases(js_env, &node_contains);
var node_has_child_nodes = [_]Case{
.{ .src = "link.hasChildNodes()", .ex = "true" },
.{ .src = "text.hasChildNodes()", .ex = "false" },
};
try checkCases(js_env, &node_has_child_nodes);
}

View File

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