@@ -158,7 +158,10 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
158
158
159
159
platform : ? * const Platform ,
160
160
161
+ snapshot_creator : v8.SnapshotCreator ,
162
+
161
163
// the global isolate
164
+ // owned by snapshot_creator.
162
165
isolate : v8.Isolate ,
163
166
164
167
// 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 {
193
196
params .array_buffer_allocator = v8 .createDefaultArrayBufferAllocator ();
194
197
errdefer v8 .destroyArrayBufferAllocator (params .array_buffer_allocator .? );
195
198
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 ();
198
203
199
- isolate .enter ();
200
- errdefer isolate .exit ();
204
+ // snapshot_creator enters the isolate for us.
201
205
202
206
isolate .setHostInitializeImportMetaObjectCallback (struct {
203
207
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 {
218
222
219
223
env .* = .{
220
224
.platform = platform ,
225
+ .snapshot_creator = snapshot_creator ,
221
226
.isolate = isolate ,
222
227
.templates = undefined ,
223
228
.allocator = allocator ,
@@ -258,8 +263,9 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
258
263
}
259
264
260
265
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 ();
263
269
v8 .destroyArrayBufferAllocator (self .isolate_params .array_buffer_allocator .? );
264
270
self .allocator .destroy (self .isolate_params );
265
271
self .allocator .destroy (self );
0 commit comments