Skip to content

Lightpanda: the headless browser designed for AI and automation

`URL`: reintroduce `parse` static method

Halil Durake223827789b9
diff --git a/src/browser/webapi/URL.zig b/src/browser/webapi/URL.zig
index bde373ebf..6872c8248 100644
--- a/src/browser/webapi/URL.zig
+++ b/src/browser/webapi/URL.zig
@@ -53,6 +53,11 @@ pub fn init(url: []const u8, maybe_base: ?[]const u8, exec: *const Execution) !*
return exec._factory.create(URL{ ._url = u });
}
+/// Like the constructor, but returns null instead of throwing when parsing fails.
+pub fn parse(url: []const u8, maybe_base: ?[]const u8, exec: *const Execution) ?*URL {
+ return URL.init(url, maybe_base, exec) catch null;
+}
+
pub fn deinit(self: *URL, _: *Page) void {
// Not tracked by arena.
U.url_free(self._url);
@@ -298,14 +303,6 @@ pub fn toString(self: *const URL, exec: *const Execution) ![]const u8 {
return out[0..len];
}
-/// Like the constructor, but returns null instead of throwing when parsing fails.
-pub fn parse(url: []const u8, maybe_base: ?[]const u8, exec: *const Execution) !?*URL {
- return URL.init(url, maybe_base, exec) catch |err| switch (err) {
- error.TypeError => null,
- else => err,
- };
-}
-
pub fn canParse(url: []const u8, maybe_base: ?[]const u8) bool {
if (maybe_base) |base| {
return U.url_can_parse_with_base(base.ptr, base.len, url.ptr, url.len);