Applies changes from jsruntime Self and mem_guaranteed

Signed-off-by: Francis Bouvier <francis.bouvier@gmail.com>
This commit is contained in:
Francis Bouvier
2023-06-02 16:54:57 +02:00
parent 8f2d59172b
commit e0eee45156
9 changed files with 318 additions and 538 deletions

View File

@@ -6,30 +6,20 @@ const Node = @import("node.zig").Node;
const Element = @import("element.zig").Element;
pub const Document = struct {
proto: Node,
base: ?*parser.Document,
pub const Self = parser.Document;
pub const prototype = *Node;
pub const mem_guarantied = true;
pub fn init(base: ?*parser.Document) Document {
return .{
.proto = Node.init(null),
.base = base,
};
}
// pub fn constructor() *parser.Document {
// // TODO
// return .{};
// }
pub fn constructor() Document {
return Document.init(null);
}
pub fn getElementById(self: Document, elem_dom: *parser.Element, id: []const u8) ?Element {
if (self.base == null) {
return null;
}
const collection = parser.collectionInit(self.base.?, 1);
pub fn getElementById(self: *parser.Document, elem: *parser.Element, id: []const u8) ?*parser.Element {
const collection = parser.collectionInit(self, 1);
defer parser.collectionDeinit(collection);
const case_sensitve = true;
parser.elementsByAttr(elem_dom, collection, "id", id, case_sensitve) catch |err| {
parser.elementsByAttr(elem, collection, "id", id, case_sensitve) catch |err| {
std.debug.print("getElementById error: {s}\n", .{@errorName(err)});
return null;
};
@@ -37,19 +27,18 @@ pub const Document = struct {
// no results
return null;
}
const element_base = parser.collectionElement(collection, 0);
return Element.init(element_base);
return parser.collectionElement(collection, 0);
}
// JS funcs
// --------
pub fn get_body(_: Document) ?void {
pub fn get_body(_: *parser.Document) ?*parser.Body {
// TODO
return null;
}
pub fn _getElementById(_: Document, _: []u8) ?Element {
pub fn _getElementById(_: *parser.Document, _: []u8) ?*parser.Element {
// TODO
return null;
}

View File

@@ -5,22 +5,14 @@ const parser = @import("../parser.zig");
const Node = @import("node.zig").Node;
pub const Element = struct {
proto: Node,
base: *parser.Element,
pub const Self = parser.Element;
pub const prototype = *Node;
pub fn init(base: *parser.Element) Element {
return .{
.proto = Node.init(null),
.base = base,
};
}
pub const mem_guarantied = true;
// JS funcs
// --------
pub fn get_localName(self: Element) []const u8 {
return parser.elementLocalName(self.base);
pub fn get_localName(self: *parser.Element) []const u8 {
return parser.elementLocalName(self);
}
};

View File

@@ -1,13 +1,6 @@
const parser = @import("../parser.zig");
pub const EventTarget = struct {
base: ?*parser.EventTarget = null,
pub fn init(base: ?*parser.EventTarget) EventTarget {
return .{ .base = base };
}
pub fn constructor() EventTarget {
return .{};
}
pub const Self = parser.EventTarget;
pub const mem_guarantied = true;
};

View File

@@ -18,19 +18,11 @@ pub fn create_tree(node: ?*parser.Node, _: ?*anyopaque) callconv(.C) parser.Acti
}
pub const Node = struct {
proto: EventTarget,
base: ?*parser.Node = null,
pub const Self = parser.Node;
pub const prototype = *EventTarget;
pub const mem_guarantied = true;
pub fn init(base: ?*parser.Node) Node {
return .{ .proto = EventTarget.init(null), .base = base };
}
pub fn make_tree(self: Node) !void {
if (self.base) |node| {
try parser.nodeWalk(node, create_tree);
}
return error.NodeParserNull;
pub fn make_tree(self: *parser.Node) !void {
try parser.nodeWalk(self, create_tree);
}
};