mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-28 14:43:28 +00:00
Compare commits
4 Commits
d4d35670a0
...
8d4cf400ce
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8d4cf400ce | ||
|
|
c6a0368c61 | ||
|
|
033eb82ae5 | ||
|
|
2d14452dda |
@@ -272,14 +272,12 @@ pub const HTMLAnchorElement = struct {
|
||||
return error.NotProvided;
|
||||
}
|
||||
|
||||
// TODO return a disposable string
|
||||
pub fn get_origin(self: *parser.Anchor, page: *Page) ![]const u8 {
|
||||
var u = try url(self, page);
|
||||
defer u.destructor();
|
||||
return u.get_origin(page);
|
||||
}
|
||||
|
||||
// TODO return a disposable string
|
||||
pub fn get_protocol(self: *parser.Anchor, page: *Page) ![]const u8 {
|
||||
var u = try url(self, page);
|
||||
defer u.destructor();
|
||||
@@ -296,7 +294,6 @@ pub const HTMLAnchorElement = struct {
|
||||
return parser.anchorSetHref(self, href);
|
||||
}
|
||||
|
||||
// TODO return a disposable string
|
||||
pub fn get_host(self: *parser.Anchor, page: *Page) ![]const u8 {
|
||||
var u = url(self, page) catch return "";
|
||||
defer u.destructor();
|
||||
@@ -328,7 +325,6 @@ pub const HTMLAnchorElement = struct {
|
||||
return parser.anchorSetHref(self, href);
|
||||
}
|
||||
|
||||
// TODO return a disposable string
|
||||
pub fn get_port(self: *parser.Anchor, page: *Page) ![]const u8 {
|
||||
var u = url(self, page) catch return "";
|
||||
defer u.destructor();
|
||||
@@ -349,7 +345,6 @@ pub const HTMLAnchorElement = struct {
|
||||
return parser.anchorSetHref(self, href);
|
||||
}
|
||||
|
||||
// TODO return a disposable string
|
||||
pub fn get_username(self: *parser.Anchor, page: *Page) ![]const u8 {
|
||||
var u = url(self, page) catch return "";
|
||||
defer u.destructor();
|
||||
@@ -373,7 +368,6 @@ pub const HTMLAnchorElement = struct {
|
||||
return parser.anchorSetHref(self, href);
|
||||
}
|
||||
|
||||
// TODO return a disposable string
|
||||
pub fn get_password(self: *parser.Anchor, page: *Page) ![]const u8 {
|
||||
var u = url(self, page) catch return "";
|
||||
defer u.destructor();
|
||||
@@ -392,7 +386,6 @@ pub const HTMLAnchorElement = struct {
|
||||
return parser.anchorSetHref(self, href);
|
||||
}
|
||||
|
||||
// TODO return a disposable string
|
||||
pub fn get_pathname(self: *parser.Anchor, page: *Page) ![]const u8 {
|
||||
var u = url(self, page) catch return "";
|
||||
defer u.destructor();
|
||||
@@ -426,7 +419,6 @@ pub const HTMLAnchorElement = struct {
|
||||
return parser.anchorSetHref(self, href);
|
||||
}
|
||||
|
||||
// TODO return a disposable string
|
||||
pub fn get_hash(self: *parser.Anchor, page: *Page) ![]const u8 {
|
||||
var u = url(self, page) catch return "";
|
||||
defer u.destructor();
|
||||
|
||||
@@ -281,10 +281,11 @@ pub const URL = struct {
|
||||
/// `Internal` error for failing cases.
|
||||
const SetterError = error{Internal};
|
||||
|
||||
// FIXME: reinit search_params?
|
||||
pub fn set_href(self: *const URL, input: []const u8) SetterError!void {
|
||||
pub fn set_href(self: *URL, input: []const u8, page: *Page) !void {
|
||||
_ = ada.setHref(self.internal, input);
|
||||
if (!ada.isValid(self.internal)) return error.Internal;
|
||||
// Can't call `get_search` here since it uses `search_params`.
|
||||
self.search_params = try prepareSearchParams(page.arena, self.internal);
|
||||
}
|
||||
|
||||
pub fn set_host(self: *const URL, input: []const u8) SetterError!void {
|
||||
|
||||
@@ -64,6 +64,23 @@
|
||||
testing.expectEqual(null, url.searchParams.get('a'));
|
||||
</script>
|
||||
|
||||
<script id=searchParamsSetHref>
|
||||
url = new URL("https://foo.bar");
|
||||
const searchParams = url.searchParams;
|
||||
|
||||
// SearchParams should be empty.
|
||||
testing.expectEqual(0, searchParams.size);
|
||||
|
||||
url.href = "https://lightpanda.io?over=9000&light=panda";
|
||||
// It won't hurt to check href and host too.
|
||||
testing.expectEqual("https://lightpanda.io/?over=9000&light=panda", url.href);
|
||||
testing.expectEqual("lightpanda.io", url.host);
|
||||
// SearchParams should be updated too when URL is set.
|
||||
testing.expectEqual(2, searchParams.size);
|
||||
testing.expectEqual("9000", searchParams.get("over"));
|
||||
testing.expectEqual("panda", searchParams.get("light"));
|
||||
</script>
|
||||
|
||||
<script id=base>
|
||||
url = new URL('over?9000', 'https://lightpanda.io');
|
||||
testing.expectEqual("https://lightpanda.io/over?9000", url.href);
|
||||
@@ -76,3 +93,9 @@
|
||||
testing.expectEqual("", sk.hostname);
|
||||
testing.expectEqual("sveltekit-internal://", sk.href);
|
||||
</script>
|
||||
|
||||
<script id=invalidUrl>
|
||||
testing.expectError("Error: Invalid", () => {
|
||||
_ = new URL("://foo.bar/path?query#fragment");
|
||||
});
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user