From 6638b05096c2657461b40c84a2383b189a67e322 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Wed, 6 May 2020 19:26:23 +0200 Subject: [PATCH] Fix: SnapshotCreator's internal Isolate does not get initialized (#371) --- src/isolate.rs | 8 ++++++-- src/snapshot.rs | 4 +++- tests/test_api.rs | 3 +++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/isolate.rs b/src/isolate.rs index 6e783924..9233b13c 100644 --- a/src/isolate.rs +++ b/src/isolate.rs @@ -159,10 +159,14 @@ impl Isolate { IsolateHandle::new(self) } - fn create_annex(&mut self, create_param_allocations: Box) { + pub(crate) fn create_annex( + &mut self, + create_param_allocations: Box, + ) { let annex_arc = Arc::new(IsolateAnnex::new(self, create_param_allocations)); let annex_ptr = Arc::into_raw(annex_arc); - unsafe { v8__Isolate__SetData(self, 0, annex_ptr as *mut c_void) } + unsafe { assert!(v8__Isolate__GetData(self, 0).is_null()) }; + unsafe { v8__Isolate__SetData(self, 0, annex_ptr as *mut c_void) }; } fn get_annex(&self) -> &IsolateAnnex { diff --git a/src/snapshot.rs b/src/snapshot.rs index 06693862..2f1685a3 100644 --- a/src/snapshot.rs +++ b/src/snapshot.rs @@ -133,6 +133,8 @@ impl SnapshotCreator { // revisited after the libdeno integration is complete. pub unsafe fn get_owned_isolate(&mut self) -> OwnedIsolate { let isolate_ptr = v8__SnapshotCreator__GetIsolate(self); - OwnedIsolate::new(isolate_ptr) + let mut owned_isolate = OwnedIsolate::new(isolate_ptr); + owned_isolate.create_annex(Box::new(())); + owned_isolate } } diff --git a/tests/test_api.rs b/tests/test_api.rs index fad89279..06f55ce4 100644 --- a/tests/test_api.rs +++ b/tests/test_api.rs @@ -1761,6 +1761,9 @@ fn snapshot_creator() { // the scope type system. let mut isolate = unsafe { snapshot_creator.get_owned_isolate() }; + // Check that the SnapshotCreator isolate has been set up correctly. + let _ = isolate.thread_safe_handle(); + let mut hs = v8::HandleScope::new(&mut isolate); let scope = hs.enter();