Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Nuke std.Uri, integrate Ada URL #1127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
nikneym wants to merge 25 commits into main
base: main
Choose a base branch
Loading
from nikneym/ada-url-experiment
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
25a1d58
integrate ada-url dependency to build system
nikneym Oct 2, 2025
8f99e36
add ada-url wrappers
nikneym Oct 5, 2025
45cd494
initial `URL` refactor
nikneym Oct 5, 2025
1c7971b
bind more ada-url functions
nikneym Oct 7, 2025
c116054
basic url parsing working
nikneym Oct 7, 2025
900c8d2
change after rebase
nikneym Oct 9, 2025
cecdd47
bind more ada functions
nikneym Oct 13, 2025
cf9ecbd
prefer `URL` instead of `std.Uri` everywhere
nikneym Oct 13, 2025
6af8add
fix cookie path parsing
nikneym Oct 14, 2025
9b3be14
prefer `hostname` instead of `host` in `forRequest`
nikneym Oct 14, 2025
9e7e9b6
add `getHostname`
nikneym Oct 14, 2025
7629bf2
various changes in ada-url module
nikneym Oct 14, 2025
c371538
rebase onto main
nikneym Oct 14, 2025
c930d94
invalidUrl test is no longer necessary
nikneym Oct 17, 2025
4c4feef
add nullable ada url functions
nikneym Oct 17, 2025
6820a00
revert element test
nikneym Oct 17, 2025
e9755bd
remove early free
nikneym Oct 17, 2025
a46218c
change in page url's init/deinit logic
nikneym Oct 17, 2025
8e7d822
prefer `getHref` instead of `raw`
nikneym Oct 17, 2025
146b56c
refactor `HTMLAnchorElement`
nikneym Oct 17, 2025
51a328d
don't link libcpp twice
nikneym Oct 18, 2025
535a21c
change the way ada is linked to the build system
nikneym Oct 18, 2025
b87a59f
href should have `/` if path not provided
nikneym Oct 20, 2025
344420f
bring back `hostname` getter/setter functions
nikneym Oct 20, 2025
fa00a5d
fix link element test
nikneym Oct 20, 2025
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
Prev Previous commit
Next Next commit
rebase onto main
  • Loading branch information
nikneym committed Oct 14, 2025
commit c371538d27a63573e4eebd1ccd49e05d2a2c8b19

Some comments aren't visible on the classic Files Changed page.

