Skip to content

Commit bcf4083

Browse files
francisbouvierkrichprollsch
authored andcommitted
Keep reference of current Page in Session
Signed-off-by: Francis Bouvier <francis@lightpanda.io>
1 parent 4444d8a commit bcf4083

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/browser/browser.zig

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ pub const Session = struct {
7373
window: Window,
7474
// TODO move the shed to the browser?
7575
storageShed: storage.Shed,
76+
page: ?*Page = null,
7677

7778
jstypes: [Types.len]usize = undefined,
7879

@@ -95,6 +96,8 @@ pub const Session = struct {
9596
}
9697

9798
fn deinit(self: *Session) void {
99+
if (self.page) |page| page.end();
100+
98101
self.env.deinit();
99102
self.arena.deinit();
100103

@@ -130,10 +133,12 @@ pub const Page = struct {
130133
alloc: std.mem.Allocator,
131134
session: *Session,
132135
) Page {
133-
return Page{
136+
var page = Page{
134137
.arena = std.heap.ArenaAllocator.init(alloc),
135138
.session = session,
136139
};
140+
session.page = &page;
141+
return page;
137142
}
138143

139144
// reset js env and mem arena.
@@ -149,6 +154,7 @@ pub const Page = struct {
149154

150155
pub fn deinit(self: *Page) void {
151156
self.arena.deinit();
157+
self.session.page = null;
152158
}
153159

154160
// dump writes the page content into the given file.

0 commit comments

Comments
 (0)