From e0b8f2d02cd44ef748a5a01f671d49b2f713d294 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Sat, 4 Jan 2020 01:17:48 +0100 Subject: [PATCH] Fix some issues with v8::StartupData (#178) --- src/isolate.rs | 7 +++++-- src/snapshot.rs | 2 +- tests/test_api.rs | 8 ++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/isolate.rs b/src/isolate.rs index 96b41d5f..8cfc5603 100644 --- a/src/isolate.rs +++ b/src/isolate.rs @@ -397,9 +397,12 @@ impl CreateParams { /// - Compression of the startup blob might be useful, but needs to /// handled entirely on the embedders' side. /// - The call will abort if the data is invalid. - pub fn set_snapshot_blob(&mut self, snapshot_blob: &mut StartupData) { + pub fn set_snapshot_blob(&mut self, snapshot_blob: &StartupData) { unsafe { - v8__Isolate__CreateParams__SET__snapshot_blob(self, snapshot_blob) + v8__Isolate__CreateParams__SET__snapshot_blob( + self, + snapshot_blob as *const _ as *mut StartupData, + ) }; } } diff --git a/src/snapshot.rs b/src/snapshot.rs index f60756a0..f9b1972d 100644 --- a/src/snapshot.rs +++ b/src/snapshot.rs @@ -41,7 +41,7 @@ pub struct StartupData<'a> { impl<'a> StartupData<'a> { pub fn new(data: &'a D) -> Self where - D: Borrow<[u8]>, + D: Borrow<[u8]> + ?Sized, { let data = data.borrow(); Self { diff --git a/tests/test_api.rs b/tests/test_api.rs index ce5a5c9b..e72aede9 100644 --- a/tests/test_api.rs +++ b/tests/test_api.rs @@ -1494,7 +1494,7 @@ fn snapshot_creator() { let g = setup(); // First we create the snapshot, there is a single global variable 'a' set to // the value 3. - let mut startup_data = { + let startup_data = { let mut snapshot_creator = v8::SnapshotCreator::new(None); let isolate = snapshot_creator.get_isolate(); let mut locker = v8::Locker::new(&isolate); @@ -1524,7 +1524,7 @@ fn snapshot_creator() { { let mut params = v8::Isolate::create_params(); params.set_array_buffer_allocator(v8::new_default_allocator()); - params.set_snapshot_blob(&mut startup_data); + params.set_snapshot_blob(&startup_data); let isolate = v8::Isolate::new(params); let mut locker = v8::Locker::new(&isolate); { @@ -1560,7 +1560,7 @@ fn external_references() { let g = setup(); // First we create the snapshot, there is a single global variable 'a' set to // the value 3. - let mut startup_data = { + let startup_data = { let mut snapshot_creator = v8::SnapshotCreator::new(Some(&EXTERNAL_REFERENCES)); let isolate = snapshot_creator.get_isolate(); @@ -1595,7 +1595,7 @@ fn external_references() { { let mut params = v8::Isolate::create_params(); params.set_array_buffer_allocator(v8::new_default_allocator()); - params.set_snapshot_blob(&mut startup_data); + params.set_snapshot_blob(&startup_data); params.set_external_references(&EXTERNAL_REFERENCES); let isolate = v8::Isolate::new(params); let mut locker = v8::Locker::new(&isolate);