mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-04-04 08:30:31 +00:00
dom: reimplement nodelist in pure zig
This commit is contained in:
@@ -14,6 +14,7 @@ const EventTarget = @import("event_target.zig").EventTarget;
|
||||
const Attr = @import("attribute.zig").Attr;
|
||||
const CData = @import("character_data.zig");
|
||||
const Element = @import("element.zig").Element;
|
||||
const NodeList = @import("nodelist.zig").NodeList;
|
||||
const Document = @import("document.zig").Document;
|
||||
const DocumentType = @import("document_type.zig").DocumentType;
|
||||
const DocumentFragment = @import("document_fragment.zig").DocumentFragment;
|
||||
@@ -193,8 +194,15 @@ pub const Node = struct {
|
||||
return try parser.nodeHasChildNodes(self);
|
||||
}
|
||||
|
||||
pub fn get_childNodes(self: *parser.Node) !*parser.NodeList {
|
||||
return try parser.nodeGetChildNodes(self);
|
||||
pub fn get_childNodes(self: *parser.Node, alloc: std.mem.Allocator) !*NodeList {
|
||||
const list = try NodeList.init(alloc);
|
||||
errdefer list.deinit(alloc);
|
||||
|
||||
var n = try parser.nodeFirstChild(self) orelse return list;
|
||||
while (true) {
|
||||
try list.append(n);
|
||||
n = try parser.nodeNextSibling(n) orelse return list;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn _insertBefore(self: *parser.Node, new_node: *parser.Node, ref_node: *parser.Node) !*parser.Node {
|
||||
@@ -246,6 +254,8 @@ pub const Node = struct {
|
||||
const res = try parser.nodeReplaceChild(self, new_child, old_child);
|
||||
return try Node.toInterface(res);
|
||||
}
|
||||
|
||||
pub fn deinit(_: *parser.Node, _: std.mem.Allocator) void {}
|
||||
};
|
||||
|
||||
// Tests
|
||||
|
||||
Reference in New Issue
Block a user