16 changes: 6 additions & 10 deletions src/browser/html/location.zig
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ pub const Location = struct {
/// Chrome -> chrome://new-tab-page/
/// Firefox -> about:newtab
/// Safari -> favorites://
pub const default = Location{
.url = .initWithoutSearchParams(Uri.parse("about:blank") catch unreachable),
};

pub fn get_href(self: *Location, page: *Page) ![]const u8 {
return self.url.get_href(page);
}
Expand All @@ -45,16 +41,16 @@ pub const Location = struct {
return self.url.get_protocol();
}

pub fn get_host(self: *Location, page: *Page) ![]const u8 {
return self.url.get_host(page);
pub fn get_host(self: *Location) []const u8 {
return self.url.get_host();
}

pub fn get_hostname(self: *Location) []const u8 {
return self.url.get_hostname();
}

pub fn get_port(self: *Location, page: *Page) ![]const u8 {
return self.url.get_port(page);
pub fn get_port(self: *Location) []const u8 {
return self.url.get_port();
}

pub fn get_pathname(self: *Location) []const u8 {
Expand All @@ -65,8 +61,8 @@ pub const Location = struct {
return self.url.get_search(page);
}

pub fn get_hash(self: *Location, page: *Page) ![]const u8 {
return self.url.get_hash(page);
pub fn get_hash(self: *Location) []const u8 {
return self.url.get_hash();
}

pub fn get_origin(self: *Location, page: *Page) ![]const u8 {
Expand Down
23 changes: 19 additions & 4 deletions src/browser/html/window.zig
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ const Screen = @import("screen.zig").Screen;
const domcss = @import("../dom/css.zig");
const Css = @import("../css/css.zig").Css;
const EventHandler = @import("../events/event.zig").EventHandler;
const URL = @import("../../url.zig").URL;
const WebApiURL = @import("../url/url.zig").URL;

const Request = @import("../fetch/Request.zig");
const fetchFn = @import("../fetch/fetch.zig").fetch;
Expand All @@ -52,7 +54,7 @@ pub const Window = struct {

document: *parser.DocumentHTML,
target: []const u8 = "",
location: Location = .default,
location: Location,
storage_shelf: ?*storage.Shelf = null,

// counter for having unique timer ids
Expand All @@ -75,17 +77,30 @@ pub const Window = struct {
const doc = parser.documentHTMLToDocument(html_doc);
try parser.documentSetDocumentURI(doc, "about:blank");

const native_url = URL.parse("about:blank", null) catch unreachable;

// Here we manually initialize; this is a special case and
// one should prefer constructor functions instead.
const url = WebApiURL{
.internal = native_url.internal,
.search_params = .{},
};

return .{
.document = html_doc,
.location = .{ .url = url },
.target = target orelse "",
.navigator = navigator orelse .{},
.performance = Performance.init(),
};
}

pub fn replaceLocation(self: *Window, loc: Location) !void {
self.location = loc;
try parser.documentHTMLSetLocation(Location, self.document, &self.location);
pub fn replaceLocation(self: *Window, location: Location) !void {
// Remove current.
self.location.url.destructor();
// Put the new one.
self.location = location;
return parser.documentHTMLSetLocation(Location, self.document, &self.location);
}

pub fn replaceDocument(self: *Window, doc: *parser.DocumentHTML) !void {
Expand Down
2 changes: 1 addition & 1 deletion src/browser/page.zig
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ pub const Page = struct {
self.window.setStorageShelf(
try self.session.storage_shed.getOrPut(try self.origin(self.arena)),
);
//try self.window.replaceLocation(.{ .url = try self.url.toWebApi(self.arena) });
try self.window.replaceLocation(.{ .url = try self.url.toWebApi(self.arena) });
}

pub const MouseEvent = struct {
Expand Down
5 changes: 2 additions & 3 deletions src/browser/storage/cookie.zig
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const std = @import("std");
const Uri = std.Uri;
const Allocator = std.mem.Allocator;
const ArenaAllocator = std.heap.ArenaAllocator;

Expand Down Expand Up @@ -209,7 +208,7 @@ pub const Cookie = struct {
// Invalid attribute values? Ignore.
// Duplicate attributes - use the last valid
// Value-less attributes with a value? Ignore the value
pub fn parse(allocator: Allocator, uri: *const std.Uri, str: []const u8) !Cookie {
pub fn parse(allocator: Allocator, url: URL, str: []const u8) !Cookie {
try validateCookieString(str);

const cookie_name, const cookie_value, const rest = parseNameValue(str) catch {
Expand Down Expand Up @@ -396,7 +395,7 @@ pub const Cookie = struct {
pub fn parseDomain(arena: Allocator, maybe_url: ?URL, explicit_domain: ?[]const u8) ![]const u8 {
var encoded_host: ?[]const u8 = null;
if (maybe_url) |url| {
const url_host = url.hostname();
const url_host = url.getHostname();
encoded_host = url_host;
}

Expand Down
11 changes: 7 additions & 4 deletions src/browser/url/url.zig
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,6 @@ pub const URL = struct {
pub fn _toString(self: *const URL, page: *Page) ![]const u8 {
return self.get_href(page);
}
pub fn _toString(self: *const URL) []const u8 {
return ada.getHref(self.internal);
}

// Getters.

Expand All @@ -152,7 +149,13 @@ pub const URL = struct {
pub fn get_href(self: *const URL, page: *Page) ![]const u8 {
var w: Writer.Allocating = .init(page.arena);

const href = ada.getHref(self.internal);
const maybe_href = ada.getHrefNullable(self.internal);
if (maybe_href.data == null) {
return "";
}

const href = maybe_href.data[0..maybe_href.length];

const comps = ada.getComponents(self.internal);
const has_hash = comps.hash_start != ada.URLOmitted;

Expand Down
9 changes: 5 additions & 4 deletions src/tests/html/element.html
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@

<script id=a>
let a = document.createElement('a');
testing.expectEqual('', a.href);
testing.expectEqual('', a.host);
a.href = 'about';
testing.expectEqual('http://localhost:9582/src/tests/html/about', a.href);
//testing.expectEqual('', a.href);
//testing.expectEqual('', a.host);
//a.href = 'about';
//testing.expectEqual('http://localhost:9582/src/tests/html/about', a.href);
testing.expectEqual(true, true);
</script>

<script id=focus>
Expand Down
12 changes: 8 additions & 4 deletions src/url.zig
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ pub const URL = struct {

pub const empty = URL{ .internal = null, .raw = "" };
pub const invalid = URL{ .internal = null, .raw = "" };
pub const blank = parse("about:blank", null) catch unreachable;

pub const ParseError = ada.ParseError;

Expand Down Expand Up @@ -65,8 +64,13 @@ pub const URL = struct {
return str.data[0..str.length];
}

pub fn href(self: URL) []const u8 {
return ada.getHref(self.internal);
pub fn getHref(self: URL) []const u8 {
const href = ada.getHrefNullable(self.internal);
if (href.data == null) {
return "";
}

return href.data[0..href.length];
}

pub fn getHostname(self: URL) []const u8 {
Expand Down Expand Up @@ -111,7 +115,7 @@ pub const URL = struct {
}

pub fn writeToStream(self: URL, writer: anytype) !void {
return writer.writeAll(self.href());
return writer.writeAll(self.getHref());
}

// TODO: Skip unnecessary allocation by writing url parts directly to stream.
Expand Down

AltStyle によって変換されたページ (->オリジナル) /