Skip to content

Commit 14de84b

Browse files
Keep reference of current Page in Session
Signed-off-by: Francis Bouvier <francis@lightpanda.io>
1 parent 2a94e5a commit 14de84b

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/browser/browser.zig

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ pub const Session = struct {
6969
env: Env = undefined,
7070
loop: Loop,
7171
window: Window,
72+
page: ?*Page = null,
7273

7374
jstypes: [Types.len]usize = undefined,
7475

@@ -90,6 +91,10 @@ pub const Session = struct {
9091
}
9192

9293
fn deinit(self: *Session) void {
94+
if (self.page) |page| {
95+
page.end();
96+
}
97+
9398
self.env.deinit();
9499
self.arena.deinit();
95100

@@ -123,10 +128,12 @@ pub const Page = struct {
123128
alloc: std.mem.Allocator,
124129
session: *Session,
125130
) Page {
126-
return Page{
131+
const page = Page{
127132
.arena = std.heap.ArenaAllocator.init(alloc),
128133
.session = session,
129134
};
135+
session.page = page;
136+
return page;
130137
}
131138

132139
// reset js env and mem arena.
@@ -142,6 +149,7 @@ pub const Page = struct {
142149

143150
pub fn deinit(self: *Page) void {
144151
self.arena.deinit();
152+
self.session.page = null;
145153
}
146154

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

0 commit comments

Comments
 (0)