@@ -25,13 +25,14 @@ const URL = @import("../url/url.zig").URL;
2525pub const Location = struct {
2626 url : URL ,
2727
28+ /// Initializes the `Location` to be used in `Window`.
2829 /// Browsers give such initial values when user not navigated yet:
2930 /// Chrome -> chrome://new-tab-page/
3031 /// Firefox -> about:newtab
3132 /// Safari -> favorites://
32- pub const default = Location {
33- . url = . initWithoutSearchParams ( Uri . parse ( "about:blank" ) catch unreachable ),
34- };
33+ pub fn init ( url : [] const u8 ) ! Location {
34+ return .{ . url = try . initForLocation ( url ) };
35+ }
3536
3637 pub fn get_href (self : * Location , page : * Page ) ! []const u8 {
3738 return self .url .get_href (page );
@@ -45,16 +46,16 @@ pub const Location = struct {
4546 return self .url .get_protocol ();
4647 }
4748
48- pub fn get_host (self : * Location , page : * Page ) ! []const u8 {
49- return self .url .get_host (page );
49+ pub fn get_host (self : * Location ) []const u8 {
50+ return self .url .get_host ();
5051 }
5152
5253 pub fn get_hostname (self : * Location ) []const u8 {
5354 return self .url .get_hostname ();
5455 }
5556
56- pub fn get_port (self : * Location , page : * Page ) ! []const u8 {
57- return self .url .get_port (page );
57+ pub fn get_port (self : * Location ) []const u8 {
58+ return self .url .get_port ();
5859 }
5960
6061 pub fn get_pathname (self : * Location ) []const u8 {
@@ -65,8 +66,8 @@ pub const Location = struct {
6566 return self .url .get_search (page );
6667 }
6768
68- pub fn get_hash (self : * Location , page : * Page ) ! []const u8 {
69- return self .url .get_hash (page );
69+ pub fn get_hash (self : * Location ) []const u8 {
70+ return self .url .get_hash ();
7071 }
7172
7273 pub fn get_origin (self : * Location , page : * Page ) ! []const u8 {
@@ -86,7 +87,7 @@ pub const Location = struct {
8687 }
8788
8889 pub fn _toString (self : * Location , page : * Page ) ! []const u8 {
89- return try self .get_href (page );
90+ return self .get_href (page );
9091 }
9192};
9293
0 commit comments