Skip to content

Commit 024f7ad

Browse files
authored
Merge pull request #1056 from lightpanda-io/DOM_NO_ERR
Convert more DOM_NO_ERR cases to assertions
2 parents f8425fe + 58acb2b commit 024f7ad

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+380
-446
lines changed

src/browser/Scheduler.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
// along with this program. If not, see <https://www.gnu.org/licenses/>.
1818

1919
const std = @import("std");
20-
const log = @import("../log.zig");
2120
const Allocator = std.mem.Allocator;
2221

2322
const Scheduler = @This();

src/browser/ScriptManager.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ pub fn addFromElement(self: *ScriptManager, element: *parser.Element) !void {
161161
remote_url = try URL.stitch(page.arena, src, page.url.raw, .{ .null_terminated = true });
162162
source = .{ .remote = .{} };
163163
} else {
164-
const inline_source = try parser.nodeTextContent(@ptrCast(element)) orelse return;
164+
const inline_source = parser.nodeTextContent(@ptrCast(element)) orelse return;
165165
source = .{ .@"inline" = inline_source };
166166
}
167167

src/browser/State.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ const parser = @import("netsurf.zig");
3131
const DataSet = @import("html/DataSet.zig");
3232
const ShadowRoot = @import("dom/shadow_root.zig").ShadowRoot;
3333
const StyleSheet = @import("cssom/StyleSheet.zig");
34-
const CSSStyleSheet = @import("cssom/CSSStyleSheet.zig");
3534
const CSSStyleDeclaration = @import("cssom/CSSStyleDeclaration.zig");
3635

3736
// for HTMLScript (but probably needs to be added to more)

src/browser/console/console.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ const std = @import("std");
2020
const builtin = @import("builtin");
2121
const log = @import("../../log.zig");
2222

23-
const Allocator = std.mem.Allocator;
2423
const Page = @import("../page.zig").Page;
2524
const JsObject = @import("../env.zig").Env.JsObject;
2625

src/browser/css/css.zig

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,31 +46,27 @@ pub fn parse(alloc: std.mem.Allocator, s: []const u8, opts: parser.ParseOptions)
4646
// matchFirst call m.match with the first node that matches the selector s, from the
4747
// descendants of n and returns true. If none matches, it returns false.
4848
pub fn matchFirst(s: *const Selector, node: anytype, m: anytype) !bool {
49-
var c = try node.firstChild();
50-
while (true) {
51-
if (c == null) break;
52-
53-
if (try s.match(c.?)) {
54-
try m.match(c.?);
49+
var child = node.firstChild();
50+
while (child) |c| {
51+
if (try s.match(c)) {
52+
try m.match(c);
5553
return true;
5654
}
5755

58-
if (try matchFirst(s, c.?, m)) return true;
59-
c = try c.?.nextSibling();
56+
if (try matchFirst(s, c, m)) return true;
57+
child = c.nextSibling();
6058
}
6159
return false;
6260
}
6361

6462
// matchAll call m.match with the all the nodes that matches the selector s, from the
6563
// descendants of n.
6664
pub fn matchAll(s: *const Selector, node: anytype, m: anytype) !void {
67-
var c = try node.firstChild();
68-
while (true) {
69-
if (c == null) break;
70-
71-
if (try s.match(c.?)) try m.match(c.?);
72-
try matchAll(s, c.?, m);
73-
c = try c.?.nextSibling();
65+
var child = node.firstChild();
66+
while (child) |c| {
67+
if (try s.match(c)) try m.match(c);
68+
try matchAll(s, c, m);
69+
child = c.nextSibling();
7470
}
7571
}
7672

src/browser/css/libdom.zig

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,79 +26,75 @@ const Allocator = std.mem.Allocator;
2626
pub const Node = struct {
2727
node: *parser.Node,
2828

29-
pub fn firstChild(n: Node) !?Node {
30-
const c = try parser.nodeFirstChild(n.node);
29+
pub fn firstChild(n: Node) ?Node {
30+
const c = parser.nodeFirstChild(n.node);
3131
if (c) |cc| return .{ .node = cc };
3232

3333
return null;
3434
}
3535

36-
pub fn lastChild(n: Node) !?Node {
37-
const c = try parser.nodeLastChild(n.node);
36+
pub fn lastChild(n: Node) ?Node {
37+
const c = parser.nodeLastChild(n.node);
3838
if (c) |cc| return .{ .node = cc };
3939

4040
return null;
4141
}
4242

43-
pub fn nextSibling(n: Node) !?Node {
44-
const c = try parser.nodeNextSibling(n.node);
43+
pub fn nextSibling(n: Node) ?Node {
44+
const c = parser.nodeNextSibling(n.node);
4545
if (c) |cc| return .{ .node = cc };
4646

4747
return null;
4848
}
4949

50-
pub fn prevSibling(n: Node) !?Node {
51-
const c = try parser.nodePreviousSibling(n.node);
50+
pub fn prevSibling(n: Node) ?Node {
51+
const c = parser.nodePreviousSibling(n.node);
5252
if (c) |cc| return .{ .node = cc };
5353

5454
return null;
5555
}
5656

57-
pub fn parent(n: Node) !?Node {
58-
const c = try parser.nodeParentNode(n.node);
57+
pub fn parent(n: Node) ?Node {
58+
const c = parser.nodeParentNode(n.node);
5959
if (c) |cc| return .{ .node = cc };
6060

6161
return null;
6262
}
6363

6464
pub fn isElement(n: Node) bool {
65-
const t = parser.nodeType(n.node) catch return false;
66-
return t == .element;
65+
return parser.nodeType(n.node) == .element;
6766
}
6867

6968
pub fn isDocument(n: Node) bool {
70-
const t = parser.nodeType(n.node) catch return false;
71-
return t == .document;
69+
return parser.nodeType(n.node) == .document;
7270
}
7371

7472
pub fn isComment(n: Node) bool {
75-
const t = parser.nodeType(n.node) catch return false;
76-
return t == .comment;
73+
return parser.nodeType(n.node) == .comment;
7774
}
7875

7976
pub fn isText(n: Node) bool {
80-
const t = parser.nodeType(n.node) catch return false;
81-
return t == .text;
77+
return parser.nodeType(n.node) == .text;
8278
}
8379

84-
pub fn text(n: Node) !?[]const u8 {
85-
const data = try parser.nodeTextContent(n.node);
80+
pub fn text(n: Node) ?[]const u8 {
81+
const data = parser.nodeTextContent(n.node);
8682
if (data == null) return null;
8783
if (data.?.len == 0) return null;
8884

8985
return std.mem.trim(u8, data.?, &std.ascii.whitespace);
9086
}
9187

92-
pub fn isEmptyText(n: Node) !bool {
93-
const data = try parser.nodeTextContent(n.node);
88+
pub fn isEmptyText(n: Node) bool {
89+
const data = parser.nodeTextContent(n.node);
9490
if (data == null) return true;
9591
if (data.?.len == 0) return true;
9692

9793
return std.mem.trim(u8, data.?, &std.ascii.whitespace).len == 0;
9894
}
9995

10096
pub fn tag(n: Node) ![]const u8 {
101-
return try parser.nodeName(n.node);
97+
return parser.nodeName(n.node);
10298
}
10399

104100
pub fn attr(n: Node, key: []const u8) !?[]const u8 {

0 commit comments

Comments
 (0)