Skip to content

Commit 34b3c39

Browse files
committed
Fix document.domain
Currently seems to always return null. Doesn't seem to be a way in libdom to change this. The property is deprecated, and MDN recommends using location.host instead, so change document.get_domain to wrap location.host.
1 parent bdc49a6 commit 34b3c39

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

src/browser/html/document.zig

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,12 @@ pub const HTMLDocument = struct {
4242
// JS funcs
4343
// --------
4444

45-
pub fn get_domain(self: *parser.DocumentHTML) ![]const u8 {
46-
return try parser.documentHTMLGetDomain(self);
45+
pub fn get_domain(self: *parser.DocumentHTML, page: *Page) ![]const u8 {
46+
// libdom's document_html get_domain always returns null, this is
47+
// the way MDN recommends getting the domain anyways, since document.domain
48+
// is deprecated.
49+
const location = try parser.documentHTMLGetLocation(Location, self) orelse return "";
50+
return location.get_host(page);
4751
}
4852

4953
pub fn set_domain(_: *parser.DocumentHTML, _: []const u8) ![]const u8 {
@@ -307,7 +311,7 @@ test "Browser.HTML.Document" {
307311
}, .{});
308312

309313
try runner.testCases(&.{
310-
.{ "document.domain", "" },
314+
.{ "document.domain", "lightpanda.io" },
311315
.{ "document.referrer", "" },
312316
.{ "document.title", "" },
313317
.{ "document.body.localName", "body" },

src/browser/netsurf.zig

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2369,14 +2369,6 @@ pub inline fn documentHTMLSetBody(doc_html: *DocumentHTML, elt: ?*ElementHTML) !
23692369
try DOMErr(err);
23702370
}
23712371

2372-
pub inline fn documentHTMLGetDomain(doc: *DocumentHTML) ![]const u8 {
2373-
var s: ?*String = undefined;
2374-
const err = documentHTMLVtable(doc).get_domain.?(doc, &s);
2375-
try DOMErr(err);
2376-
if (s == null) return "";
2377-
return strToData(s.?);
2378-
}
2379-
23802372
pub inline fn documentHTMLGetReferrer(doc: *DocumentHTML) ![]const u8 {
23812373
var s: ?*String = undefined;
23822374
const err = documentHTMLVtable(doc).get_referrer.?(doc, &s);

0 commit comments

Comments
 (0)