dom: expose document.location

This commit is contained in:
Pierre Tachoire
2025-01-23 17:08:02 +01:00
parent 09ba4bcf43
commit 318e2bd1c6
8 changed files with 28 additions and 12 deletions

View File

@@ -28,6 +28,7 @@ const Node = @import("../dom/node.zig").Node;
const Document = @import("../dom/document.zig").Document;
const NodeList = @import("../dom/nodelist.zig").NodeList;
const HTMLElem = @import("elements.zig");
const Location = @import("location.zig").Location;
const collection = @import("../dom/html_collection.zig");
const Walker = @import("../dom/walker.zig").WalkerDepthFirst;
@@ -157,6 +158,10 @@ pub const HTMLDocument = struct {
return try parser.documentHTMLGetCurrentScript(self);
}
pub fn get_location(self: *parser.DocumentHTML) !?*Location {
return try parser.documentHTMLGetLocation(Location, self);
}
pub fn get_designMode(_: *parser.DocumentHTML) []const u8 {
return "off";
}

View File

@@ -115,6 +115,7 @@ pub fn testExecFn(
) anyerror!void {
var location = [_]Case{
.{ .src = "location.href", .ex = "" },
.{ .src = "document.location.href", .ex = "" },
};
try checkCases(js_env, &location);
}

View File

@@ -62,12 +62,17 @@ pub const Window = struct {
};
}
pub fn replaceLocation(self: *Window, loc: Location) void {
pub fn replaceLocation(self: *Window, loc: Location) !void {
self.location = loc;
if (self.doc != null) {
try parser.documentHTMLSetLocation(Location, self.doc.?, &self.location);
}
}
pub fn replaceDocument(self: *Window, doc: *parser.DocumentHTML) void {
pub fn replaceDocument(self: *Window, doc: *parser.DocumentHTML) !void {
self.document = doc;
try parser.documentHTMLSetLocation(Location, doc, &self.location);
}
pub fn setStorageShelf(self: *Window, shelf: *storage.Shelf) void {