mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 15:13:28 +00:00
Merge pull request #865 from lightpanda-io/document_domain
Fix document.domain
This commit is contained in:
@@ -42,8 +42,12 @@ pub const HTMLDocument = struct {
|
||||
// JS funcs
|
||||
// --------
|
||||
|
||||
pub fn get_domain(self: *parser.DocumentHTML) ![]const u8 {
|
||||
return try parser.documentHTMLGetDomain(self);
|
||||
pub fn get_domain(self: *parser.DocumentHTML, page: *Page) ![]const u8 {
|
||||
// libdom's document_html get_domain always returns null, this is
|
||||
// the way MDN recommends getting the domain anyways, since document.domain
|
||||
// is deprecated.
|
||||
const location = try parser.documentHTMLGetLocation(Location, self) orelse return "";
|
||||
return location.get_host(page);
|
||||
}
|
||||
|
||||
pub fn set_domain(_: *parser.DocumentHTML, _: []const u8) ![]const u8 {
|
||||
@@ -307,7 +311,7 @@ test "Browser.HTML.Document" {
|
||||
}, .{});
|
||||
|
||||
try runner.testCases(&.{
|
||||
.{ "document.domain", "" },
|
||||
.{ "document.domain", "lightpanda.io" },
|
||||
.{ "document.referrer", "" },
|
||||
.{ "document.title", "" },
|
||||
.{ "document.body.localName", "body" },
|
||||
|
||||
@@ -2384,14 +2384,6 @@ pub inline fn documentHTMLSetBody(doc_html: *DocumentHTML, elt: ?*ElementHTML) !
|
||||
try DOMErr(err);
|
||||
}
|
||||
|
||||
pub inline fn documentHTMLGetDomain(doc: *DocumentHTML) ![]const u8 {
|
||||
var s: ?*String = undefined;
|
||||
const err = documentHTMLVtable(doc).get_domain.?(doc, &s);
|
||||
try DOMErr(err);
|
||||
if (s == null) return "";
|
||||
return strToData(s.?);
|
||||
}
|
||||
|
||||
pub inline fn documentHTMLGetReferrer(doc: *DocumentHTML) ![]const u8 {
|
||||
var s: ?*String = undefined;
|
||||
const err = documentHTMLVtable(doc).get_referrer.?(doc, &s);
|
||||
|
||||
Reference in New Issue
Block a user