@@ -25,6 +25,7 @@ const Case = jsruntime.test_utils.Case;
2525const checkCases = jsruntime .test_utils .checkCases ;
2626
2727const Element = @import ("../dom/element.zig" ).Element ;
28+ const URL = @import ("../url/url.zig" ).URL ;
2829
2930// HTMLElement interfaces
3031pub const Interfaces = .{
@@ -188,6 +189,30 @@ pub const HTMLAnchorElement = struct {
188189 pub fn set_text (self : * parser.Anchor , v : []const u8 ) ! void {
189190 return try parser .nodeSetTextContent (parser .anchorToNode (self ), v );
190191 }
192+
193+ inline fn url (self : * parser.Anchor , alloc : std.mem.Allocator ) ! URL {
194+ const href = try parser .anchorGetHref (self );
195+ return URL .constructor (alloc , href , null ); // TODO inject base url
196+ }
197+
198+ // TODO return a disposable string
199+ pub fn get_host (self : * parser.Anchor , alloc : std.mem.Allocator ) ! []const u8 {
200+ var u = try url (self , alloc );
201+ defer u .deinit (alloc );
202+
203+ return try alloc .dupe (u8 , u .get_host ());
204+ }
205+
206+ pub fn set_host (self : * parser.Anchor , alloc : std.mem.Allocator , v : []const u8 ) ! void {
207+ var u = try url (self , alloc );
208+ defer u .deinit (alloc );
209+
210+ u .uri .host = v ;
211+ const href = try u .get_href (alloc );
212+ try parser .anchorSetHref (self , href );
213+ }
214+
215+ pub fn deinit (_ : * parser.Anchor , _ : std.mem.Allocator ) void {}
191216};
192217
193218pub const HTMLAppletElement = struct {
@@ -665,6 +690,11 @@ pub fn testExecFn(
665690 .{ .src = "a.href" , .ex = "foo" },
666691 .{ .src = "a.href = 'https://lightpanda.io/'" , .ex = "https://lightpanda.io/" },
667692 .{ .src = "a.href" , .ex = "https://lightpanda.io/" },
693+
694+ .{ .src = "a.host" , .ex = "lightpanda.io" },
695+ .{ .src = "a.host = 'foo.bar'" , .ex = "foo.bar" },
696+ .{ .src = "a.href" , .ex = "https://foo.bar/" },
697+
668698 .{ .src = "a.href = 'foo'" , .ex = "foo" },
669699
670700 .{ .src = "a.type" , .ex = "" },
0 commit comments