Skip to content

Commit 2dde39a

Browse files
committed
Use isolate form snapshot_creator
1 parent ab01401 commit 2dde39a

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/runtime/js.zig

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,10 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
158158

159159
platform: ?*const Platform,
160160

161+
snapshot_creator: v8.SnapshotCreator,
162+
161163
// the global isolate
164+
// owned by snapshot_creator.
162165
isolate: v8.Isolate,
163166

164167
// just kept around because we need to free it on deinit
@@ -193,11 +196,12 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
193196
params.array_buffer_allocator = v8.createDefaultArrayBufferAllocator();
194197
errdefer v8.destroyArrayBufferAllocator(params.array_buffer_allocator.?);
195198

196-
var isolate = v8.Isolate.init(params);
197-
errdefer isolate.deinit();
199+
var snapshot_creator = v8.SnapshotCreator.init(params);
200+
errdefer snapshot_creator.deinit();
201+
202+
var isolate = snapshot_creator.getIsolate();
198203

199-
isolate.enter();
200-
errdefer isolate.exit();
204+
// snapshot_creator enters the isolate for us.
201205

202206
isolate.setHostInitializeImportMetaObjectCallback(struct {
203207
fn callback(c_context: ?*v8.C_Context, c_module: ?*v8.C_Module, c_meta: ?*v8.C_Value) callconv(.C) void {
@@ -218,6 +222,7 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
218222

219223
env.* = .{
220224
.platform = platform,
225+
.snapshot_creator = snapshot_creator,
221226
.isolate = isolate,
222227
.templates = undefined,
223228
.allocator = allocator,
@@ -258,8 +263,9 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
258263
}
259264

260265
pub fn deinit(self: *Self) void {
261-
self.isolate.exit();
262-
self.isolate.deinit();
266+
// The snapshot_creator owns the isolate. So it exit and deinit it
267+
// for us.
268+
self.snapshot_creator.deinit();
263269
v8.destroyArrayBufferAllocator(self.isolate_params.array_buffer_allocator.?);
264270
self.allocator.destroy(self.isolate_params);
265271
self.allocator.destroy(self);

0 commit comments

Comments
 (0)