mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-30 07:31:47 +00:00
nodelist: return struct instead of pointer
This commit is contained in:
@@ -210,8 +210,8 @@ pub const Document = struct {
|
|||||||
// TODO netsurf doesn't handle query selectors. We have to implement a
|
// TODO netsurf doesn't handle query selectors. We have to implement a
|
||||||
// solution by ourselves.
|
// solution by ourselves.
|
||||||
// We handle only * and single id selector like `#foo`.
|
// We handle only * and single id selector like `#foo`.
|
||||||
pub fn _querySelectorAll(self: *parser.Document, alloc: std.mem.Allocator, selectors: []const u8) !*NodeList {
|
pub fn _querySelectorAll(self: *parser.Document, alloc: std.mem.Allocator, selectors: []const u8) !NodeList {
|
||||||
const list = try NodeList.init(alloc);
|
var list = try NodeList.init();
|
||||||
errdefer list.deinit(alloc);
|
errdefer list.deinit(alloc);
|
||||||
|
|
||||||
if (selectors.len == 0) return list;
|
if (selectors.len == 0) return list;
|
||||||
|
|||||||
@@ -229,8 +229,8 @@ pub const Element = struct {
|
|||||||
// TODO netsurf doesn't handle query selectors. We have to implement a
|
// TODO netsurf doesn't handle query selectors. We have to implement a
|
||||||
// solution by ourselves.
|
// solution by ourselves.
|
||||||
// We handle only * and single id selector like `#foo`.
|
// We handle only * and single id selector like `#foo`.
|
||||||
pub fn _querySelectorAll(self: *parser.Element, alloc: std.mem.Allocator, selectors: []const u8) !*NodeList {
|
pub fn _querySelectorAll(self: *parser.Element, alloc: std.mem.Allocator, selectors: []const u8) !NodeList {
|
||||||
const list = try NodeList.init(alloc);
|
var list = try NodeList.init();
|
||||||
errdefer list.deinit(alloc);
|
errdefer list.deinit(alloc);
|
||||||
|
|
||||||
if (selectors.len == 0) return list;
|
if (selectors.len == 0) return list;
|
||||||
|
|||||||
@@ -194,8 +194,8 @@ pub const Node = struct {
|
|||||||
return try parser.nodeHasChildNodes(self);
|
return try parser.nodeHasChildNodes(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_childNodes(self: *parser.Node, alloc: std.mem.Allocator) !*NodeList {
|
pub fn get_childNodes(self: *parser.Node, alloc: std.mem.Allocator) !NodeList {
|
||||||
const list = try NodeList.init(alloc);
|
var list = try NodeList.init();
|
||||||
errdefer list.deinit(alloc);
|
errdefer list.deinit(alloc);
|
||||||
|
|
||||||
var n = try parser.nodeFirstChild(self) orelse return list;
|
var n = try parser.nodeFirstChild(self) orelse return list;
|
||||||
|
|||||||
@@ -22,19 +22,15 @@ pub const NodeList = struct {
|
|||||||
|
|
||||||
nodes: NodesArrayList,
|
nodes: NodesArrayList,
|
||||||
|
|
||||||
pub fn init(alloc: std.mem.Allocator) !*NodeList {
|
pub fn init() !NodeList {
|
||||||
const list = try alloc.create(NodeList);
|
return NodeList{
|
||||||
list.* = NodeList{
|
|
||||||
.nodes = NodesArrayList{},
|
.nodes = NodesArrayList{},
|
||||||
};
|
};
|
||||||
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(self: *NodeList, alloc: std.mem.Allocator) void {
|
pub fn deinit(self: *NodeList, alloc: std.mem.Allocator) void {
|
||||||
// TODO unref all nodes
|
// TODO unref all nodes
|
||||||
self.nodes.deinit(alloc);
|
self.nodes.deinit(alloc);
|
||||||
alloc.destroy(self);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn append(self: *NodeList, alloc: std.mem.Allocator, node: *parser.Node) !void {
|
pub fn append(self: *NodeList, alloc: std.mem.Allocator, node: *parser.Node) !void {
|
||||||
|
|||||||
Reference in New Issue
Block a user