Keep reference of current Page in Session

Signed-off-by: Francis Bouvier <francis@lightpanda.io>
This commit is contained in:
Francis Bouvier
2024-04-19 12:56:55 +02:00
committed by Pierre Tachoire
parent 4444d8a008
commit bcf4083f9c

View File

@@ -73,6 +73,7 @@ pub const Session = struct {
window: Window,
// TODO move the shed to the browser?
storageShed: storage.Shed,
page: ?*Page = null,
jstypes: [Types.len]usize = undefined,
@@ -95,6 +96,8 @@ pub const Session = struct {
}
fn deinit(self: *Session) void {
if (self.page) |page| page.end();
self.env.deinit();
self.arena.deinit();
@@ -130,10 +133,12 @@ pub const Page = struct {
alloc: std.mem.Allocator,
session: *Session,
) Page {
return Page{
var page = Page{
.arena = std.heap.ArenaAllocator.init(alloc),
.session = session,
};
session.page = &page;
return page;
}
// reset js env and mem arena.
@@ -149,6 +154,7 @@ pub const Page = struct {
pub fn deinit(self: *Page) void {
self.arena.deinit();
self.session.page = null;
}
// dump writes the page content into the given file.