Skip to content

Commit 080b1d9

Browse files
committed
drain micro task queue before reset ExecutionWorld and page
1 parent a65aa9f commit 080b1d9

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/browser/js/ExecutionWorld.zig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,12 @@ pub fn createContext(self: *ExecutionWorld, page: *Page, enter: bool, global_cal
231231
}
232232

233233
pub fn removeContext(self: *ExecutionWorld) void {
234+
// Force running the micro task to drain the queue before reseting the
235+
// context arena.
236+
// Tasks in the queue are relying to the arena memory could be present in
237+
// the queue. Running them later could lead to invalid memory accesses.
238+
self.env.runMicrotasks();
239+
234240
self.context.?.deinit();
235241
self.context = null;
236242
_ = self.context_arena.reset(.{ .retain_with_limit = CONTEXT_ARENA_RETAIN });

src/browser/page.zig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ pub const Page = struct {
161161
}
162162

163163
fn reset(self: *Page) void {
164+
// Force running the micro task to drain the queue.
165+
self.session.browser.env.runMicrotasks();
166+
164167
self.scheduler.reset();
165168
self.http_client.abort();
166169
self.script_manager.reset();

0 commit comments

Comments
 (0)