Skip to content

Commit 8c2c1e5

Browse files
authored
Merge pull request #865 from lightpanda-io/document_domain
Fix document.domain
2 parents bfc01d9 + 34b3c39 commit 8c2c1e5

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
@@ -2384,14 +2384,6 @@ pub inline fn documentHTMLSetBody(doc_html: *DocumentHTML, elt: ?*ElementHTML) !
23842384
try DOMErr(err);
23852385
}
23862386

2387-
pub inline fn documentHTMLGetDomain(doc: *DocumentHTML) ![]const u8 {
2388-
var s: ?*String = undefined;
2389-
const err = documentHTMLVtable(doc).get_domain.?(doc, &s);
2390-
try DOMErr(err);
2391-
if (s == null) return "";
2392-
return strToData(s.?);
2393-
}
2394-
23952387
pub inline fn documentHTMLGetReferrer(doc: *DocumentHTML) ![]const u8 {
23962388
var s: ?*String = undefined;
23972389
const err = documentHTMLVtable(doc).get_referrer.?(doc, &s);

0 commit comments

Comments
 (0)