From 78e2f70cfb2629df71543b77382a0f2d495aceef Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Fri, 17 Nov 2023 16:40:20 +0100 Subject: [PATCH 01/10] dom: refacto HTMLCollection to extract matching --- src/dom/document.zig | 10 ++--- src/dom/html_collection.zig | 80 ++++++++++++++++++++++++++----------- 2 files changed, 60 insertions(+), 30 deletions(-) diff --git a/src/dom/document.zig b/src/dom/document.zig index b889169b..f869f8e5 100644 --- a/src/dom/document.zig +++ b/src/dom/document.zig @@ -7,7 +7,8 @@ const Case = jsruntime.test_utils.Case; const checkCases = jsruntime.test_utils.checkCases; const Node = @import("node.zig").Node; -const HTMLCollection = @import("html_collection.zig").HTMLCollection; + +const collection = @import("html_collection.zig"); const Element = @import("element.zig").Element; const ElementUnion = @import("element.zig").Union; @@ -49,12 +50,9 @@ pub const Document = struct { // the spec changed to return an HTMLCollection instead. // That's why we reimplemented getElementsByTagName by using an // HTMLCollection in zig here. - pub fn _getElementsByTagName(self: *parser.Document, tag_name: []const u8) HTMLCollection { + pub fn _getElementsByTagName(self: *parser.Document, allocator: std.mem.Allocator, tag_name: []const u8) !collection.HTMLCollection { const root = parser.documentGetDocumentElement(self); - return HTMLCollection{ - .root = parser.elementToNode(root), - .match = tag_name, - }; + return collection.HTMLCollectionByTagName(allocator, parser.elementToNode(root), tag_name); } }; diff --git a/src/dom/html_collection.zig b/src/dom/html_collection.zig index 10cfb78f..c9e02b22 100644 --- a/src/dom/html_collection.zig +++ b/src/dom/html_collection.zig @@ -5,11 +5,59 @@ const parser = @import("../netsurf.zig"); const jsruntime = @import("jsruntime"); const Case = jsruntime.test_utils.Case; const checkCases = jsruntime.test_utils.checkCases; +const generate = @import("../generate.zig"); const utils = @import("utils.z"); const Element = @import("element.zig").Element; const Union = @import("element.zig").Union; +const Match = union(enum) { + matchByTagName: MatchByTagName, + + pub fn match(self: Match, node: *parser.Node) bool { + switch (self) { + inline else => |case| return case.match(node), + } + } + + pub fn deinit(self: Match, allocator: std.mem.Allocator) void { + switch (self) { + inline else => |case| case.deinit(allocator), + } + } +}; + +pub const MatchByTagName = struct { + // tag is used to select node against their name. + // tag comparison is case insensitive. + tag: []const u8, + is_wildcard: bool, + + fn init(allocator: std.mem.Allocator, tag_name: []const u8) !MatchByTagName { + return MatchByTagName{ + .tag = try std.ascii.allocUpperString(allocator, tag_name), + .is_wildcard = std.mem.eql(u8, tag_name, "*"), + }; + } + + fn deinit(self: *MatchByTagName, allocator: std.mem.Allocator) void { + allocator.free(self.tag); + } + + pub fn match(self: MatchByTagName, node: *parser.Node) bool { + return self.is_wildcard or std.mem.eql(u8, self.tag, parser.nodeName(node)); + } +}; + +pub fn HTMLCollectionByTagName(allocator: std.mem.Allocator, root: *parser.Node, tag_name: []const u8) !HTMLCollection { + return HTMLCollection{ + .root = root, + .match = Match{ + .matchByTagName = try MatchByTagName.init(allocator, tag_name), + }, + }; +} + // WEB IDL https://dom.spec.whatwg.org/#htmlcollection // HTMLCollection is re implemented in zig here because libdom // dom_html_collection expects a comparison function callback as arguement. @@ -17,10 +65,9 @@ const Union = @import("element.zig").Union; pub const HTMLCollection = struct { pub const mem_guarantied = true; + match: Match, + root: *parser.Node, - // match is used to select node against their name. - // match comparison is case insensitive. - match: []const u8, // save a state for the collection to improve the _item speed. cur_idx: ?u32 = undefined, @@ -76,20 +123,15 @@ pub const HTMLCollection = struct { /// 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, allocator: std.mem.Allocator) !u32 { + pub fn get_length(self: *HTMLCollection) u32 { var len: u32 = 0; var node: *parser.Node = self.root; var ntype: parser.NodeType = undefined; - const imatch = try std.ascii.allocUpperString(allocator, self.match); - defer allocator.free(imatch); - - const is_wildcard = std.mem.eql(u8, self.match, "*"); - while (true) { ntype = parser.nodeType(node); if (ntype == .element) { - if (is_wildcard or std.mem.eql(u8, imatch, parser.nodeName(node))) { + if (self.match.match(node)) { len += 1; } } @@ -100,26 +142,21 @@ pub const HTMLCollection = struct { return len; } - pub fn _item(self: *HTMLCollection, allocator: std.mem.Allocator, 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; - const is_wildcard = std.mem.eql(u8, self.match, "*"); - // Use the current state to improve speed if possible. if (self.cur_idx != null and index >= self.cur_idx.?) { i = self.cur_idx.?; node = self.cur_node.?; } - const imatch = try std.ascii.allocUpperString(allocator, self.match); - defer allocator.free(imatch); - while (true) { ntype = parser.nodeType(node); if (ntype == .element) { - if (is_wildcard or std.mem.eql(u8, imatch, parser.nodeName(node))) { + if (self.match.match(node)) { // check if we found the searched element. if (i == index) { // save the current state @@ -140,7 +177,7 @@ pub const HTMLCollection = struct { return null; } - pub fn _namedItem(self: *HTMLCollection, allocator: std.mem.Allocator, name: []const u8) !?Union { + pub fn _namedItem(self: *HTMLCollection, name: []const u8) ?Union { if (name.len == 0) { return null; } @@ -148,15 +185,10 @@ pub const HTMLCollection = struct { var node: *parser.Node = self.root; var ntype: parser.NodeType = undefined; - const is_wildcard = std.mem.eql(u8, self.match, "*"); - - const imatch = try std.ascii.allocUpperString(allocator, self.match); - defer allocator.free(imatch); - while (true) { ntype = parser.nodeType(node); if (ntype == .element) { - if (is_wildcard or std.mem.eql(u8, imatch, parser.nodeName(node))) { + if (self.match.match(node)) { const elem = @as(*parser.Element, @ptrCast(node)); var attr = parser.elementGetAttribute(elem, "id"); From 9b94a4ec4947d7029e6f5d94e331c761067bfbe7 Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Fri, 17 Nov 2023 16:41:42 +0100 Subject: [PATCH 02/10] dom: deinit matcher with HTMLCollection --- src/dom/html_collection.zig | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/dom/html_collection.zig b/src/dom/html_collection.zig index c9e02b22..cbe309b0 100644 --- a/src/dom/html_collection.zig +++ b/src/dom/html_collection.zig @@ -73,6 +73,10 @@ pub const HTMLCollection = struct { cur_idx: ?u32 = undefined, cur_node: ?*parser.Node = undefined, + pub fn deinit(self: *HTMLCollection, allocator: std.mem.Allocator) void { + self.match.deinit(allocator); + } + // get_next iterates over the DOM tree to return the next following node or // null at the end. // From e9edb8bab49d5011a3ebc76a7cfd1e3da97833d4 Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Fri, 17 Nov 2023 17:11:39 +0100 Subject: [PATCH 03/10] dom: no need to allocate mem for case insensitive equality thanks to [std.ascii.eqlIgnoreCase](https://ziglang.org/documentation/master/std/#A;std:ascii.eqlIgnoreCase) --- src/dom/document.zig | 4 ++-- src/dom/html_collection.zig | 17 +++++++---------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/dom/document.zig b/src/dom/document.zig index f869f8e5..58845359 100644 --- a/src/dom/document.zig +++ b/src/dom/document.zig @@ -50,9 +50,9 @@ pub const Document = struct { // the spec changed to return an HTMLCollection instead. // That's why we reimplemented getElementsByTagName by using an // HTMLCollection in zig here. - pub fn _getElementsByTagName(self: *parser.Document, allocator: std.mem.Allocator, tag_name: []const u8) !collection.HTMLCollection { + pub fn _getElementsByTagName(self: *parser.Document, tag_name: []const u8) !collection.HTMLCollection { const root = parser.documentGetDocumentElement(self); - return collection.HTMLCollectionByTagName(allocator, parser.elementToNode(root), tag_name); + return collection.HTMLCollectionByTagName(parser.elementToNode(root), tag_name); } }; diff --git a/src/dom/html_collection.zig b/src/dom/html_collection.zig index cbe309b0..7b2e8605 100644 --- a/src/dom/html_collection.zig +++ b/src/dom/html_collection.zig @@ -21,8 +21,9 @@ const Match = union(enum) { } pub fn deinit(self: Match, allocator: std.mem.Allocator) void { + _ = allocator; switch (self) { - inline else => |case| case.deinit(allocator), + inline else => return, } } }; @@ -33,27 +34,23 @@ pub const MatchByTagName = struct { tag: []const u8, is_wildcard: bool, - fn init(allocator: std.mem.Allocator, tag_name: []const u8) !MatchByTagName { + fn init(tag_name: []const u8) !MatchByTagName { return MatchByTagName{ - .tag = try std.ascii.allocUpperString(allocator, tag_name), + .tag = tag_name, .is_wildcard = std.mem.eql(u8, tag_name, "*"), }; } - fn deinit(self: *MatchByTagName, allocator: std.mem.Allocator) void { - allocator.free(self.tag); - } - pub fn match(self: MatchByTagName, node: *parser.Node) bool { - return self.is_wildcard or std.mem.eql(u8, self.tag, parser.nodeName(node)); + return self.is_wildcard or std.ascii.eqlIgnoreCase(self.tag, parser.nodeName(node)); } }; -pub fn HTMLCollectionByTagName(allocator: std.mem.Allocator, root: *parser.Node, tag_name: []const u8) !HTMLCollection { +pub fn HTMLCollectionByTagName(root: *parser.Node, tag_name: []const u8) !HTMLCollection { return HTMLCollection{ .root = root, .match = Match{ - .matchByTagName = try MatchByTagName.init(allocator, tag_name), + .matchByTagName = try MatchByTagName.init(tag_name), }, }; } From dd282047970143244b08421d7cc49cb4f0b77d30 Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Fri, 17 Nov 2023 17:36:28 +0100 Subject: [PATCH 04/10] dom: implement getElementsByClassName --- src/dom/document.zig | 5 +++++ src/dom/html_collection.zig | 32 ++++++++++++++++++++++++++++++++ src/netsurf.zig | 11 +++++++++++ 3 files changed, 48 insertions(+) diff --git a/src/dom/document.zig b/src/dom/document.zig index 58845359..2524be9b 100644 --- a/src/dom/document.zig +++ b/src/dom/document.zig @@ -54,6 +54,11 @@ pub const Document = struct { const root = parser.documentGetDocumentElement(self); return collection.HTMLCollectionByTagName(parser.elementToNode(root), tag_name); } + + pub fn _getElementsByClassName(self: *parser.Document, classNames: []const u8) !collection.HTMLCollection { + const root = parser.documentGetDocumentElement(self); + return collection.HTMLCollectionByClassName(parser.elementToNode(root), classNames); + } }; // Tests diff --git a/src/dom/html_collection.zig b/src/dom/html_collection.zig index 7b2e8605..5e486807 100644 --- a/src/dom/html_collection.zig +++ b/src/dom/html_collection.zig @@ -13,6 +13,7 @@ const Union = @import("element.zig").Union; const Match = union(enum) { matchByTagName: MatchByTagName, + matchByClassName: MatchByClassName, pub fn match(self: Match, node: *parser.Node) bool { switch (self) { @@ -55,6 +56,37 @@ pub fn HTMLCollectionByTagName(root: *parser.Node, tag_name: []const u8) !HTMLCo }; } +pub const MatchByClassName = struct { + classNames: []const u8, + + fn init(classNames: []const u8) !MatchByClassName { + return MatchByClassName{ + .classNames = classNames, + }; + } + + 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)) { + return false; + } + } + + return true; + } +}; + +pub fn HTMLCollectionByClassName(root: *parser.Node, classNames: []const u8) !HTMLCollection { + return HTMLCollection{ + .root = root, + .match = Match{ + .matchByClassName = try MatchByClassName.init(classNames), + }, + }; +} + // WEB IDL https://dom.spec.whatwg.org/#htmlcollection // HTMLCollection is re implemented in zig here because libdom // dom_html_collection expects a comparison function callback as arguement. diff --git a/src/netsurf.zig b/src/netsurf.zig index 7052a0ac..c0f9bd5b 100644 --- a/src/netsurf.zig +++ b/src/netsurf.zig @@ -522,6 +522,11 @@ pub fn nodeReplaceChild(node: *Node, new_child: *Node, old_child: *Node) *Node { return res.?; } +// nodeToElement is an helper to convert a node to an element. +pub inline fn nodeToElement(node: *Node) *Element { + return @as(*Element, @ptrCast(node)); +} + // CharacterData pub const CharacterData = c.dom_characterdata; @@ -621,6 +626,12 @@ pub fn elementGetAttribute(elem: *Element, name: []const u8) ?[]const u8 { return stringToData(s.?); } +pub fn elementHasClass(elem: *Element, class: []const u8) bool { + var res: bool = undefined; + _ = elementVtable(elem).dom_element_has_class.?(elem, stringFromData(class), &res); + return res; +} + // elementToNode is an helper to convert an element to a node. pub inline fn elementToNode(e: *Element) *Node { return @as(*Node, @ptrCast(e)); From 9acf3fb20982449547c76bacbe570546aaae6748 Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Fri, 17 Nov 2023 17:37:02 +0100 Subject: [PATCH 05/10] dom: remove useless deinit from html_collection --- src/dom/html_collection.zig | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/dom/html_collection.zig b/src/dom/html_collection.zig index 5e486807..969830d9 100644 --- a/src/dom/html_collection.zig +++ b/src/dom/html_collection.zig @@ -20,13 +20,6 @@ const Match = union(enum) { inline else => |case| return case.match(node), } } - - pub fn deinit(self: Match, allocator: std.mem.Allocator) void { - _ = allocator; - switch (self) { - inline else => return, - } - } }; pub const MatchByTagName = struct { @@ -102,10 +95,6 @@ pub const HTMLCollection = struct { cur_idx: ?u32 = undefined, cur_node: ?*parser.Node = undefined, - pub fn deinit(self: *HTMLCollection, allocator: std.mem.Allocator) void { - self.match.deinit(allocator); - } - // get_next iterates over the DOM tree to return the next following node or // null at the end. // From 47e52b8217461546b2215fcfbda1ec9d9b307628 Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Sun, 19 Nov 2023 08:48:10 +0100 Subject: [PATCH 06/10] dom: implement lwc_string and unit tests for document.GetElementByClassName --- src/dom/document.zig | 10 ++++++++++ src/netsurf.zig | 14 +++++++++++++- test.html | 4 ++-- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/dom/document.zig b/src/dom/document.zig index 2524be9b..83f17893 100644 --- a/src/dom/document.zig +++ b/src/dom/document.zig @@ -96,6 +96,16 @@ pub fn testExecFn( }; try checkCases(js_env, &getElementsByTagName); + var getElementsByClassName = [_]Case{ + .{ .src = "let ok = document.getElementsByClassName('ok')", .ex = "undefined" }, + .{ .src = "ok.length", .ex = "2" }, + .{ .src = "let empty = document.getElementsByClassName('empty')", .ex = "undefined" }, + .{ .src = "empty.length", .ex = "1" }, + .{ .src = "let emptyok = document.getElementsByClassName('empty ok')", .ex = "undefined" }, + .{ .src = "emptyok.length", .ex = "1" }, + }; + try checkCases(js_env, &getElementsByClassName); + const tags = comptime parser.Tag.all(); comptime var createElements: [(tags.len) * 2]Case = undefined; inline for (tags, 0..) |tag, i| { diff --git a/src/netsurf.zig b/src/netsurf.zig index c0f9bd5b..c9af70a2 100644 --- a/src/netsurf.zig +++ b/src/netsurf.zig @@ -65,6 +65,18 @@ inline fn stringFromData(data: []const u8) *String { return s.?; } +const LWCString = c.lwc_string; + +// TODO implement lwcStringToData +// inline fn lwcStringToData(s: *LWCString) []const u8 { +// } + +inline fn lwcStringFromData(data: []const u8) *LWCString { + var s: ?*LWCString = undefined; + _ = c.lwc_intern_string(data.ptr, data.len, &s); + return s.?; +} + // Tag pub const Tag = enum(u8) { @@ -628,7 +640,7 @@ pub fn elementGetAttribute(elem: *Element, name: []const u8) ?[]const u8 { pub fn elementHasClass(elem: *Element, class: []const u8) bool { var res: bool = undefined; - _ = elementVtable(elem).dom_element_has_class.?(elem, stringFromData(class), &res); + _ = elementVtable(elem).dom_element_has_class.?(elem, lwcStringFromData(class), &res); return res; } diff --git a/test.html b/test.html index cb54107e..7a0d7b77 100644 --- a/test.html +++ b/test.html @@ -1,6 +1,6 @@
- OK -

+ OK +

And

From b06083e250bf242af26b5174d3d6f2a3e19ae097 Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Sun, 19 Nov 2023 09:00:15 +0100 Subject: [PATCH 07/10] wpt: add document.getElementsByClassName tests --- .../dom/Document-getElementsByClassName.html | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 tests/wpt/dom/Document-getElementsByClassName.html diff --git a/tests/wpt/dom/Document-getElementsByClassName.html b/tests/wpt/dom/Document-getElementsByClassName.html new file mode 100644 index 00000000..db8fac21 --- /dev/null +++ b/tests/wpt/dom/Document-getElementsByClassName.html @@ -0,0 +1,26 @@ + +Document.getElementsByClassName + + + +
+ From 1d5eb4773244d9698765fc4d538a8689d5a16044 Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Mon, 20 Nov 2023 14:44:55 +0100 Subject: [PATCH 08/10] dom: html_collection: remove useless error union --- src/dom/html_collection.zig | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/dom/html_collection.zig b/src/dom/html_collection.zig index 969830d9..601e0ad2 100644 --- a/src/dom/html_collection.zig +++ b/src/dom/html_collection.zig @@ -28,7 +28,7 @@ pub const MatchByTagName = struct { tag: []const u8, is_wildcard: bool, - fn init(tag_name: []const u8) !MatchByTagName { + fn init(tag_name: []const u8) MatchByTagName { return MatchByTagName{ .tag = tag_name, .is_wildcard = std.mem.eql(u8, tag_name, "*"), @@ -40,11 +40,11 @@ pub const MatchByTagName = struct { } }; -pub fn HTMLCollectionByTagName(root: *parser.Node, tag_name: []const u8) !HTMLCollection { +pub fn HTMLCollectionByTagName(root: *parser.Node, tag_name: []const u8) HTMLCollection { return HTMLCollection{ .root = root, .match = Match{ - .matchByTagName = try MatchByTagName.init(tag_name), + .matchByTagName = MatchByTagName.init(tag_name), }, }; } @@ -52,7 +52,7 @@ pub fn HTMLCollectionByTagName(root: *parser.Node, tag_name: []const u8) !HTMLCo pub const MatchByClassName = struct { classNames: []const u8, - fn init(classNames: []const u8) !MatchByClassName { + fn init(classNames: []const u8) MatchByClassName { return MatchByClassName{ .classNames = classNames, }; @@ -71,11 +71,11 @@ pub const MatchByClassName = struct { } }; -pub fn HTMLCollectionByClassName(root: *parser.Node, classNames: []const u8) !HTMLCollection { +pub fn HTMLCollectionByClassName(root: *parser.Node, classNames: []const u8) HTMLCollection { return HTMLCollection{ .root = root, .match = Match{ - .matchByClassName = try MatchByClassName.init(classNames), + .matchByClassName = MatchByClassName.init(classNames), }, }; } From 2ce6f36006762bd4180eb330a38fe6b34e05ea8f Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Mon, 20 Nov 2023 14:57:20 +0100 Subject: [PATCH 09/10] dom: html_collection: rename Match into Matcher --- src/dom/html_collection.zig | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/dom/html_collection.zig b/src/dom/html_collection.zig index 601e0ad2..de04cad4 100644 --- a/src/dom/html_collection.zig +++ b/src/dom/html_collection.zig @@ -11,11 +11,11 @@ const utils = @import("utils.z"); const Element = @import("element.zig").Element; const Union = @import("element.zig").Union; -const Match = union(enum) { +const Matcher = union(enum) { matchByTagName: MatchByTagName, matchByClassName: MatchByClassName, - pub fn match(self: Match, node: *parser.Node) bool { + pub fn match(self: Matcher, node: *parser.Node) bool { switch (self) { inline else => |case| return case.match(node), } @@ -43,7 +43,7 @@ pub const MatchByTagName = struct { pub fn HTMLCollectionByTagName(root: *parser.Node, tag_name: []const u8) HTMLCollection { return HTMLCollection{ .root = root, - .match = Match{ + .matcher = Matcher{ .matchByTagName = MatchByTagName.init(tag_name), }, }; @@ -74,7 +74,7 @@ pub const MatchByClassName = struct { pub fn HTMLCollectionByClassName(root: *parser.Node, classNames: []const u8) HTMLCollection { return HTMLCollection{ .root = root, - .match = Match{ + .matcher = Matcher{ .matchByClassName = MatchByClassName.init(classNames), }, }; @@ -87,7 +87,7 @@ pub fn HTMLCollectionByClassName(root: *parser.Node, classNames: []const u8) HTM pub const HTMLCollection = struct { pub const mem_guarantied = true; - match: Match, + matcher: Matcher, root: *parser.Node, @@ -153,7 +153,7 @@ pub const HTMLCollection = struct { while (true) { ntype = parser.nodeType(node); if (ntype == .element) { - if (self.match.match(node)) { + if (self.matcher.match(node)) { len += 1; } } @@ -178,7 +178,7 @@ pub const HTMLCollection = struct { while (true) { ntype = parser.nodeType(node); if (ntype == .element) { - if (self.match.match(node)) { + if (self.matcher.match(node)) { // check if we found the searched element. if (i == index) { // save the current state @@ -210,7 +210,7 @@ pub const HTMLCollection = struct { while (true) { ntype = parser.nodeType(node); if (ntype == .element) { - if (self.match.match(node)) { + if (self.matcher.match(node)) { const elem = @as(*parser.Element, @ptrCast(node)); var attr = parser.elementGetAttribute(elem, "id"); From 06ec9a16f510562b074e8c18e5bcf38fdcc84f22 Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Mon, 20 Nov 2023 16:34:13 +0100 Subject: [PATCH 10/10] dom: remove useless error union on document.getElementsBy* --- src/dom/document.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dom/document.zig b/src/dom/document.zig index 83f17893..b012eb37 100644 --- a/src/dom/document.zig +++ b/src/dom/document.zig @@ -50,12 +50,12 @@ pub const Document = struct { // the spec changed to return an HTMLCollection instead. // That's why we reimplemented getElementsByTagName by using an // HTMLCollection in zig here. - pub fn _getElementsByTagName(self: *parser.Document, tag_name: []const u8) !collection.HTMLCollection { + pub fn _getElementsByTagName(self: *parser.Document, tag_name: []const u8) collection.HTMLCollection { const root = parser.documentGetDocumentElement(self); return collection.HTMLCollectionByTagName(parser.elementToNode(root), tag_name); } - pub fn _getElementsByClassName(self: *parser.Document, classNames: []const u8) !collection.HTMLCollection { + pub fn _getElementsByClassName(self: *parser.Document, classNames: []const u8) collection.HTMLCollection { const root = parser.documentGetDocumentElement(self); return collection.HTMLCollectionByClassName(parser.elementToNode(root), classNames); }