Skip to content

Commit e2cd983

Browse files
Merge pull request #220 from lightpanda-io/session_page
Keep reference of current Page in Session
2 parents 4444d8a + df82d25 commit e2cd983

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/browser/browser.zig

Lines changed: 9 additions & 2 deletions
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

@@ -129,11 +132,14 @@ pub const Page = struct {
129132
fn init(
130133
alloc: std.mem.Allocator,
131134
session: *Session,
132-
) Page {
133-
return Page{
135+
) !Page {
136+
if (session.page != null) return error.SessionPageExists;
137+
var page = Page{
134138
.arena = std.heap.ArenaAllocator.init(alloc),
135139
.session = session,
136140
};
141+
session.page = &page;
142+
return page;
137143
}
138144

139145
// reset js env and mem arena.
@@ -149,6 +155,7 @@ pub const Page = struct {
149155

150156
pub fn deinit(self: *Page) void {
151157
self.arena.deinit();
158+
self.session.page = null;
152159
}
153160

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

0 commit comments

Comments
 (0)