Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ fn addDependencies(b: *Build, mod: *Build.Module, opts: *Build.Step.Options) !vo
try buildMbedtls(b, mod);
try buildNghttp2(b, mod);
try buildCurl(b, mod);
try buildAda(b, mod);

switch (target.result.os.tag) {
.macos => {
Expand Down Expand Up @@ -849,3 +850,34 @@ fn buildCurl(b: *Build, m: *Build.Module) !void {
},
});
}

pub fn buildAda(b: *Build, m: *Build.Module) !void {
const ada_dep = b.dependency("ada-singleheader", .{});

const ada_mod = b.createModule(.{
.root_source_file = b.path("vendor/ada/root.zig"),
});

const ada_lib = b.addLibrary(.{
.name = "ada",
.root_module = b.createModule(.{
.link_libcpp = true,
.target = m.resolved_target,
.optimize = m.optimize,
}),
.linkage = .static,
});

ada_lib.addCSourceFile(.{
.file = ada_dep.path("ada.cpp"),
.flags = &.{ "-std=c++20", "-O3" },
.language = .cpp,
});

ada_lib.installHeader(ada_dep.path("ada_c.h"), "ada_c.h");

// Link the library to ada module.
ada_mod.linkLibrary(ada_lib);
// Expose ada module to main module.
m.addImport("ada", ada_mod);
}
4 changes: 4 additions & 0 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@
.hash = "v8-0.0.0-xddH63bVAwBSEobaUok9J0er1FqsvEujCDDVy6ItqKQ5",
},
//.v8 = .{ .path = "../zig-v8-fork" }
.@"ada-singleheader" = .{
.url = "https://github.com/ada-url/ada/releases/download/v3.3.0/singleheader.zip",
.hash = "N-V-__8AAPmhFAAw64ALjlzd5YMtzpSrmZ6KymsT84BKfB4s",
},
},
}
6 changes: 3 additions & 3 deletions src/browser/ScriptManager.zig
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ pub fn addFromElement(self: *ScriptManager, element: *parser.Element, comptime c
if (try DataURI.parse(page.arena, src)) |data_uri| {
source = .{ .@"inline" = data_uri };
} else {
remote_url = try URL.stitch(page.arena, src, page.url.raw, .{ .null_terminated = true });
remote_url = try URL.stitch(page.arena, src, page.url.getHref(), .{ .null_terminated = true });
source = .{ .remote = .{} };
}
} else {
Expand All @@ -204,7 +204,7 @@ pub fn addFromElement(self: *ScriptManager, element: *parser.Element, comptime c
.kind = kind,
.element = element,
.source = source,
.url = remote_url orelse page.url.raw,
.url = remote_url orelse page.url.getHref(),
.is_defer = if (remote_url == null) false else try parser.elementGetAttribute(element, "defer") != null,
.is_async = if (remote_url == null) false else try parser.elementGetAttribute(element, "async") != null,
};
Expand Down Expand Up @@ -503,7 +503,7 @@ fn parseImportmap(self: *ScriptManager, script: *const Script) !void {
const resolved_url = try URL.stitch(
self.page.arena,
entry.value_ptr.*,
self.page.url.raw,
self.page.url.getHref(),
.{ .alloc = .if_needed, .null_terminated = true },
);

Expand Down
4 changes: 2 additions & 2 deletions src/browser/dom/node.zig
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ pub const Node = struct {
// --------

// Read-only attributes
pub fn get_baseURI(_: *parser.Node, page: *Page) ![]const u8 {
return page.url.raw;
pub fn get_baseURI(_: *parser.Node, page: *Page) []const u8 {
return page.url.getHref();
}

pub fn get_firstChild(self: *parser.Node) !?Union {
Expand Down
2 changes: 1 addition & 1 deletion src/browser/fetch/Request.zig
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pub fn constructor(input: RequestInput, _options: ?RequestInit, page: *Page) !Re

const url: [:0]const u8 = blk: switch (input) {
.string => |str| {
break :blk try URL.stitch(arena, str, page.url.raw, .{ .null_terminated = true });
break :blk try URL.stitch(arena, str, page.url.getHref(), .{ .null_terminated = true });
},
.request => |req| {
break :blk try arena.dupeZ(u8, req.url);
Expand Down
10 changes: 5 additions & 5 deletions src/browser/html/History.zig
Original file line number Diff line number Diff line change
Expand Up @@ -113,26 +113,26 @@ fn _dispatchPopStateEvent(state: ?[]const u8, page: *Page) !void {
);
}

pub fn _pushState(self: *History, state: js.Object, _: ?[]const u8, _url: ?[]const u8, page: *Page) !void {
pub fn _pushState(self: *History, state: js.Object, _: ?[]const u8, maybe_url: ?[]const u8, page: *Page) !void {
const arena = page.session.arena;

const json = try state.toJson(arena);
const url = if (_url) |u| try arena.dupe(u8, u) else try arena.dupe(u8, page.url.raw);
const url = if (maybe_url) |u| try arena.dupe(u8, u) else page.url.getHref();
const entry = HistoryEntry{ .state = json, .url = url };
try self.stack.append(arena, entry);
self.current = self.stack.items.len - 1;
}

pub fn _replaceState(self: *History, state: js.Object, _: ?[]const u8, _url: ?[]const u8, page: *Page) !void {
pub fn _replaceState(self: *History, state: js.Object, _: ?[]const u8, maybe_url: ?[]const u8, page: *Page) !void {
const arena = page.session.arena;

if (self.current) |curr| {
const entry = &self.stack.items[curr];
const json = try state.toJson(arena);
const url = if (_url) |u| try arena.dupe(u8, u) else try arena.dupe(u8, page.url.raw);
const url = if (maybe_url) |u| try arena.dupe(u8, u) else page.url.getHref();
entry.* = HistoryEntry{ .state = json, .url = url };
} else {
try self._pushState(state, "", _url, page);
try self._pushState(state, "", maybe_url, page);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/browser/html/document.zig
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ pub const HTMLDocument = struct {
// JS funcs
// --------

pub fn get_domain(self: *parser.DocumentHTML, page: *Page) ![]const u8 {
pub fn get_domain(self: *parser.DocumentHTML) ![]const u8 {
// libdom's document_html get_domain always returns null, this is
// the way MDN recommends getting the domain anyways, since document.domain
// is deprecated.
const location = try parser.documentHTMLGetLocation(Location, self) orelse return "";
return location.get_host(page);
return location.get_host();
}

pub fn set_domain(_: *parser.DocumentHTML, _: []const u8) ![]const u8 {
Expand Down Expand Up @@ -85,7 +85,7 @@ pub const HTMLDocument = struct {

pub fn get_cookie(_: *parser.DocumentHTML, page: *Page) ![]const u8 {
var buf: std.ArrayListUnmanaged(u8) = .{};
try page.cookie_jar.forRequest(&page.url.uri, buf.writer(page.arena), .{
try page.cookie_jar.forRequest(page.url, buf.writer(page.arena), .{
.is_http = false,
.is_navigation = true,
});
Expand All @@ -95,7 +95,7 @@ pub const HTMLDocument = struct {
pub fn set_cookie(_: *parser.DocumentHTML, cookie_str: []const u8, page: *Page) ![]const u8 {
// we use the cookie jar's allocator to parse the cookie because it
// outlives the page's arena.
const c = try Cookie.parse(page.cookie_jar.allocator, &page.url.uri, cookie_str);
const c = try Cookie.parse(page.cookie_jar.allocator, page.url, cookie_str);
errdefer c.deinit();
if (c.http_only) {
c.deinit();
Expand Down
Loading
Loading