mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-12-16 16:28:58 +00:00
@@ -29,57 +29,57 @@ pub const CharacterData = struct {
|
||||
|
||||
// Read attributes
|
||||
|
||||
pub fn get_length(self: *parser.CharacterData) u32 {
|
||||
return parser.characterDataLength(self);
|
||||
pub fn get_length(self: *parser.CharacterData) !u32 {
|
||||
return try parser.characterDataLength(self);
|
||||
}
|
||||
|
||||
pub fn get_nextElementSibling(self: *parser.CharacterData) ?HTMLElem.Union {
|
||||
const res = parser.nodeNextElementSibling(parser.characterDataToNode(self));
|
||||
pub fn get_nextElementSibling(self: *parser.CharacterData) !?HTMLElem.Union {
|
||||
const res = try parser.nodeNextElementSibling(parser.characterDataToNode(self));
|
||||
if (res == null) {
|
||||
return null;
|
||||
}
|
||||
return HTMLElem.toInterface(HTMLElem.Union, res.?);
|
||||
return try HTMLElem.toInterface(HTMLElem.Union, res.?);
|
||||
}
|
||||
|
||||
pub fn get_previousElementSibling(self: *parser.CharacterData) ?HTMLElem.Union {
|
||||
const res = parser.nodePreviousElementSibling(parser.characterDataToNode(self));
|
||||
pub fn get_previousElementSibling(self: *parser.CharacterData) !?HTMLElem.Union {
|
||||
const res = try parser.nodePreviousElementSibling(parser.characterDataToNode(self));
|
||||
if (res == null) {
|
||||
return null;
|
||||
}
|
||||
return HTMLElem.toInterface(HTMLElem.Union, res.?);
|
||||
return try HTMLElem.toInterface(HTMLElem.Union, res.?);
|
||||
}
|
||||
|
||||
// Read/Write attributes
|
||||
|
||||
pub fn get_data(self: *parser.CharacterData) []const u8 {
|
||||
return parser.characterDataData(self);
|
||||
pub fn get_data(self: *parser.CharacterData) ![]const u8 {
|
||||
return try parser.characterDataData(self);
|
||||
}
|
||||
|
||||
pub fn set_data(self: *parser.CharacterData, data: []const u8) void {
|
||||
return parser.characterDataSetData(self, data);
|
||||
pub fn set_data(self: *parser.CharacterData, data: []const u8) !void {
|
||||
return try parser.characterDataSetData(self, data);
|
||||
}
|
||||
|
||||
// JS methods
|
||||
// ----------
|
||||
|
||||
pub fn _appendData(self: *parser.CharacterData, data: []const u8) void {
|
||||
return parser.characterDataAppendData(self, data);
|
||||
pub fn _appendData(self: *parser.CharacterData, data: []const u8) !void {
|
||||
return try parser.characterDataAppendData(self, data);
|
||||
}
|
||||
|
||||
pub fn _deleteData(self: *parser.CharacterData, offset: u32, count: u32) void {
|
||||
return parser.characterDataDeleteData(self, offset, count);
|
||||
pub fn _deleteData(self: *parser.CharacterData, offset: u32, count: u32) !void {
|
||||
return try parser.characterDataDeleteData(self, offset, count);
|
||||
}
|
||||
|
||||
pub fn _insertData(self: *parser.CharacterData, offset: u32, data: []const u8) void {
|
||||
return parser.characterDataInsertData(self, offset, data);
|
||||
pub fn _insertData(self: *parser.CharacterData, offset: u32, data: []const u8) !void {
|
||||
return try parser.characterDataInsertData(self, offset, data);
|
||||
}
|
||||
|
||||
pub fn _replaceData(self: *parser.CharacterData, offset: u32, count: u32, data: []const u8) void {
|
||||
return parser.characterDataReplaceData(self, offset, count, data);
|
||||
pub fn _replaceData(self: *parser.CharacterData, offset: u32, count: u32, data: []const u8) !void {
|
||||
return try parser.characterDataReplaceData(self, offset, count, data);
|
||||
}
|
||||
|
||||
pub fn _substringData(self: *parser.CharacterData, offset: u32, count: u32) []const u8 {
|
||||
return parser.characterDataSubstringData(self, offset, count);
|
||||
pub fn _substringData(self: *parser.CharacterData, offset: u32, count: u32) ![]const u8 {
|
||||
return try parser.characterDataSubstringData(self, offset, count);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -22,28 +22,27 @@ pub const Document = struct {
|
||||
pub const prototype = *Node;
|
||||
pub const mem_guarantied = true;
|
||||
|
||||
pub fn constructor() *parser.Document {
|
||||
return parser.domImplementationCreateHTMLDocument(null);
|
||||
pub fn constructor() !*parser.Document {
|
||||
return try parser.domImplementationCreateHTMLDocument(null);
|
||||
}
|
||||
|
||||
// JS funcs
|
||||
// --------
|
||||
|
||||
pub fn get_implementation(_: *parser.Document) DOMImplementation {
|
||||
return DOMImplementation{};
|
||||
}
|
||||
|
||||
pub fn get_documentElement(self: *parser.Document) ElementUnion {
|
||||
const e = parser.documentGetDocumentElement(self);
|
||||
return Element.toInterface(e);
|
||||
pub fn get_documentElement(self: *parser.Document) !ElementUnion {
|
||||
const e = try parser.documentGetDocumentElement(self);
|
||||
return try Element.toInterface(e);
|
||||
}
|
||||
|
||||
pub fn get_documentURI(self: *parser.Document) []const u8 {
|
||||
return parser.documentGetDocumentURI(self);
|
||||
pub fn get_documentURI(self: *parser.Document) ![]const u8 {
|
||||
return try parser.documentGetDocumentURI(self);
|
||||
}
|
||||
|
||||
pub fn get_URL(self: *parser.Document) []const u8 {
|
||||
return get_documentURI(self);
|
||||
pub fn get_URL(self: *parser.Document) ![]const u8 {
|
||||
return try get_documentURI(self);
|
||||
}
|
||||
|
||||
// TODO implement contentType
|
||||
@@ -58,37 +57,37 @@ pub const Document = struct {
|
||||
return "CSS1Compat";
|
||||
}
|
||||
|
||||
pub fn get_characterSet(self: *parser.Document) []const u8 {
|
||||
return parser.documentGetInputEncoding(self);
|
||||
pub fn get_characterSet(self: *parser.Document) ![]const u8 {
|
||||
return try parser.documentGetInputEncoding(self);
|
||||
}
|
||||
|
||||
// alias of get_characterSet
|
||||
pub fn get_charset(self: *parser.Document) []const u8 {
|
||||
return get_characterSet(self);
|
||||
pub fn get_charset(self: *parser.Document) ![]const u8 {
|
||||
return try get_characterSet(self);
|
||||
}
|
||||
|
||||
// alias of get_characterSet
|
||||
pub fn get_inputEncoding(self: *parser.Document) []const u8 {
|
||||
return get_characterSet(self);
|
||||
pub fn get_inputEncoding(self: *parser.Document) ![]const u8 {
|
||||
return try get_characterSet(self);
|
||||
}
|
||||
|
||||
pub fn get_doctype(self: *parser.Document) ?*parser.DocumentType {
|
||||
return parser.documentGetDoctype(self);
|
||||
pub fn get_doctype(self: *parser.Document) !?*parser.DocumentType {
|
||||
return try parser.documentGetDoctype(self);
|
||||
}
|
||||
|
||||
pub fn _getElementById(self: *parser.Document, id: []const u8) ?ElementUnion {
|
||||
const e = parser.documentGetElementById(self, id) orelse return null;
|
||||
return Element.toInterface(e);
|
||||
pub fn _getElementById(self: *parser.Document, id: []const u8) !?ElementUnion {
|
||||
const e = try parser.documentGetElementById(self, id) orelse return null;
|
||||
return try Element.toInterface(e);
|
||||
}
|
||||
|
||||
pub fn _createElement(self: *parser.Document, tag_name: []const u8) ElementUnion {
|
||||
const e = parser.documentCreateElement(self, tag_name);
|
||||
return Element.toInterface(e);
|
||||
pub fn _createElement(self: *parser.Document, tag_name: []const u8) !ElementUnion {
|
||||
const e = try parser.documentCreateElement(self, tag_name);
|
||||
return try Element.toInterface(e);
|
||||
}
|
||||
|
||||
pub fn _createElementNS(self: *parser.Document, ns: []const u8, tag_name: []const u8) ElementUnion {
|
||||
const e = parser.documentCreateElementNS(self, ns, tag_name);
|
||||
return Element.toInterface(e);
|
||||
pub fn _createElementNS(self: *parser.Document, ns: []const u8, tag_name: []const u8) !ElementUnion {
|
||||
const e = try parser.documentCreateElementNS(self, ns, tag_name);
|
||||
return try Element.toInterface(e);
|
||||
}
|
||||
|
||||
// We can't simply use libdom dom_document_get_elements_by_tag_name here.
|
||||
@@ -104,7 +103,7 @@ pub const Document = struct {
|
||||
alloc: std.mem.Allocator,
|
||||
tag_name: []const u8,
|
||||
) !collection.HTMLCollection {
|
||||
const root = parser.documentGetDocumentElement(self);
|
||||
const root = try parser.documentGetDocumentElement(self);
|
||||
return try collection.HTMLCollectionByTagName(
|
||||
alloc,
|
||||
parser.elementToNode(root),
|
||||
@@ -117,7 +116,7 @@ pub const Document = struct {
|
||||
alloc: std.mem.Allocator,
|
||||
classNames: []const u8,
|
||||
) !collection.HTMLCollection {
|
||||
const root = parser.documentGetDocumentElement(self);
|
||||
const root = try parser.documentGetDocumentElement(self);
|
||||
return try collection.HTMLCollectionByClassName(
|
||||
alloc,
|
||||
parser.elementToNode(root),
|
||||
|
||||
@@ -10,15 +10,15 @@ pub const DocumentType = struct {
|
||||
pub const prototype = *Node;
|
||||
pub const mem_guarantied = true;
|
||||
|
||||
pub fn get_name(self: *parser.DocumentType) []const u8 {
|
||||
return parser.documentTypeGetName(self);
|
||||
pub fn get_name(self: *parser.DocumentType) ![]const u8 {
|
||||
return try parser.documentTypeGetName(self);
|
||||
}
|
||||
|
||||
pub fn get_publicId(self: *parser.DocumentType) []const u8 {
|
||||
return parser.documentTypeGetPublicId(self);
|
||||
pub fn get_publicId(self: *parser.DocumentType) ![]const u8 {
|
||||
return try parser.documentTypeGetPublicId(self);
|
||||
}
|
||||
|
||||
pub fn get_systemId(self: *parser.DocumentType) []const u8 {
|
||||
return parser.documentTypeGetSystemId(self);
|
||||
pub fn get_systemId(self: *parser.DocumentType) ![]const u8 {
|
||||
return try parser.documentTypeGetSystemId(self);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -12,14 +12,14 @@ pub const Element = struct {
|
||||
pub const prototype = *Node;
|
||||
pub const mem_guarantied = true;
|
||||
|
||||
pub fn toInterface(e: *parser.Element) Union {
|
||||
return HTMLElem.toInterface(Union, e);
|
||||
pub fn toInterface(e: *parser.Element) !Union {
|
||||
return try HTMLElem.toInterface(Union, e);
|
||||
}
|
||||
|
||||
// JS funcs
|
||||
// --------
|
||||
|
||||
pub fn get_localName(self: *parser.Element) []const u8 {
|
||||
return parser.elementLocalName(self);
|
||||
pub fn get_localName(self: *parser.Element) ![]const u8 {
|
||||
return try parser.elementLocalName(self);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -54,7 +54,11 @@ pub const DOMException = struct {
|
||||
.{ errName, callerName },
|
||||
),
|
||||
error.NoError => unreachable,
|
||||
else => "", // TODO: implement other messages
|
||||
else => try allocPrint(
|
||||
alloc,
|
||||
"{s}: TODO message", // TODO: implement other messages
|
||||
.{DOMException.name(errCast)},
|
||||
),
|
||||
};
|
||||
return .{ .err = errCast, .str = str };
|
||||
}
|
||||
@@ -154,6 +158,8 @@ pub fn testExecFn(
|
||||
.{ .src = "HierarchyRequestError.code", .ex = "3" },
|
||||
.{ .src = "HierarchyRequestError.message", .ex = err },
|
||||
.{ .src = "HierarchyRequestError.toString()", .ex = "HierarchyRequestError: " ++ err },
|
||||
.{ .src = "HierarchyRequestError instanceof DOMException", .ex = "true" },
|
||||
.{ .src = "HierarchyRequestError instanceof Error", .ex = "true" },
|
||||
};
|
||||
try checkCases(js_env, &cases);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ const Matcher = union(enum) {
|
||||
matchByTagName: MatchByTagName,
|
||||
matchByClassName: MatchByClassName,
|
||||
|
||||
pub fn match(self: Matcher, node: *parser.Node) bool {
|
||||
pub fn match(self: Matcher, node: *parser.Node) !bool {
|
||||
switch (self) {
|
||||
inline else => |case| return case.match(node),
|
||||
}
|
||||
@@ -43,8 +43,8 @@ pub const MatchByTagName = struct {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn match(self: MatchByTagName, node: *parser.Node) bool {
|
||||
return self.is_wildcard or std.ascii.eqlIgnoreCase(self.tag, parser.nodeName(node));
|
||||
pub fn match(self: MatchByTagName, node: *parser.Node) !bool {
|
||||
return self.is_wildcard or std.ascii.eqlIgnoreCase(self.tag, try parser.nodeName(node));
|
||||
}
|
||||
|
||||
fn deinit(self: MatchByTagName, alloc: std.mem.Allocator) void {
|
||||
@@ -76,11 +76,11 @@ pub const MatchByClassName = struct {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn match(self: MatchByClassName, node: *parser.Node) bool {
|
||||
pub fn match(self: MatchByClassName, node: *parser.Node) !bool {
|
||||
var it = std.mem.splitAny(u8, self.classNames, " ");
|
||||
const e = parser.nodeToElement(node);
|
||||
while (it.next()) |c| {
|
||||
if (!parser.elementHasClass(e, c)) {
|
||||
if (!try parser.elementHasClass(e, c)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -130,24 +130,24 @@ pub const HTMLCollection = struct {
|
||||
// The iteration is a depth first as required by the specification.
|
||||
// https://dom.spec.whatwg.org/#htmlcollection
|
||||
// https://dom.spec.whatwg.org/#concept-tree-order
|
||||
fn get_next(root: *parser.Node, cur: *parser.Node) ?*parser.Node {
|
||||
fn get_next(root: *parser.Node, cur: *parser.Node) !?*parser.Node {
|
||||
// TODO deinit next
|
||||
if (parser.nodeFirstChild(cur)) |next| {
|
||||
if (try parser.nodeFirstChild(cur)) |next| {
|
||||
return next;
|
||||
}
|
||||
|
||||
// TODO deinit next
|
||||
if (parser.nodeNextSibling(cur)) |next| {
|
||||
if (try parser.nodeNextSibling(cur)) |next| {
|
||||
return next;
|
||||
}
|
||||
|
||||
// TODO deinit parent
|
||||
// Back to the parent of cur.
|
||||
// If cur has no parent, then the iteration is over.
|
||||
var parent = parser.nodeParentNode(cur) orelse return null;
|
||||
var parent = try parser.nodeParentNode(cur) orelse return null;
|
||||
|
||||
// TODO deinit lastchild
|
||||
var lastchild = parser.nodeLastChild(parent);
|
||||
var lastchild = try parser.nodeLastChild(parent);
|
||||
var prev = cur;
|
||||
while (prev != root and prev == lastchild) {
|
||||
prev = parent;
|
||||
@@ -155,42 +155,42 @@ pub const HTMLCollection = struct {
|
||||
// TODO deinit parent
|
||||
// Back to the prev's parent.
|
||||
// If prev has no parent, then the loop must stop.
|
||||
parent = parser.nodeParentNode(prev) orelse break;
|
||||
parent = try parser.nodeParentNode(prev) orelse break;
|
||||
|
||||
// TODO deinit lastchild
|
||||
lastchild = parser.nodeLastChild(parent);
|
||||
lastchild = try parser.nodeLastChild(parent);
|
||||
}
|
||||
|
||||
if (prev == root) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return parser.nodeNextSibling(prev);
|
||||
return try parser.nodeNextSibling(prev);
|
||||
}
|
||||
|
||||
/// get_length computes the collection's length dynamically according to
|
||||
/// the current root structure.
|
||||
// TODO: nodes retrieved must be de-referenced.
|
||||
pub fn get_length(self: *HTMLCollection) u32 {
|
||||
pub fn get_length(self: *HTMLCollection) !u32 {
|
||||
var len: u32 = 0;
|
||||
var node: *parser.Node = self.root;
|
||||
var ntype: parser.NodeType = undefined;
|
||||
|
||||
while (true) {
|
||||
ntype = parser.nodeType(node);
|
||||
ntype = try parser.nodeType(node);
|
||||
if (ntype == .element) {
|
||||
if (self.matcher.match(node)) {
|
||||
if (try self.matcher.match(node)) {
|
||||
len += 1;
|
||||
}
|
||||
}
|
||||
|
||||
node = get_next(self.root, node) orelse break;
|
||||
node = try get_next(self.root, node) orelse break;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
pub fn _item(self: *HTMLCollection, index: u32) ?Union {
|
||||
pub fn _item(self: *HTMLCollection, index: u32) !?Union {
|
||||
var i: u32 = 0;
|
||||
var node: *parser.Node = self.root;
|
||||
var ntype: parser.NodeType = undefined;
|
||||
@@ -202,9 +202,9 @@ pub const HTMLCollection = struct {
|
||||
}
|
||||
|
||||
while (true) {
|
||||
ntype = parser.nodeType(node);
|
||||
ntype = try parser.nodeType(node);
|
||||
if (ntype == .element) {
|
||||
if (self.matcher.match(node)) {
|
||||
if (try self.matcher.match(node)) {
|
||||
// check if we found the searched element.
|
||||
if (i == index) {
|
||||
// save the current state
|
||||
@@ -212,20 +212,20 @@ pub const HTMLCollection = struct {
|
||||
self.cur_idx = i;
|
||||
|
||||
const e = @as(*parser.Element, @ptrCast(node));
|
||||
return Element.toInterface(e);
|
||||
return try Element.toInterface(e);
|
||||
}
|
||||
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
|
||||
node = get_next(self.root, node) orelse break;
|
||||
node = try get_next(self.root, node) orelse break;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
pub fn _namedItem(self: *HTMLCollection, name: []const u8) ?Union {
|
||||
pub fn _namedItem(self: *HTMLCollection, name: []const u8) !?Union {
|
||||
if (name.len == 0) {
|
||||
return null;
|
||||
}
|
||||
@@ -234,26 +234,26 @@ pub const HTMLCollection = struct {
|
||||
var ntype: parser.NodeType = undefined;
|
||||
|
||||
while (true) {
|
||||
ntype = parser.nodeType(node);
|
||||
ntype = try parser.nodeType(node);
|
||||
if (ntype == .element) {
|
||||
if (self.matcher.match(node)) {
|
||||
if (try self.matcher.match(node)) {
|
||||
const elem = @as(*parser.Element, @ptrCast(node));
|
||||
|
||||
var attr = parser.elementGetAttribute(elem, "id");
|
||||
var attr = try parser.elementGetAttribute(elem, "id");
|
||||
// check if the node id corresponds to the name argument.
|
||||
if (attr != null and std.mem.eql(u8, name, attr.?)) {
|
||||
return Element.toInterface(elem);
|
||||
return try Element.toInterface(elem);
|
||||
}
|
||||
|
||||
attr = parser.elementGetAttribute(elem, "name");
|
||||
attr = try parser.elementGetAttribute(elem, "name");
|
||||
// check if the node id corresponds to the name argument.
|
||||
if (attr != null and std.mem.eql(u8, name, attr.?)) {
|
||||
return Element.toInterface(elem);
|
||||
return try Element.toInterface(elem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
node = get_next(self.root, node) orelse break;
|
||||
node = try get_next(self.root, node) orelse break;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -8,11 +8,14 @@ const checkCases = jsruntime.test_utils.checkCases;
|
||||
|
||||
const Document = @import("document.zig").Document;
|
||||
const DocumentType = @import("document_type.zig").DocumentType;
|
||||
const DOMException = @import("exceptions.zig").DOMException;
|
||||
|
||||
// WEB IDL https://dom.spec.whatwg.org/#domimplementation
|
||||
pub const DOMImplementation = struct {
|
||||
pub const mem_guarantied = true;
|
||||
|
||||
pub const Exception = DOMException;
|
||||
|
||||
pub fn _createDocumentType(
|
||||
_: *DOMImplementation,
|
||||
alloc: std.mem.Allocator,
|
||||
@@ -29,7 +32,7 @@ pub const DOMImplementation = struct {
|
||||
const csystemId = try alloc.dupeZ(u8, systemId);
|
||||
defer alloc.free(csystemId);
|
||||
|
||||
return parser.domImplementationCreateDocumentType(cqname, cpublicId, csystemId);
|
||||
return try parser.domImplementationCreateDocumentType(cqname, cpublicId, csystemId);
|
||||
}
|
||||
|
||||
pub fn _createDocument(
|
||||
@@ -42,20 +45,20 @@ pub const DOMImplementation = struct {
|
||||
var cnamespace: ?[:0]const u8 = null;
|
||||
if (namespace) |ns| {
|
||||
cnamespace = try alloc.dupeZ(u8, ns);
|
||||
defer alloc.free(cnamespace.?);
|
||||
}
|
||||
defer if (cnamespace) |v| alloc.free(v);
|
||||
|
||||
var cqname: ?[:0]const u8 = null;
|
||||
if (qname) |qn| {
|
||||
cqname = try alloc.dupeZ(u8, qn);
|
||||
defer alloc.free(cqname.?);
|
||||
}
|
||||
defer if (cqname) |v| alloc.free(v);
|
||||
|
||||
return parser.domImplementationCreateDocument(cnamespace, cqname, doctype);
|
||||
return try parser.domImplementationCreateDocument(cnamespace, cqname, doctype);
|
||||
}
|
||||
|
||||
pub fn _createHTMLDocument(_: *DOMImplementation, title: ?[]const u8) *parser.Document {
|
||||
return parser.domImplementationCreateHTMLDocument(title);
|
||||
pub fn _createHTMLDocument(_: *DOMImplementation, title: ?[]const u8) !*parser.Document {
|
||||
return try parser.domImplementationCreateHTMLDocument(title);
|
||||
}
|
||||
|
||||
pub fn _hasFeature(_: *DOMImplementation) bool {
|
||||
|
||||
135
src/dom/node.zig
135
src/dom/node.zig
@@ -42,9 +42,12 @@ pub const Node = struct {
|
||||
pub const prototype = *EventTarget;
|
||||
pub const mem_guarantied = true;
|
||||
|
||||
pub fn toInterface(node: *parser.Node) Union {
|
||||
return switch (parser.nodeType(node)) {
|
||||
.element => HTMLElem.toInterface(Union, @as(*parser.Element, @ptrCast(node))),
|
||||
pub fn toInterface(node: *parser.Node) !Union {
|
||||
return switch (try parser.nodeType(node)) {
|
||||
.element => try HTMLElem.toInterface(
|
||||
Union,
|
||||
@as(*parser.Element, @ptrCast(node)),
|
||||
),
|
||||
.comment => .{ .Comment = @as(*parser.Comment, @ptrCast(node)) },
|
||||
.text => .{ .Text = @as(*parser.Text, @ptrCast(node)) },
|
||||
.document => .{ .HTMLDocument = @as(*parser.DocumentHTML, @ptrCast(node)) },
|
||||
@@ -58,94 +61,94 @@ pub const Node = struct {
|
||||
|
||||
// Read-only attributes
|
||||
|
||||
pub fn get_firstChild(self: *parser.Node) ?Union {
|
||||
const res = parser.nodeFirstChild(self);
|
||||
pub fn get_firstChild(self: *parser.Node) !?Union {
|
||||
const res = try parser.nodeFirstChild(self);
|
||||
if (res == null) {
|
||||
return null;
|
||||
}
|
||||
return Node.toInterface(res.?);
|
||||
return try Node.toInterface(res.?);
|
||||
}
|
||||
|
||||
pub fn get_lastChild(self: *parser.Node) ?Union {
|
||||
const res = parser.nodeLastChild(self);
|
||||
pub fn get_lastChild(self: *parser.Node) !?Union {
|
||||
const res = try parser.nodeLastChild(self);
|
||||
if (res == null) {
|
||||
return null;
|
||||
}
|
||||
return Node.toInterface(res.?);
|
||||
return try Node.toInterface(res.?);
|
||||
}
|
||||
|
||||
pub fn get_nextSibling(self: *parser.Node) ?Union {
|
||||
const res = parser.nodeNextSibling(self);
|
||||
pub fn get_nextSibling(self: *parser.Node) !?Union {
|
||||
const res = try parser.nodeNextSibling(self);
|
||||
if (res == null) {
|
||||
return null;
|
||||
}
|
||||
return Node.toInterface(res.?);
|
||||
return try Node.toInterface(res.?);
|
||||
}
|
||||
|
||||
pub fn get_previousSibling(self: *parser.Node) ?Union {
|
||||
const res = parser.nodePreviousSibling(self);
|
||||
pub fn get_previousSibling(self: *parser.Node) !?Union {
|
||||
const res = try parser.nodePreviousSibling(self);
|
||||
if (res == null) {
|
||||
return null;
|
||||
}
|
||||
return Node.toInterface(res.?);
|
||||
return try Node.toInterface(res.?);
|
||||
}
|
||||
|
||||
pub fn get_parentNode(self: *parser.Node) ?Union {
|
||||
const res = parser.nodeParentNode(self);
|
||||
pub fn get_parentNode(self: *parser.Node) !?Union {
|
||||
const res = try parser.nodeParentNode(self);
|
||||
if (res == null) {
|
||||
return null;
|
||||
}
|
||||
return Node.toInterface(res.?);
|
||||
return try Node.toInterface(res.?);
|
||||
}
|
||||
|
||||
pub fn get_parentElement(self: *parser.Node) ?HTMLElem.Union {
|
||||
const res = parser.nodeParentElement(self);
|
||||
pub fn get_parentElement(self: *parser.Node) !?HTMLElem.Union {
|
||||
const res = try parser.nodeParentElement(self);
|
||||
if (res == null) {
|
||||
return null;
|
||||
}
|
||||
return HTMLElem.toInterface(HTMLElem.Union, @as(*parser.Element, @ptrCast(res.?)));
|
||||
return try HTMLElem.toInterface(HTMLElem.Union, @as(*parser.Element, @ptrCast(res.?)));
|
||||
}
|
||||
|
||||
pub fn get_nodeName(self: *parser.Node) []const u8 {
|
||||
return parser.nodeName(self);
|
||||
pub fn get_nodeName(self: *parser.Node) ![]const u8 {
|
||||
return try parser.nodeName(self);
|
||||
}
|
||||
|
||||
pub fn get_nodeType(self: *parser.Node) u8 {
|
||||
return @intFromEnum(parser.nodeType(self));
|
||||
pub fn get_nodeType(self: *parser.Node) !u8 {
|
||||
return @intFromEnum(try parser.nodeType(self));
|
||||
}
|
||||
|
||||
pub fn get_ownerDocument(self: *parser.Node) ?*parser.DocumentHTML {
|
||||
const res = parser.nodeOwnerDocument(self);
|
||||
pub fn get_ownerDocument(self: *parser.Node) !?*parser.DocumentHTML {
|
||||
const res = try parser.nodeOwnerDocument(self);
|
||||
if (res == null) {
|
||||
return null;
|
||||
}
|
||||
return @as(*parser.DocumentHTML, @ptrCast(res.?));
|
||||
}
|
||||
|
||||
pub fn get_isConnected(self: *parser.Node) bool {
|
||||
pub fn get_isConnected(self: *parser.Node) !bool {
|
||||
// TODO: handle Shadow DOM
|
||||
if (parser.nodeType(self) == .document) {
|
||||
if (try parser.nodeType(self) == .document) {
|
||||
return true;
|
||||
}
|
||||
return Node.get_parentNode(self) != null;
|
||||
return try Node.get_parentNode(self) != null;
|
||||
}
|
||||
|
||||
// Read/Write attributes
|
||||
|
||||
pub fn get_nodeValue(self: *parser.Node) ?[]const u8 {
|
||||
return parser.nodeValue(self);
|
||||
pub fn get_nodeValue(self: *parser.Node) !?[]const u8 {
|
||||
return try parser.nodeValue(self);
|
||||
}
|
||||
|
||||
pub fn set_nodeValue(self: *parser.Node, data: []u8) void {
|
||||
parser.nodeSetValue(self, data);
|
||||
pub fn set_nodeValue(self: *parser.Node, data: []u8) !void {
|
||||
try parser.nodeSetValue(self, data);
|
||||
}
|
||||
|
||||
pub fn get_textContent(self: *parser.Node) ?[]const u8 {
|
||||
return parser.nodeTextContent(self);
|
||||
pub fn get_textContent(self: *parser.Node) !?[]const u8 {
|
||||
return try parser.nodeTextContent(self);
|
||||
}
|
||||
|
||||
pub fn set_textContent(self: *parser.Node, data: []u8) void {
|
||||
return parser.nodeSetTextContent(self, data);
|
||||
pub fn set_textContent(self: *parser.Node, data: []u8) !void {
|
||||
return try parser.nodeSetTextContent(self, data);
|
||||
}
|
||||
|
||||
// Methods
|
||||
@@ -153,12 +156,12 @@ pub const Node = struct {
|
||||
pub fn _appendChild(self: *parser.Node, child: *parser.Node) !Union {
|
||||
// TODO: DocumentFragment special case
|
||||
const res = try parser.nodeAppendChild(self, child);
|
||||
return Node.toInterface(res);
|
||||
return try Node.toInterface(res);
|
||||
}
|
||||
|
||||
pub fn _cloneNode(self: *parser.Node, deep: ?bool) Union {
|
||||
const clone = parser.nodeCloneNode(self, deep orelse false);
|
||||
return Node.toInterface(clone);
|
||||
pub fn _cloneNode(self: *parser.Node, deep: ?bool) !Union {
|
||||
const clone = try parser.nodeCloneNode(self, deep orelse false);
|
||||
return try Node.toInterface(clone);
|
||||
}
|
||||
|
||||
pub fn _compareDocumentPosition(self: *parser.Node, other: *parser.Node) void {
|
||||
@@ -168,8 +171,8 @@ pub const Node = struct {
|
||||
std.log.err("Not implemented {s}", .{"node.compareDocumentPosition()"});
|
||||
}
|
||||
|
||||
pub fn _contains(self: *parser.Node, other: *parser.Node) bool {
|
||||
return parser.nodeContains(self, other);
|
||||
pub fn _contains(self: *parser.Node, other: *parser.Node) !bool {
|
||||
return try parser.nodeContains(self, other);
|
||||
}
|
||||
|
||||
pub fn _getRootNode(self: *parser.Node) void {
|
||||
@@ -178,31 +181,31 @@ pub const Node = struct {
|
||||
std.log.err("Not implemented {s}", .{"node.getRootNode()"});
|
||||
}
|
||||
|
||||
pub fn _hasChildNodes(self: *parser.Node) bool {
|
||||
return parser.nodeHasChildNodes(self);
|
||||
pub fn _hasChildNodes(self: *parser.Node) !bool {
|
||||
return try parser.nodeHasChildNodes(self);
|
||||
}
|
||||
|
||||
pub fn _insertBefore(self: *parser.Node, new_node: *parser.Node, ref_node: *parser.Node) *parser.Node {
|
||||
return parser.nodeInsertBefore(self, new_node, ref_node);
|
||||
pub fn _insertBefore(self: *parser.Node, new_node: *parser.Node, ref_node: *parser.Node) !*parser.Node {
|
||||
return try parser.nodeInsertBefore(self, new_node, ref_node);
|
||||
}
|
||||
|
||||
pub fn _isDefaultNamespace(self: *parser.Node, namespace: []const u8) bool {
|
||||
pub fn _isDefaultNamespace(self: *parser.Node, namespace: []const u8) !bool {
|
||||
// TODO: namespace is not an optional parameter, but can be null.
|
||||
return parser.nodeIsDefaultNamespace(self, namespace);
|
||||
return try parser.nodeIsDefaultNamespace(self, namespace);
|
||||
}
|
||||
|
||||
pub fn _isEqualNode(self: *parser.Node, other: *parser.Node) bool {
|
||||
pub fn _isEqualNode(self: *parser.Node, other: *parser.Node) !bool {
|
||||
// TODO: other is not an optional parameter, but can be null.
|
||||
return parser.nodeIsEqualNode(self, other);
|
||||
return try parser.nodeIsEqualNode(self, other);
|
||||
}
|
||||
|
||||
pub fn _isSameNode(self: *parser.Node, other: *parser.Node) bool {
|
||||
pub fn _isSameNode(self: *parser.Node, other: *parser.Node) !bool {
|
||||
// TODO: other is not an optional parameter, but can be null.
|
||||
// NOTE: there is no need to use isSameNode(); instead use the === strict equality operator
|
||||
return parser.nodeIsSameNode(self, other);
|
||||
return try parser.nodeIsSameNode(self, other);
|
||||
}
|
||||
|
||||
pub fn _lookupPrefix(self: *parser.Node, namespace: ?[]const u8) ?[]const u8 {
|
||||
pub fn _lookupPrefix(self: *parser.Node, namespace: ?[]const u8) !?[]const u8 {
|
||||
// TODO: other is not an optional parameter, but can be null.
|
||||
if (namespace == null) {
|
||||
return null;
|
||||
@@ -210,26 +213,26 @@ pub const Node = struct {
|
||||
if (std.mem.eql(u8, namespace.?, "")) {
|
||||
return null;
|
||||
}
|
||||
return parser.nodeLookupPrefix(self, namespace.?);
|
||||
return try parser.nodeLookupPrefix(self, namespace.?);
|
||||
}
|
||||
|
||||
pub fn _lookupNamespaceURI(self: *parser.Node, prefix: ?[]const u8) ?[]const u8 {
|
||||
pub fn _lookupNamespaceURI(self: *parser.Node, prefix: ?[]const u8) !?[]const u8 {
|
||||
// TODO: other is not an optional parameter, but can be null.
|
||||
return parser.nodeLookupNamespaceURI(self, prefix);
|
||||
return try parser.nodeLookupNamespaceURI(self, prefix);
|
||||
}
|
||||
|
||||
pub fn _normalize(self: *parser.Node) void {
|
||||
return parser.nodeNormalize(self);
|
||||
pub fn _normalize(self: *parser.Node) !void {
|
||||
return try parser.nodeNormalize(self);
|
||||
}
|
||||
|
||||
pub fn _removeChild(self: *parser.Node, child: *parser.Node) Union {
|
||||
const res = parser.nodeRemoveChild(self, child);
|
||||
return Node.toInterface(res);
|
||||
pub fn _removeChild(self: *parser.Node, child: *parser.Node) !Union {
|
||||
const res = try parser.nodeRemoveChild(self, child);
|
||||
return try Node.toInterface(res);
|
||||
}
|
||||
|
||||
pub fn _replaceChild(self: *parser.Node, new_child: *parser.Node, old_child: *parser.Node) Union {
|
||||
const res = parser.nodeReplaceChild(self, new_child, old_child);
|
||||
return Node.toInterface(res);
|
||||
pub fn _replaceChild(self: *parser.Node, new_child: *parser.Node, old_child: *parser.Node) !Union {
|
||||
const res = try parser.nodeReplaceChild(self, new_child, old_child);
|
||||
return try Node.toInterface(res);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -18,15 +18,15 @@ pub const Text = struct {
|
||||
|
||||
// Read attributes
|
||||
|
||||
pub fn get_wholeText(self: *parser.Text) []const u8 {
|
||||
return parser.textWholdeText(self);
|
||||
pub fn get_wholeText(self: *parser.Text) ![]const u8 {
|
||||
return try parser.textWholdeText(self);
|
||||
}
|
||||
|
||||
// JS methods
|
||||
// ----------
|
||||
|
||||
pub fn _splitText(self: *parser.Text, offset: u32) *parser.Text {
|
||||
return parser.textSplitText(self, offset);
|
||||
pub fn _splitText(self: *parser.Text, offset: u32) !*parser.Text {
|
||||
return try parser.textSplitText(self, offset);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user