node: implement getRootNode

This commit is contained in:
Pierre Tachoire
2024-10-17 14:43:58 +02:00
parent b64f7d013d
commit 8dc757ddf3

View File

@@ -251,10 +251,13 @@ pub const Node = struct {
return try parser.nodeContains(self, other); return try parser.nodeContains(self, other);
} }
pub fn _getRootNode(self: *parser.Node) void { pub fn _getRootNode(self: *parser.Node) !?HTMLElem.Union {
// TODO // TODO return thiss shadow-including root if options["composed"] is true
_ = self; const res = try parser.nodeOwnerDocument(self);
std.log.err("Not implemented {s}", .{"node.getRootNode()"}); if (res == null) {
return null;
}
return try HTMLElem.toInterface(HTMLElem.Union, @as(*parser.Element, @ptrCast(res.?)));
} }
pub fn _hasChildNodes(self: *parser.Node) !bool { pub fn _hasChildNodes(self: *parser.Node) !bool {
@@ -439,6 +442,11 @@ pub fn testExecFn(
}; };
try checkCases(js_env, &node_compare_document_position); try checkCases(js_env, &node_compare_document_position);
var get_root_node = [_]Case{
.{ .src = "document.getElementById('content').getRootNode().__proto__.constructor.name", .ex = "HTMLDocument" },
};
try checkCases(js_env, &get_root_node);
var first_child = [_]Case{ var first_child = [_]Case{
// for next test cases // for next test cases
.{ .src = "let content = document.getElementById('content')", .ex = "undefined" }, .{ .src = "let content = document.getElementById('content')", .ex = "undefined" },