mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 23:23:28 +00:00
dom: expose document.location
This commit is contained in:
@@ -391,7 +391,7 @@ pub const Page = struct {
|
|||||||
|
|
||||||
// TODO set the referrer to the document.
|
// TODO set the referrer to the document.
|
||||||
|
|
||||||
self.session.window.replaceDocument(html_doc);
|
try self.session.window.replaceDocument(html_doc);
|
||||||
self.session.window.setStorageShelf(
|
self.session.window.setStorageShelf(
|
||||||
try self.session.storageShed.getOrPut(self.origin orelse "null"),
|
try self.session.storageShed.getOrPut(self.origin orelse "null"),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ const Node = @import("../dom/node.zig").Node;
|
|||||||
const Document = @import("../dom/document.zig").Document;
|
const Document = @import("../dom/document.zig").Document;
|
||||||
const NodeList = @import("../dom/nodelist.zig").NodeList;
|
const NodeList = @import("../dom/nodelist.zig").NodeList;
|
||||||
const HTMLElem = @import("elements.zig");
|
const HTMLElem = @import("elements.zig");
|
||||||
|
const Location = @import("location.zig").Location;
|
||||||
|
|
||||||
const collection = @import("../dom/html_collection.zig");
|
const collection = @import("../dom/html_collection.zig");
|
||||||
const Walker = @import("../dom/walker.zig").WalkerDepthFirst;
|
const Walker = @import("../dom/walker.zig").WalkerDepthFirst;
|
||||||
@@ -157,6 +158,10 @@ pub const HTMLDocument = struct {
|
|||||||
return try parser.documentHTMLGetCurrentScript(self);
|
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 {
|
pub fn get_designMode(_: *parser.DocumentHTML) []const u8 {
|
||||||
return "off";
|
return "off";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -115,6 +115,7 @@ pub fn testExecFn(
|
|||||||
) anyerror!void {
|
) anyerror!void {
|
||||||
var location = [_]Case{
|
var location = [_]Case{
|
||||||
.{ .src = "location.href", .ex = "" },
|
.{ .src = "location.href", .ex = "" },
|
||||||
|
.{ .src = "document.location.href", .ex = "" },
|
||||||
};
|
};
|
||||||
try checkCases(js_env, &location);
|
try checkCases(js_env, &location);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
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;
|
self.document = doc;
|
||||||
|
try parser.documentHTMLSetLocation(Location, doc, &self.location);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setStorageShelf(self: *Window, shelf: *storage.Shelf) void {
|
pub fn setStorageShelf(self: *Window, shelf: *storage.Shelf) void {
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ fn execJS(
|
|||||||
|
|
||||||
// alias global as self and window
|
// alias global as self and window
|
||||||
var window = Window.create(null, null);
|
var window = Window.create(null, null);
|
||||||
window.replaceDocument(doc);
|
try window.replaceDocument(doc);
|
||||||
window.setStorageShelf(&storageShelf);
|
window.setStorageShelf(&storageShelf);
|
||||||
try js_env.bindGlobal(window);
|
try js_env.bindGlobal(window);
|
||||||
|
|
||||||
|
|||||||
@@ -2265,14 +2265,19 @@ pub fn documentHTMLGetCurrentScript(doc: *DocumentHTML) !?*Script {
|
|||||||
return @ptrCast(elem.?);
|
return @ptrCast(elem.?);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn documentHTMLSetLocation(doc: *DocumentHTML, location: ?*anyopaque) !void {
|
pub fn documentHTMLSetLocation(T: type, doc: *DocumentHTML, location: *T) !void {
|
||||||
const err = documentHTMLVtable(doc).set_location.?(doc, location);
|
const l = @as(*anyopaque, @ptrCast(location));
|
||||||
|
const err = documentHTMLVtable(doc).set_location.?(doc, l);
|
||||||
try DOMErr(err);
|
try DOMErr(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn documentHTMLGetLocation(doc: *DocumentHTML) !?*anyopaque {
|
pub fn documentHTMLGetLocation(T: type, doc: *DocumentHTML) !?*T {
|
||||||
var loc: ?*anyopaque = undefined;
|
var l: ?*anyopaque = undefined;
|
||||||
const err = documentHTMLVtable(doc).get_location.?(doc, &loc);
|
const err = documentHTMLVtable(doc).get_location.?(doc, &l);
|
||||||
try DOMErr(err);
|
try DOMErr(err);
|
||||||
return loc;
|
|
||||||
|
if (l == null) return null;
|
||||||
|
|
||||||
|
const ptr: *align(@alignOf(*T)) anyopaque = @alignCast(l.?);
|
||||||
|
return @as(*T, @ptrCast(ptr));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ fn testExecFn(
|
|||||||
// alias global as self and window
|
// alias global as self and window
|
||||||
var window = Window.create(null, null);
|
var window = Window.create(null, null);
|
||||||
|
|
||||||
window.replaceDocument(doc);
|
try window.replaceDocument(doc);
|
||||||
window.setStorageShelf(&storageShelf);
|
window.setStorageShelf(&storageShelf);
|
||||||
|
|
||||||
try js_env.bindGlobal(window);
|
try js_env.bindGlobal(window);
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ pub fn run(arena: *std.heap.ArenaAllocator, comptime dir: []const u8, f: []const
|
|||||||
|
|
||||||
// setup global env vars.
|
// setup global env vars.
|
||||||
var window = Window.create(null, null);
|
var window = Window.create(null, null);
|
||||||
window.replaceDocument(html_doc);
|
try window.replaceDocument(html_doc);
|
||||||
window.setStorageShelf(&storageShelf);
|
window.setStorageShelf(&storageShelf);
|
||||||
try js_env.bindGlobal(&window);
|
try js_env.bindGlobal(&window);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user