Skip to content

Commit 344420f

Browse files
committed
bring back hostname getter/setter functions
This was a regression while testing things.
1 parent b87a59f commit 344420f

File tree

1 file changed

+27
-28
lines changed

1 file changed

+27
-28
lines changed

src/browser/html/elements.zig

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -355,34 +355,33 @@ pub const HTMLAnchorElement = struct {
355355
return parser.anchorSetHref(self, u.getHref());
356356
}
357357

358-
//pub fn get_hostname(self: *parser.Anchor, page: *Page) ![]const u8 {
359-
// const maybe_href_str = try getAnchorHref(self);
360-
// const href_str = maybe_href_str orelse return "";
361-
//
362-
// const u = try NativeURL.parse(href_str, null);
363-
// defer u.deinit();
364-
//
365-
// return page.arena.dupe(u8, u.getHostname());
366-
//}
367-
368-
//pub fn set_hostname(self: *parser.Anchor, v: []const u8) !void {
369-
// const maybe_href_str = try getAnchorHref(self);
370-
//
371-
// if (maybe_href_str) |href_str| {
372-
// const u = try NativeURL.parse(href_str, null);
373-
// defer u.deinit();
374-
//
375-
// try u.setHostname(v);
376-
//
377-
// return parser.anchorSetHref(self, u.getHref());
378-
// }
379-
//
380-
// // No href string there; use the given value as href.
381-
// const u = try NativeURL.parse(v, null);
382-
// defer u.deinit();
383-
//
384-
// return parser.anchorSetHref(self, u.getHref());
385-
//}
358+
pub fn get_hostname(self: *parser.Anchor, page: *Page) []const u8 {
359+
const u = getURL(self, page) catch return "";
360+
return u.getHostname();
361+
}
362+
363+
pub fn set_hostname(self: *parser.Anchor, hostname: []const u8, page: *Page) !void {
364+
const u = blk: {
365+
if (page.getObjectData(self)) |internal_url| {
366+
break :blk NativeURL.fromInternal(internal_url);
367+
}
368+
369+
const maybe_anchor_href = try getHref(self);
370+
if (maybe_anchor_href) |anchor_href| {
371+
const new_u = try NativeURL.parse(anchor_href, null);
372+
try page.putObjectData(self, new_u.internal.?);
373+
break :blk new_u;
374+
}
375+
376+
// Last resort; try to create URL object out of hostname.
377+
const new_u = try NativeURL.parse(hostname, null);
378+
// We can just return here since hostname is updated.
379+
return page.putObjectData(self, new_u.internal.?);
380+
};
381+
382+
try u.setHostname(hostname);
383+
return parser.anchorSetHref(self, u.getHref());
384+
}
386385

387386
// TODO return a disposable string
388387
pub fn get_port(self: *parser.Anchor, page: *Page) ![]const u8 {

0 commit comments

Comments
 (0)