dom: implement document.adoptNode

This commit is contained in:
Pierre Tachoire
2023-12-07 17:31:04 +01:00
parent 3ec5cee98c
commit 82148da5f6
2 changed files with 18 additions and 0 deletions

View File

@@ -149,6 +149,10 @@ pub const Document = struct {
return try parser.documentImportNode(self, node, deep orelse false);
}
pub fn _adoptNode(self: *parser.Document, node: *parser.Node) !*parser.Node {
return try parser.documentAdoptNode(self, node);
}
pub fn deinit(_: *parser.Document, _: std.mem.Allocator) void {}
};
@@ -273,6 +277,12 @@ pub fn testExecFn(
};
try checkCases(js_env, &importNode);
var adoptNode = [_]Case{
.{ .src = "let nadop = document.getElementById('content')", .ex = "undefined" },
.{ .src = "document.adoptNode(nadop)", .ex = "[object Node]" },
};
try checkCases(js_env, &adoptNode);
const tags = comptime parser.Tag.all();
comptime var createElements: [(tags.len) * 2]Case = undefined;
inline for (tags, 0..) |tag, i| {

View File

@@ -1184,6 +1184,14 @@ pub inline fn documentImportNode(doc: *Document, node: *Node, deep: bool) !*Node
return @as(*Node, @ptrCast(res));
}
pub inline fn documentAdoptNode(doc: *Document, node: *Node) !*Node {
var res: NodeExternal = undefined;
const nodeext = toNodeExternal(Node, node);
const err = documentVtable(doc).dom_document_adopt_node.?(doc, nodeext, &res);
try DOMErr(err);
return @as(*Node, @ptrCast(res));
}
// DocumentHTML
pub const DocumentHTML = c.dom_html_document;