0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2024-12-24 08:09:16 -05:00

Remove v8::Locker (#272)

This patch clarifies that v8::Isolate is a single threaded creature,
which can only be accessed from other threads in special circumstances.
To ensure optimal operation in Deno, we remove v8::Locker, which ought
to be unnecessary when a thread is dedicated to each Isolate and the
Isolates never move between threads.

There are valid use-cases for v8::Locker, and we hope to address them in
future versions of rusty_v8.

Co-authored-by: Bert Belder <bertbelder@gmail.com>
This commit is contained in:
Ryan Dahl 2020-02-11 17:01:27 -05:00 committed by GitHub
parent 46bf0989fe
commit 32abe84dc6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 148 additions and 287 deletions

View file

@ -4,6 +4,7 @@ use super::session::V8InspectorSession;
use super::Channel; use super::Channel;
use super::StringView; use super::StringView;
use super::V8InspectorClient; use super::V8InspectorClient;
use crate::scope_traits::InIsolate;
use crate::support::int; use crate::support::int;
use crate::support::Delete; use crate::support::Delete;
use crate::support::Opaque; use crate::support::Opaque;
@ -37,7 +38,7 @@ pub struct V8Inspector(Opaque);
impl V8Inspector { impl V8Inspector {
pub fn create<T>( pub fn create<T>(
isolate: &mut Isolate, isolate: &mut impl InIsolate,
client: &mut T, client: &mut T,
) -> UniqueRef<V8Inspector> ) -> UniqueRef<V8Inspector>
where where
@ -45,7 +46,7 @@ impl V8Inspector {
{ {
unsafe { unsafe {
UniqueRef::from_raw(v8_inspector__V8Inspector__create( UniqueRef::from_raw(v8_inspector__V8Inspector__create(
isolate, isolate.isolate(),
client.as_client_mut(), client.as_client_mut(),
)) ))
} }

View file

@ -8,6 +8,7 @@ use crate::support::Opaque;
use crate::support::UniqueRef; use crate::support::UniqueRef;
use crate::Context; use crate::Context;
use crate::Function; use crate::Function;
use crate::InIsolate;
use crate::Local; use crate::Local;
use crate::Message; use crate::Message;
use crate::Module; use crate::Module;
@ -360,6 +361,12 @@ pub unsafe fn new_owned_isolate(isolate_ptr: *mut Isolate) -> OwnedIsolate {
/// Same as Isolate but gets disposed when it goes out of scope. /// Same as Isolate but gets disposed when it goes out of scope.
pub struct OwnedIsolate(NonNull<Isolate>); pub struct OwnedIsolate(NonNull<Isolate>);
impl InIsolate for OwnedIsolate {
fn isolate(&mut self) -> &mut Isolate {
self.deref_mut()
}
}
impl Drop for OwnedIsolate { impl Drop for OwnedIsolate {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { self.0.as_mut().dispose() } unsafe { self.0.as_mut().dispose() }

View file

@ -11,12 +11,9 @@
//! //!
//! let mut create_params = v8::Isolate::create_params(); //! let mut create_params = v8::Isolate::create_params();
//! create_params.set_array_buffer_allocator(v8::new_default_allocator()); //! create_params.set_array_buffer_allocator(v8::new_default_allocator());
//! let isolate = v8::Isolate::new(create_params); //! let mut isolate = v8::Isolate::new(create_params);
//! //!
//! let mut locker = v8::Locker::new(&isolate); //! let mut handle_scope = v8::HandleScope::new(&mut isolate);
//! let scope = locker.enter();
//!
//! let mut handle_scope = v8::HandleScope::new(scope);
//! let scope = handle_scope.enter(); //! let scope = handle_scope.enter();
//! //!
//! let context = v8::Context::new(scope); //! let context = v8::Context::new(scope);
@ -154,7 +151,6 @@ pub use property_attribute::*;
pub use scope::CallbackScope; pub use scope::CallbackScope;
pub use scope::ContextScope; pub use scope::ContextScope;
pub use scope::FunctionCallbackScope; pub use scope::FunctionCallbackScope;
pub use scope::Locker;
pub use scope::PropertyCallbackScope; pub use scope::PropertyCallbackScope;
pub use scope::Scope; pub use scope::Scope;
pub use scope_traits::*; pub use scope_traits::*;

View file

@ -246,49 +246,6 @@ impl<'s, X> From<&'s PromiseRejectMessage<'s>> for Scope<'s, CallbackScope<X>> {
} }
} }
#[repr(C)]
/// v8::Locker is a scoped lock object. While it's active, i.e. between its
/// construction and destruction, the current thread is allowed to use the locked
/// isolate. V8 guarantees that an isolate can be locked by at most one thread at
/// any time. In other words, the scope of a v8::Locker is a critical section.
pub struct Locker {
has_lock: bool,
top_level: bool,
isolate: *mut Isolate,
}
extern "C" {
fn v8__Locker__CONSTRUCT(buf: *mut Locker, isolate: *mut Isolate);
fn v8__Locker__DESTRUCT(this: &mut Locker);
}
impl<'s> Locker {
// TODO(piscisaureus): We should not be sharing &Isolate references between
// threads while at the same time dereferencing to &mut Isolate *within* the
// various scopes. Instead, add a separate type (e.g. IsolateHandle).
pub fn new(isolate: &Isolate) -> Scope<'s, Self> {
Scope::new_root(isolate as *const _ as *mut Isolate)
}
pub(crate) fn get_raw_isolate_(&self) -> *mut Isolate {
self.isolate
}
}
unsafe impl<'s> ScopeDefinition<'s> for Locker {
type Args = *mut Isolate;
unsafe fn enter_scope(buf: *mut Self, isolate: *mut Isolate) {
v8__Locker__CONSTRUCT(buf, isolate)
}
}
impl Drop for Locker {
fn drop(&mut self) {
unsafe { v8__Locker__DESTRUCT(self) }
}
}
/// Stack-allocated class which sets the execution context for all operations /// Stack-allocated class which sets the execution context for all operations
/// executed within a local scope. /// executed within a local scope.
pub struct ContextScope { pub struct ContextScope {

View file

@ -10,7 +10,6 @@ use crate::FunctionCallbackInfo;
use crate::HandleScope; use crate::HandleScope;
use crate::Isolate; use crate::Isolate;
use crate::Local; use crate::Local;
use crate::Locker;
use crate::Message; use crate::Message;
use crate::Object; use crate::Object;
use crate::PropertyCallbackInfo; use crate::PropertyCallbackInfo;
@ -83,12 +82,6 @@ pub(crate) mod internal {
} }
} }
impl GetRawIsolate for Locker {
fn get_raw_isolate(&self) -> *mut Isolate {
self.get_raw_isolate_()
}
}
impl GetRawIsolate for Context { impl GetRawIsolate for Context {
fn get_raw_isolate(&self) -> *mut Isolate { fn get_raw_isolate(&self) -> *mut Isolate {
unsafe { v8__Context__GetIsolate(self) } unsafe { v8__Context__GetIsolate(self) }

View file

@ -1,5 +1,6 @@
// Copyright 2019-2020 the Deno authors. All rights reserved. MIT license. // Copyright 2019-2020 the Deno authors. All rights reserved. MIT license.
//! For compiling scripts. //! For compiling scripts.
use crate::InIsolate;
use crate::Isolate; use crate::Isolate;
use crate::Local; use crate::Local;
use crate::Module; use crate::Module;
@ -77,11 +78,11 @@ pub enum NoCacheReason {
/// Corresponds to the ParseModule abstract operation in the ECMAScript /// Corresponds to the ParseModule abstract operation in the ECMAScript
/// specification. /// specification.
pub fn compile_module<'a>( pub fn compile_module<'a>(
isolate: &Isolate, scope: &mut impl InIsolate,
source: Source, source: Source,
) -> Option<Local<'a, Module>> { ) -> Option<Local<'a, Module>> {
compile_module2( compile_module2(
isolate, scope,
source, source,
CompileOptions::NoCompileOptions, CompileOptions::NoCompileOptions,
NoCacheReason::NoReason, NoCacheReason::NoReason,
@ -90,14 +91,14 @@ pub fn compile_module<'a>(
/// Same as compile_module with more options. /// Same as compile_module with more options.
pub fn compile_module2<'a>( pub fn compile_module2<'a>(
isolate: &Isolate, scope: &mut impl InIsolate,
source: Source, source: Source,
options: CompileOptions, options: CompileOptions,
no_cache_reason: NoCacheReason, no_cache_reason: NoCacheReason,
) -> Option<Local<'a, Module>> { ) -> Option<Local<'a, Module>> {
unsafe { unsafe {
Local::from_raw(v8__ScriptCompiler__CompileModule( Local::from_raw(v8__ScriptCompiler__CompileModule(
isolate, scope.isolate(),
&source, &source,
options, options,
no_cache_reason, no_cache_reason,

View file

@ -17,9 +17,7 @@ extern "C" {
external_references: *const intptr_t, external_references: *const intptr_t,
); );
fn v8__SnapshotCreator__DESTRUCT(this: &mut SnapshotCreator); fn v8__SnapshotCreator__DESTRUCT(this: &mut SnapshotCreator);
fn v8__SnapshotCreator__GetIsolate( fn v8__SnapshotCreator__GetIsolate(this: &SnapshotCreator) -> &mut Isolate;
this: &mut SnapshotCreator,
) -> &mut Isolate;
fn v8__SnapshotCreator__CreateBlob( fn v8__SnapshotCreator__CreateBlob(
this: *mut SnapshotCreator, this: *mut SnapshotCreator,
function_code_handling: FunctionCodeHandling, function_code_handling: FunctionCodeHandling,
@ -151,9 +149,4 @@ impl SnapshotCreator {
let isolate_ptr = v8__SnapshotCreator__GetIsolate(self); let isolate_ptr = v8__SnapshotCreator__GetIsolate(self);
crate::isolate::new_owned_isolate(isolate_ptr) crate::isolate::new_owned_isolate(isolate_ptr)
} }
/// Returns the isolate prepared by the snapshot creator.
pub fn get_isolate(&mut self) -> &Isolate {
unsafe { v8__SnapshotCreator__GetIsolate(self) }
}
} }

View file

@ -2,8 +2,8 @@
use rusty_v8 as v8; use rusty_v8 as v8;
pub fn main() { pub fn main() {
let mut locker = v8::Locker::new(mock()); let mut isolate = v8::Isolate::new(mock());
let mut hs0 = v8::HandleScope::new(locker.enter()); let mut hs0 = v8::HandleScope::new(&mut isolate);
let hs0 = hs0.enter(); let hs0 = hs0.enter();
let _fail = { let _fail = {

View file

@ -2,8 +2,8 @@
use rusty_v8 as v8; use rusty_v8 as v8;
pub fn main() { pub fn main() {
let mut locker = v8::Locker::new(mock()); let mut isolate = v8::Isolate::new(mock());
let mut root_hs = v8::HandleScope::new(locker.enter()); let mut root_hs = v8::HandleScope::new(&mut isolate);
let root_hs = root_hs.enter(); let root_hs = root_hs.enter();
{ {

View file

@ -2,7 +2,7 @@
use rusty_v8 as v8; use rusty_v8 as v8;
pub fn main() { pub fn main() {
let mut scope: v8::Scope<v8::HandleScope, v8::Locker> = mock(); let mut scope: v8::Scope<v8::HandleScope, v8::Isolate> = mock();
let scope = scope.enter(); let scope = scope.enter();
let context: v8::Local<v8::Context> = mock(); let context: v8::Local<v8::Context> = mock();

View file

@ -39,11 +39,9 @@ fn handle_scope_nested() {
let _setup_guard = setup(); let _setup_guard = setup();
let mut params = v8::Isolate::create_params(); let mut params = v8::Isolate::create_params();
params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_array_buffer_allocator(v8::new_default_allocator());
let isolate = v8::Isolate::new(params); let mut isolate = v8::Isolate::new(params);
let mut locker = v8::Locker::new(&isolate);
let scope0 = locker.enter();
{ {
let mut hs = v8::HandleScope::new(scope0); let mut hs = v8::HandleScope::new(&mut isolate);
let scope1 = hs.enter(); let scope1 = hs.enter();
{ {
let mut hs = v8::HandleScope::new(scope1); let mut hs = v8::HandleScope::new(scope1);
@ -58,11 +56,9 @@ fn handle_scope_numbers() {
let _setup_guard = setup(); let _setup_guard = setup();
let mut params = v8::Isolate::create_params(); let mut params = v8::Isolate::create_params();
params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_array_buffer_allocator(v8::new_default_allocator());
let isolate = v8::Isolate::new(params); let mut isolate = v8::Isolate::new(params);
let mut locker = v8::Locker::new(&isolate);
let scope0 = locker.enter();
{ {
let mut hs = v8::HandleScope::new(scope0); let mut hs = v8::HandleScope::new(&mut isolate);
let scope1 = hs.enter(); let scope1 = hs.enter();
let l1 = v8::Integer::new(scope1, -123); let l1 = v8::Integer::new(scope1, -123);
let l2 = v8::Integer::new_from_unsigned(scope1, 456); let l2 = v8::Integer::new_from_unsigned(scope1, 456);
@ -84,9 +80,7 @@ fn global_handles() {
let _setup_guard = setup(); let _setup_guard = setup();
let mut params = v8::Isolate::create_params(); let mut params = v8::Isolate::create_params();
params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_array_buffer_allocator(v8::new_default_allocator());
let isolate = v8::Isolate::new(params); let mut isolate = v8::Isolate::new(params);
let mut locker = v8::Locker::new(&isolate);
let scope = locker.enter();
let mut g1 = v8::Global::<v8::String>::new(); let mut g1 = v8::Global::<v8::String>::new();
let mut g2 = v8::Global::<v8::Integer>::new(); let mut g2 = v8::Global::<v8::Integer>::new();
let mut g3 = v8::Global::<v8::Integer>::new(); let mut g3 = v8::Global::<v8::Integer>::new();
@ -94,7 +88,7 @@ fn global_handles() {
let g5 = v8::Global::<v8::Script>::new(); let g5 = v8::Global::<v8::Script>::new();
let mut g6 = v8::Global::<v8::Integer>::new(); let mut g6 = v8::Global::<v8::Integer>::new();
{ {
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let l1 = v8::String::new(scope, "bla").unwrap(); let l1 = v8::String::new(scope, "bla").unwrap();
let l2 = v8::Integer::new(scope, 123); let l2 = v8::Integer::new(scope, 123);
@ -106,7 +100,7 @@ fn global_handles() {
g6.set(scope, l6); g6.set(scope, l6);
} }
{ {
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
assert!(!g1.is_empty()); assert!(!g1.is_empty());
assert_eq!(g1.get(scope).unwrap().to_rust_string_lossy(scope), "bla"); assert_eq!(g1.get(scope).unwrap().to_rust_string_lossy(scope), "bla");
@ -121,13 +115,13 @@ fn global_handles() {
g6.reset(scope); g6.reset(scope);
assert_eq!(num.value(), 100); assert_eq!(num.value(), 100);
} }
g1.reset(scope); g1.reset(&mut isolate);
assert!(g1.is_empty()); assert!(g1.is_empty());
g2.reset(scope); g2.reset(&mut isolate);
assert!(g2.is_empty()); assert!(g2.is_empty());
g3.reset(scope); g3.reset(&mut isolate);
assert!(g3.is_empty()); assert!(g3.is_empty());
_g4.reset(scope); _g4.reset(&mut isolate);
assert!(_g4.is_empty()); assert!(_g4.is_empty());
assert!(g5.is_empty()); assert!(g5.is_empty());
} }
@ -137,11 +131,9 @@ fn test_string() {
let _setup_guard = setup(); let _setup_guard = setup();
let mut params = v8::Isolate::create_params(); let mut params = v8::Isolate::create_params();
params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_array_buffer_allocator(v8::new_default_allocator());
let isolate = v8::Isolate::new(params); let mut isolate = v8::Isolate::new(params);
let mut locker = v8::Locker::new(&isolate);
let scope = locker.enter();
{ {
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let reference = "Hello 🦕 world!"; let reference = "Hello 🦕 world!";
let local = v8::String::new(scope, reference).unwrap(); let local = v8::String::new(scope, reference).unwrap();
@ -150,7 +142,7 @@ fn test_string() {
assert_eq!(reference, local.to_rust_string_lossy(scope)); assert_eq!(reference, local.to_rust_string_lossy(scope));
} }
{ {
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let local = v8::String::empty(scope); let local = v8::String::empty(scope);
assert_eq!(0, local.length()); assert_eq!(0, local.length());
@ -158,7 +150,7 @@ fn test_string() {
assert_eq!("", local.to_rust_string_lossy(scope)); assert_eq!("", local.to_rust_string_lossy(scope));
} }
{ {
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let local = let local =
v8::String::new_from_utf8(scope, b"", v8::NewStringType::Normal).unwrap(); v8::String::new_from_utf8(scope, b"", v8::NewStringType::Normal).unwrap();
@ -174,11 +166,9 @@ fn escapable_handle_scope() {
let _setup_guard = setup(); let _setup_guard = setup();
let mut params = v8::Isolate::create_params(); let mut params = v8::Isolate::create_params();
params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_array_buffer_allocator(v8::new_default_allocator());
let isolate = v8::Isolate::new(params); let mut isolate = v8::Isolate::new(params);
let mut locker = v8::Locker::new(&isolate);
let scope0 = locker.enter();
{ {
let mut hs = v8::HandleScope::new(scope0); let mut hs = v8::HandleScope::new(&mut isolate);
let scope1 = hs.enter(); let scope1 = hs.enter();
// After dropping EscapableHandleScope, we should be able to // After dropping EscapableHandleScope, we should be able to
// read escaped values. // read escaped values.
@ -219,14 +209,12 @@ fn microtasks() {
let _setup_guard = setup(); let _setup_guard = setup();
let mut params = v8::Isolate::create_params(); let mut params = v8::Isolate::create_params();
params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_array_buffer_allocator(v8::new_default_allocator());
let isolate = v8::Isolate::new(params); let mut isolate = v8::Isolate::new(params);
let mut locker = v8::Locker::new(&isolate);
let scope = locker.enter();
scope.isolate().run_microtasks(); isolate.run_microtasks();
{ {
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let context = v8::Context::new(scope); let context = v8::Context::new(scope);
let mut cs = v8::ContextScope::new(scope, context); let mut cs = v8::ContextScope::new(scope, context);
@ -256,11 +244,9 @@ fn array_buffer() {
let _setup_guard = setup(); let _setup_guard = setup();
let mut params = v8::Isolate::create_params(); let mut params = v8::Isolate::create_params();
params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_array_buffer_allocator(v8::new_default_allocator());
let isolate = v8::Isolate::new(params); let mut isolate = v8::Isolate::new(params);
let mut locker = v8::Locker::new(&isolate);
let scope = locker.enter();
{ {
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let context = v8::Context::new(scope); let context = v8::Context::new(scope);
let mut cs = v8::ContextScope::new(scope, context); let mut cs = v8::ContextScope::new(scope, context);
@ -305,11 +291,9 @@ fn array_buffer_with_shared_backing_store() {
let _setup_guard = setup(); let _setup_guard = setup();
let mut params = v8::Isolate::create_params(); let mut params = v8::Isolate::create_params();
params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_array_buffer_allocator(v8::new_default_allocator());
let isolate = v8::Isolate::new(params); let mut isolate = v8::Isolate::new(params);
let mut locker = v8::Locker::new(&isolate);
let scope = locker.enter();
{ {
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let context = v8::Context::new(scope); let context = v8::Context::new(scope);
@ -389,11 +373,9 @@ fn try_catch() {
let _setup_guard = setup(); let _setup_guard = setup();
let mut params = v8::Isolate::create_params(); let mut params = v8::Isolate::create_params();
params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_array_buffer_allocator(v8::new_default_allocator());
let isolate = v8::Isolate::new(params); let mut isolate = v8::Isolate::new(params);
let mut locker = v8::Locker::new(&isolate);
let scope = locker.enter();
{ {
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let context = v8::Context::new(scope); let context = v8::Context::new(scope);
let mut cs = v8::ContextScope::new(scope, context); let mut cs = v8::ContextScope::new(scope, context);
@ -448,11 +430,9 @@ fn throw_exception() {
let _setup_guard = setup(); let _setup_guard = setup();
let mut params = v8::Isolate::create_params(); let mut params = v8::Isolate::create_params();
params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_array_buffer_allocator(v8::new_default_allocator());
let isolate = v8::Isolate::new(params); let mut isolate = v8::Isolate::new(params);
let mut locker = v8::Locker::new(&isolate);
let scope = locker.enter();
{ {
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let context = v8::Context::new(scope); let context = v8::Context::new(scope);
let mut cs = v8::ContextScope::new(scope, context); let mut cs = v8::ContextScope::new(scope, context);
@ -476,12 +456,10 @@ fn terminate_execution() {
let _setup_guard = setup(); let _setup_guard = setup();
let mut params = v8::Isolate::create_params(); let mut params = v8::Isolate::create_params();
params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_array_buffer_allocator(v8::new_default_allocator());
let isolate = v8::Isolate::new(params); let mut isolate = v8::Isolate::new(params);
let mut locker = v8::Locker::new(&isolate);
let scope = locker.enter();
// Originally run fine. // Originally run fine.
{ {
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let context = v8::Context::new(scope); let context = v8::Context::new(scope);
let mut cs = v8::ContextScope::new(scope, context); let mut cs = v8::ContextScope::new(scope, context);
@ -494,7 +472,7 @@ fn terminate_execution() {
isolate.terminate_execution(); isolate.terminate_execution();
// Below run should fail with terminated knowledge. // Below run should fail with terminated knowledge.
{ {
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let context = v8::Context::new(scope); let context = v8::Context::new(scope);
let mut cs = v8::ContextScope::new(scope, context); let mut cs = v8::ContextScope::new(scope, context);
@ -509,7 +487,7 @@ fn terminate_execution() {
isolate.cancel_terminate_execution(); isolate.cancel_terminate_execution();
// Works again. // Works again.
{ {
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let context = v8::Context::new(scope); let context = v8::Context::new(scope);
let mut cs = v8::ContextScope::new(scope, context); let mut cs = v8::ContextScope::new(scope, context);
@ -525,11 +503,9 @@ fn request_interrupt_small_scripts() {
let _setup_guard = setup(); let _setup_guard = setup();
let mut params = v8::Isolate::create_params(); let mut params = v8::Isolate::create_params();
params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_array_buffer_allocator(v8::new_default_allocator());
let isolate = v8::Isolate::new(params); let mut isolate = v8::Isolate::new(params);
let mut locker = v8::Locker::new(&isolate);
let scope = locker.enter();
{ {
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let context = v8::Context::new(scope); let context = v8::Context::new(scope);
let mut cs = v8::ContextScope::new(scope, context); let mut cs = v8::ContextScope::new(scope, context);
@ -543,7 +519,9 @@ fn request_interrupt_small_scripts() {
assert_eq!(data, std::ptr::null_mut()); assert_eq!(data, std::ptr::null_mut());
CALL_COUNT.fetch_add(1, Ordering::SeqCst); CALL_COUNT.fetch_add(1, Ordering::SeqCst);
} }
isolate.request_interrupt(callback, std::ptr::null_mut()); scope
.isolate()
.request_interrupt(callback, std::ptr::null_mut());
eval(scope, context, "(function(x){return x;})(1);"); eval(scope, context, "(function(x){return x;})(1);");
assert_eq!(CALL_COUNT.load(Ordering::SeqCst), 1); assert_eq!(CALL_COUNT.load(Ordering::SeqCst), 1);
} }
@ -597,10 +575,8 @@ fn add_message_listener() {
} }
isolate.add_message_listener(check_message_0); isolate.add_message_listener(check_message_0);
let mut locker = v8::Locker::new(&isolate);
let scope = locker.enter();
{ {
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let context = v8::Context::new(scope); let context = v8::Context::new(scope);
let mut cs = v8::ContextScope::new(scope, context); let mut cs = v8::ContextScope::new(scope, context);
@ -644,17 +620,15 @@ fn set_host_initialize_import_meta_object_callback() {
} }
isolate.set_host_initialize_import_meta_object_callback(callback); isolate.set_host_initialize_import_meta_object_callback(callback);
let mut locker = v8::Locker::new(&isolate);
let scope = locker.enter();
{ {
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let context = v8::Context::new(scope); let context = v8::Context::new(scope);
let mut cs = v8::ContextScope::new(scope, context); let mut cs = v8::ContextScope::new(scope, context);
let scope = cs.enter(); let scope = cs.enter();
let source = mock_source(scope, "google.com", "import.meta;"); let source = mock_source(scope, "google.com", "import.meta;");
let mut module = let mut module =
v8::script_compiler::compile_module(&isolate, source).unwrap(); v8::script_compiler::compile_module(scope, source).unwrap();
let result = let result =
module.instantiate_module(context, unexpected_module_resolve_callback); module.instantiate_module(context, unexpected_module_resolve_callback);
assert!(result.is_some()); assert!(result.is_some());
@ -674,11 +648,9 @@ fn script_compile_and_run() {
let _setup_guard = setup(); let _setup_guard = setup();
let mut params = v8::Isolate::create_params(); let mut params = v8::Isolate::create_params();
params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_array_buffer_allocator(v8::new_default_allocator());
let isolate = v8::Isolate::new(params); let mut isolate = v8::Isolate::new(params);
let mut locker = v8::Locker::new(&isolate);
let scope = locker.enter();
{ {
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let context = v8::Context::new(scope); let context = v8::Context::new(scope);
let mut cs = v8::ContextScope::new(scope, context); let mut cs = v8::ContextScope::new(scope, context);
@ -697,12 +669,10 @@ fn script_origin() {
let _setup_guard = setup(); let _setup_guard = setup();
let mut params = v8::Isolate::create_params(); let mut params = v8::Isolate::create_params();
params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_array_buffer_allocator(v8::new_default_allocator());
let isolate = v8::Isolate::new(params); let mut isolate = v8::Isolate::new(params);
let mut locker = v8::Locker::new(&isolate);
let scope = locker.enter();
{ {
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let context = v8::Context::new(scope); let context = v8::Context::new(scope);
let mut cs = v8::ContextScope::new(scope, context); let mut cs = v8::ContextScope::new(scope, context);
@ -790,11 +760,9 @@ fn test_primitives() {
let _setup_guard = setup(); let _setup_guard = setup();
let mut params = v8::Isolate::create_params(); let mut params = v8::Isolate::create_params();
params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_array_buffer_allocator(v8::new_default_allocator());
let isolate = v8::Isolate::new(params); let mut isolate = v8::Isolate::new(params);
let mut locker = v8::Locker::new(&isolate);
let scope = locker.enter();
{ {
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let null = v8::null(scope); let null = v8::null(scope);
assert!(!null.is_undefined()); assert!(!null.is_undefined());
@ -825,10 +793,8 @@ fn exception() {
let _setup_guard = setup(); let _setup_guard = setup();
let mut params = v8::Isolate::create_params(); let mut params = v8::Isolate::create_params();
params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_array_buffer_allocator(v8::new_default_allocator());
let isolate = v8::Isolate::new(params); let mut isolate = v8::Isolate::new(params);
let mut locker = v8::Locker::new(&isolate); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = locker.enter();
let mut hs = v8::HandleScope::new(scope);
let scope = hs.enter(); let scope = hs.enter();
let context = v8::Context::new(scope); let context = v8::Context::new(scope);
let mut cs = v8::ContextScope::new(scope, context); let mut cs = v8::ContextScope::new(scope, context);
@ -854,10 +820,8 @@ fn create_message_argument_lifetimes() {
let _setup_guard = setup(); let _setup_guard = setup();
let mut params = v8::Isolate::create_params(); let mut params = v8::Isolate::create_params();
params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_array_buffer_allocator(v8::new_default_allocator());
let isolate = v8::Isolate::new(params); let mut isolate = v8::Isolate::new(params);
let mut locker = v8::Locker::new(&isolate); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = locker.enter();
let mut hs = v8::HandleScope::new(scope);
let scope = hs.enter(); let scope = hs.enter();
let context = v8::Context::new(scope); let context = v8::Context::new(scope);
let mut cs = v8::ContextScope::new(scope, context); let mut cs = v8::ContextScope::new(scope, context);
@ -893,11 +857,9 @@ fn json() {
let _setup_guard = setup(); let _setup_guard = setup();
let mut params = v8::Isolate::create_params(); let mut params = v8::Isolate::create_params();
params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_array_buffer_allocator(v8::new_default_allocator());
let isolate = v8::Isolate::new(params); let mut isolate = v8::Isolate::new(params);
let mut locker = v8::Locker::new(&isolate);
let scope = locker.enter();
{ {
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let context = v8::Context::new(scope); let context = v8::Context::new(scope);
let mut cs = v8::ContextScope::new(scope, context); let mut cs = v8::ContextScope::new(scope, context);
@ -919,11 +881,9 @@ fn object_template() {
let _setup_guard = setup(); let _setup_guard = setup();
let mut params = v8::Isolate::create_params(); let mut params = v8::Isolate::create_params();
params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_array_buffer_allocator(v8::new_default_allocator());
let isolate = v8::Isolate::new(params); let mut isolate = v8::Isolate::new(params);
let mut locker = v8::Locker::new(&isolate);
let scope = locker.enter();
{ {
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let object_templ = v8::ObjectTemplate::new(scope); let object_templ = v8::ObjectTemplate::new(scope);
let function_templ = v8::FunctionTemplate::new(scope, fortytwo_callback); let function_templ = v8::FunctionTemplate::new(scope, fortytwo_callback);
@ -971,11 +931,9 @@ fn object_template_from_function_template() {
let _setup_guard = setup(); let _setup_guard = setup();
let mut params = v8::Isolate::create_params(); let mut params = v8::Isolate::create_params();
params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_array_buffer_allocator(v8::new_default_allocator());
let isolate = v8::Isolate::new(params); let mut isolate = v8::Isolate::new(params);
let mut locker = v8::Locker::new(&isolate);
let scope = locker.enter();
{ {
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let mut function_templ = let mut function_templ =
v8::FunctionTemplate::new(scope, fortytwo_callback); v8::FunctionTemplate::new(scope, fortytwo_callback);
@ -1002,11 +960,9 @@ fn object() {
let _setup_guard = setup(); let _setup_guard = setup();
let mut params = v8::Isolate::create_params(); let mut params = v8::Isolate::create_params();
params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_array_buffer_allocator(v8::new_default_allocator());
let isolate = v8::Isolate::new(params); let mut isolate = v8::Isolate::new(params);
let mut locker = v8::Locker::new(&isolate);
let scope = locker.enter();
{ {
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let context = v8::Context::new(scope); let context = v8::Context::new(scope);
let mut cs = v8::ContextScope::new(scope, context); let mut cs = v8::ContextScope::new(scope, context);
@ -1039,11 +995,9 @@ fn array() {
let _setup_guard = setup(); let _setup_guard = setup();
let mut params = v8::Isolate::create_params(); let mut params = v8::Isolate::create_params();
params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_array_buffer_allocator(v8::new_default_allocator());
let isolate = v8::Isolate::new(params); let mut isolate = v8::Isolate::new(params);
let mut locker = v8::Locker::new(&isolate);
let scope = locker.enter();
{ {
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let context = v8::Context::new(scope); let context = v8::Context::new(scope);
let mut cs = v8::ContextScope::new(scope, context); let mut cs = v8::ContextScope::new(scope, context);
@ -1073,11 +1027,9 @@ fn create_data_property() {
let _setup_guard = setup(); let _setup_guard = setup();
let mut params = v8::Isolate::create_params(); let mut params = v8::Isolate::create_params();
params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_array_buffer_allocator(v8::new_default_allocator());
let isolate = v8::Isolate::new(params); let mut isolate = v8::Isolate::new(params);
let mut locker = v8::Locker::new(&isolate);
let scope = locker.enter();
{ {
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let context = v8::Context::new(scope); let context = v8::Context::new(scope);
let mut cs = v8::ContextScope::new(scope, context); let mut cs = v8::ContextScope::new(scope, context);
@ -1112,10 +1064,8 @@ fn object_set_accessor() {
let _setup_guard = setup(); let _setup_guard = setup();
let mut params = v8::Isolate::create_params(); let mut params = v8::Isolate::create_params();
params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_array_buffer_allocator(v8::new_default_allocator());
let isolate = v8::Isolate::new(params); let mut isolate = v8::Isolate::new(params);
let mut locker = v8::Locker::new(&isolate); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = locker.enter();
let mut hs = v8::HandleScope::new(scope);
let scope = hs.enter(); let scope = hs.enter();
let context = v8::Context::new(scope); let context = v8::Context::new(scope);
let mut cs = v8::ContextScope::new(scope, context); let mut cs = v8::ContextScope::new(scope, context);
@ -1172,11 +1122,9 @@ fn promise_resolved() {
let _setup_guard = setup(); let _setup_guard = setup();
let mut params = v8::Isolate::create_params(); let mut params = v8::Isolate::create_params();
params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_array_buffer_allocator(v8::new_default_allocator());
let isolate = v8::Isolate::new(params); let mut isolate = v8::Isolate::new(params);
let mut locker = v8::Locker::new(&isolate);
let scope = locker.enter();
{ {
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let context = v8::Context::new(scope); let context = v8::Context::new(scope);
let mut cs = v8::ContextScope::new(scope, context); let mut cs = v8::ContextScope::new(scope, context);
@ -1208,11 +1156,9 @@ fn promise_rejected() {
let _setup_guard = setup(); let _setup_guard = setup();
let mut params = v8::Isolate::create_params(); let mut params = v8::Isolate::create_params();
params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_array_buffer_allocator(v8::new_default_allocator());
let isolate = v8::Isolate::new(params); let mut isolate = v8::Isolate::new(params);
let mut locker = v8::Locker::new(&isolate);
let scope = locker.enter();
{ {
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let context = v8::Context::new(scope); let context = v8::Context::new(scope);
let mut cs = v8::ContextScope::new(scope, context); let mut cs = v8::ContextScope::new(scope, context);
@ -1285,12 +1231,10 @@ fn function() {
let _setup_guard = setup(); let _setup_guard = setup();
let mut params = v8::Isolate::create_params(); let mut params = v8::Isolate::create_params();
params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_array_buffer_allocator(v8::new_default_allocator());
let isolate = v8::Isolate::new(params); let mut isolate = v8::Isolate::new(params);
let mut locker = v8::Locker::new(&isolate);
let scope = locker.enter();
{ {
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let context = v8::Context::new(scope); let context = v8::Context::new(scope);
let mut cs = v8::ContextScope::new(scope, context); let mut cs = v8::ContextScope::new(scope, context);
@ -1346,10 +1290,8 @@ fn set_promise_reject_callback() {
params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_array_buffer_allocator(v8::new_default_allocator());
let mut isolate = v8::Isolate::new(params); let mut isolate = v8::Isolate::new(params);
isolate.set_promise_reject_callback(promise_reject_callback); isolate.set_promise_reject_callback(promise_reject_callback);
let mut locker = v8::Locker::new(&isolate);
let scope = locker.enter();
{ {
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let context = v8::Context::new(scope); let context = v8::Context::new(scope);
let mut cs = v8::ContextScope::new(scope, context); let mut cs = v8::ContextScope::new(scope, context);
@ -1403,10 +1345,8 @@ fn script_compiler_source() {
params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_array_buffer_allocator(v8::new_default_allocator());
let mut isolate = v8::Isolate::new(params); let mut isolate = v8::Isolate::new(params);
isolate.set_promise_reject_callback(promise_reject_callback); isolate.set_promise_reject_callback(promise_reject_callback);
let mut locker = v8::Locker::new(&isolate);
let scope = locker.enter();
{ {
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let context = v8::Context::new(scope); let context = v8::Context::new(scope);
let mut cs = v8::ContextScope::new(scope, context); let mut cs = v8::ContextScope::new(scope, context);
@ -1417,7 +1357,7 @@ fn script_compiler_source() {
let source = let source =
v8::script_compiler::Source::new(v8_str(scope, source), &script_origin); v8::script_compiler::Source::new(v8_str(scope, source), &script_origin);
let result = v8::script_compiler::compile_module(&isolate, source); let result = v8::script_compiler::compile_module(scope, source);
assert!(result.is_some()); assert!(result.is_some());
} }
} }
@ -1427,11 +1367,9 @@ fn module_instantiation_failures1() {
let _setup_guard = setup(); let _setup_guard = setup();
let mut params = v8::Isolate::create_params(); let mut params = v8::Isolate::create_params();
params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_array_buffer_allocator(v8::new_default_allocator());
let isolate = v8::Isolate::new(params); let mut isolate = v8::Isolate::new(params);
let mut locker = v8::Locker::new(&isolate);
let scope = locker.enter();
{ {
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let context = v8::Context::new(scope); let context = v8::Context::new(scope);
let mut cs = v8::ContextScope::new(scope, context); let mut cs = v8::ContextScope::new(scope, context);
@ -1446,7 +1384,7 @@ fn module_instantiation_failures1() {
let source = v8::script_compiler::Source::new(source_text, &origin); let source = v8::script_compiler::Source::new(source_text, &origin);
let mut module = let mut module =
v8::script_compiler::compile_module(&isolate, source).unwrap(); v8::script_compiler::compile_module(scope, source).unwrap();
assert_eq!(v8::ModuleStatus::Uninstantiated, module.get_status()); assert_eq!(v8::ModuleStatus::Uninstantiated, module.get_status());
assert_eq!(2, module.get_module_requests_length()); assert_eq!(2, module.get_module_requests_length());
@ -1504,8 +1442,7 @@ fn compile_specifier_as_module_resolve_callback<'a>(
let scope = hs.enter(); let scope = hs.enter();
let origin = mock_script_origin(scope, "module.js"); let origin = mock_script_origin(scope, "module.js");
let source = v8::script_compiler::Source::new(specifier, &origin); let source = v8::script_compiler::Source::new(specifier, &origin);
let module = let module = v8::script_compiler::compile_module(scope, source).unwrap();
v8::script_compiler::compile_module(scope.isolate(), source).unwrap();
Some(scope.escape(module)) Some(scope.escape(module))
} }
@ -1514,11 +1451,9 @@ fn module_evaluation() {
let _setup_guard = setup(); let _setup_guard = setup();
let mut params = v8::Isolate::create_params(); let mut params = v8::Isolate::create_params();
params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_array_buffer_allocator(v8::new_default_allocator());
let isolate = v8::Isolate::new(params); let mut isolate = v8::Isolate::new(params);
let mut locker = v8::Locker::new(&isolate);
let scope = locker.enter();
{ {
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let context = v8::Context::new(scope); let context = v8::Context::new(scope);
let mut cs = v8::ContextScope::new(scope, context); let mut cs = v8::ContextScope::new(scope, context);
@ -1533,7 +1468,7 @@ fn module_evaluation() {
let source = v8::script_compiler::Source::new(source_text, &origin); let source = v8::script_compiler::Source::new(source_text, &origin);
let mut module = let mut module =
v8::script_compiler::compile_module(&isolate, source).unwrap(); v8::script_compiler::compile_module(scope, source).unwrap();
assert_eq!(v8::ModuleStatus::Uninstantiated, module.get_status()); assert_eq!(v8::ModuleStatus::Uninstantiated, module.get_status());
let result = module.instantiate_module( let result = module.instantiate_module(
@ -1559,11 +1494,9 @@ fn primitive_array() {
let _setup_guard = setup(); let _setup_guard = setup();
let mut params = v8::Isolate::create_params(); let mut params = v8::Isolate::create_params();
params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_array_buffer_allocator(v8::new_default_allocator());
let isolate = v8::Isolate::new(params); let mut isolate = v8::Isolate::new(params);
let mut locker = v8::Locker::new(&isolate);
let scope = locker.enter();
{ {
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let context = v8::Context::new(scope); let context = v8::Context::new(scope);
let mut cs = v8::ContextScope::new(scope, context); let mut cs = v8::ContextScope::new(scope, context);
@ -1596,11 +1529,9 @@ fn equality() {
let _setup_guard = setup(); let _setup_guard = setup();
let mut params = v8::Isolate::create_params(); let mut params = v8::Isolate::create_params();
params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_array_buffer_allocator(v8::new_default_allocator());
let isolate = v8::Isolate::new(params); let mut isolate = v8::Isolate::new(params);
let mut locker = v8::Locker::new(&isolate);
let scope = locker.enter();
{ {
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let context = v8::Context::new(scope); let context = v8::Context::new(scope);
let mut cs = v8::ContextScope::new(scope, context); let mut cs = v8::ContextScope::new(scope, context);
@ -1619,11 +1550,9 @@ fn array_buffer_view() {
let _setup_guard = setup(); let _setup_guard = setup();
let mut params = v8::Isolate::create_params(); let mut params = v8::Isolate::create_params();
params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_array_buffer_allocator(v8::new_default_allocator());
let isolate = v8::Isolate::new(params); let mut isolate = v8::Isolate::new(params);
let mut locker = v8::Locker::new(&isolate);
let scope = locker.enter();
{ {
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let context = v8::Context::new(scope); let context = v8::Context::new(scope);
let mut cs = v8::ContextScope::new(scope, context); let mut cs = v8::ContextScope::new(scope, context);
@ -1654,22 +1583,24 @@ fn snapshot_creator() {
// the value 3. // the value 3.
let startup_data = { let startup_data = {
let mut snapshot_creator = v8::SnapshotCreator::new(None); let mut snapshot_creator = v8::SnapshotCreator::new(None);
let isolate = snapshot_creator.get_isolate();
let mut locker = v8::Locker::new(&isolate);
let scope = locker.enter();
{ {
let mut hs = v8::HandleScope::new(scope); // TODO(ry) this shouldn't be necessary. workaround unfinished business in
// the scope type system.
let mut isolate = unsafe { snapshot_creator.get_owned_isolate() };
let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let context = v8::Context::new(scope); let context = v8::Context::new(scope);
let mut cs = v8::ContextScope::new(scope, context); let mut cs = v8::ContextScope::new(scope, context);
let scope = cs.enter(); let scope = cs.enter();
let source = v8::String::new(scope, "a = 1 + 2").unwrap(); let source = v8::String::new(scope, "a = 1 + 2").unwrap();
let mut script = let mut script =
v8::Script::compile(scope, context, source, None).unwrap(); v8::Script::compile(scope, context, source, None).unwrap();
script.run(scope, context).unwrap(); script.run(scope, context).unwrap();
snapshot_creator.set_default_context(context); snapshot_creator.set_default_context(context);
std::mem::forget(isolate); // TODO(ry) this shouldn't be necessary.
} }
snapshot_creator snapshot_creator
@ -1683,11 +1614,9 @@ fn snapshot_creator() {
let mut params = v8::Isolate::create_params(); let mut params = v8::Isolate::create_params();
params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_array_buffer_allocator(v8::new_default_allocator());
params.set_snapshot_blob(&startup_data); params.set_snapshot_blob(&startup_data);
let isolate = v8::Isolate::new(params); let mut isolate = v8::Isolate::new(params);
let mut locker = v8::Locker::new(&isolate);
let scope = locker.enter();
{ {
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let context = v8::Context::new(scope); let context = v8::Context::new(scope);
let mut cs = v8::ContextScope::new(scope, context); let mut cs = v8::ContextScope::new(scope, context);
@ -1720,11 +1649,12 @@ fn external_references() {
let startup_data = { let startup_data = {
let mut snapshot_creator = let mut snapshot_creator =
v8::SnapshotCreator::new(Some(&EXTERNAL_REFERENCES)); v8::SnapshotCreator::new(Some(&EXTERNAL_REFERENCES));
let isolate = snapshot_creator.get_isolate();
let mut locker = v8::Locker::new(&isolate);
let scope = locker.enter();
{ {
let mut hs = v8::HandleScope::new(scope); // TODO(ry) this shouldn't be necessary. workaround unfinished business in
// the scope type system.
let mut isolate = unsafe { snapshot_creator.get_owned_isolate() };
let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let context = v8::Context::new(scope); let context = v8::Context::new(scope);
let mut cs = v8::ContextScope::new(scope, context); let mut cs = v8::ContextScope::new(scope, context);
@ -1740,6 +1670,8 @@ fn external_references() {
global.set(context, v8_str(scope, "F").into(), function.into()); global.set(context, v8_str(scope, "F").into(), function.into());
snapshot_creator.set_default_context(context); snapshot_creator.set_default_context(context);
std::mem::forget(isolate); // TODO(ry) this shouldn't be necessary.
} }
snapshot_creator snapshot_creator
@ -1754,11 +1686,9 @@ fn external_references() {
params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_array_buffer_allocator(v8::new_default_allocator());
params.set_snapshot_blob(&startup_data); params.set_snapshot_blob(&startup_data);
params.set_external_references(&EXTERNAL_REFERENCES); params.set_external_references(&EXTERNAL_REFERENCES);
let isolate = v8::Isolate::new(params); let mut isolate = v8::Isolate::new(params);
let mut locker = v8::Locker::new(&isolate);
let scope = locker.enter();
{ {
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let context = v8::Context::new(scope); let context = v8::Context::new(scope);
let mut cs = v8::ContextScope::new(scope, context); let mut cs = v8::ContextScope::new(scope, context);
@ -1799,11 +1729,9 @@ fn uint8_array() {
let _setup_guard = setup(); let _setup_guard = setup();
let mut params = v8::Isolate::create_params(); let mut params = v8::Isolate::create_params();
params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_array_buffer_allocator(v8::new_default_allocator());
let isolate = v8::Isolate::new(params); let mut isolate = v8::Isolate::new(params);
let mut locker = v8::Locker::new(&isolate);
let scope = locker.enter();
{ {
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let context = v8::Context::new(scope); let context = v8::Context::new(scope);
let mut cs = v8::ContextScope::new(scope, context); let mut cs = v8::ContextScope::new(scope, context);
@ -1853,10 +1781,8 @@ fn dynamic_import() {
} }
isolate.set_host_import_module_dynamically_callback(dynamic_import_cb); isolate.set_host_import_module_dynamically_callback(dynamic_import_cb);
let mut locker = v8::Locker::new(&isolate);
let scope = locker.enter();
{ {
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let context = v8::Context::new(scope); let context = v8::Context::new(scope);
let mut cs = v8::ContextScope::new(scope, context); let mut cs = v8::ContextScope::new(scope, context);
@ -1879,11 +1805,9 @@ fn shared_array_buffer() {
let _setup_guard = setup(); let _setup_guard = setup();
let mut params = v8::Isolate::create_params(); let mut params = v8::Isolate::create_params();
params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_array_buffer_allocator(v8::new_default_allocator());
let isolate = v8::Isolate::new(params); let mut isolate = v8::Isolate::new(params);
let mut locker = v8::Locker::new(&isolate);
let scope = locker.enter();
{ {
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let context = v8::Context::new(scope); let context = v8::Context::new(scope);
let mut cs = v8::ContextScope::new(scope, context); let mut cs = v8::ContextScope::new(scope, context);
@ -1950,11 +1874,9 @@ fn value_checker() {
let _setup_guard = setup(); let _setup_guard = setup();
let mut params = v8::Isolate::create_params(); let mut params = v8::Isolate::create_params();
params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_array_buffer_allocator(v8::new_default_allocator());
let isolate = v8::Isolate::new(params); let mut isolate = v8::Isolate::new(params);
let mut locker = v8::Locker::new(&isolate);
let scope = locker.enter();
{ {
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let context = v8::Context::new(scope); let context = v8::Context::new(scope);
let mut cs = v8::ContextScope::new(scope, context); let mut cs = v8::ContextScope::new(scope, context);
@ -2123,11 +2045,9 @@ fn try_from_local() {
let _setup_guard = setup(); let _setup_guard = setup();
let mut params = v8::Isolate::create_params(); let mut params = v8::Isolate::create_params();
params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_array_buffer_allocator(v8::new_default_allocator());
let isolate = v8::Isolate::new(params); let mut isolate = v8::Isolate::new(params);
let mut locker = v8::Locker::new(&isolate);
let scope = locker.enter();
{ {
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let context = v8::Context::new(scope); let context = v8::Context::new(scope);
let mut cs = v8::ContextScope::new(scope, context); let mut cs = v8::ContextScope::new(scope, context);
@ -2357,19 +2277,17 @@ fn inspector_dispatch_protocol_message() {
let mut params = v8::Isolate::create_params(); let mut params = v8::Isolate::create_params();
params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_array_buffer_allocator(v8::new_default_allocator());
let mut isolate = v8::Isolate::new(params); let mut isolate = v8::Isolate::new(params);
let mut locker = v8::Locker::new(&isolate);
let scope = locker.enter();
use v8::inspector::*; use v8::inspector::*;
let mut default_client = ClientCounter::new();
let mut inspector = V8Inspector::create(&mut isolate, &mut default_client);
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let context = v8::Context::new(scope); let context = v8::Context::new(scope);
let mut cs = v8::ContextScope::new(scope, context); let mut cs = v8::ContextScope::new(scope, context);
let _scope = cs.enter(); let _scope = cs.enter();
let mut default_client = ClientCounter::new();
let mut inspector = V8Inspector::create(&mut isolate, &mut default_client);
let name = b""; let name = b"";
let name_view = StringView::from(&name[..]); let name_view = StringView::from(&name[..]);
inspector.context_created(context, 1, &name_view); inspector.context_created(context, 1, &name_view);
@ -2394,19 +2312,17 @@ fn inspector_schedule_pause_on_next_statement() {
let mut params = v8::Isolate::create_params(); let mut params = v8::Isolate::create_params();
params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_array_buffer_allocator(v8::new_default_allocator());
let mut isolate = v8::Isolate::new(params); let mut isolate = v8::Isolate::new(params);
let mut locker = v8::Locker::new(&isolate);
let scope = locker.enter();
use v8::inspector::*; use v8::inspector::*;
let mut client = ClientCounter::new();
let mut inspector = V8Inspector::create(&mut isolate, &mut client);
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let context = v8::Context::new(scope); let context = v8::Context::new(scope);
let mut cs = v8::ContextScope::new(scope, context); let mut cs = v8::ContextScope::new(scope, context);
let scope = cs.enter(); let scope = cs.enter();
let mut client = ClientCounter::new();
let mut inspector = V8Inspector::create(&mut isolate, &mut client);
let mut channel = ChannelCounter::new(); let mut channel = ChannelCounter::new();
let state = b"{}"; let state = b"{}";
let state_view = StringView::from(&state[..]); let state_view = StringView::from(&state[..]);
@ -2460,8 +2376,6 @@ fn inspector_console_api_message() {
let mut params = v8::Isolate::create_params(); let mut params = v8::Isolate::create_params();
params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_array_buffer_allocator(v8::new_default_allocator());
let mut isolate = v8::Isolate::new(params); let mut isolate = v8::Isolate::new(params);
let mut locker = v8::Locker::new(&isolate);
let scope = locker.enter();
use v8::inspector::*; use v8::inspector::*;
@ -2502,14 +2416,15 @@ fn inspector_console_api_message() {
} }
} }
let mut hs = v8::HandleScope::new(scope); let mut client = Client::new();
let mut inspector = V8Inspector::create(&mut isolate, &mut client);
let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let context = v8::Context::new(scope); let context = v8::Context::new(scope);
let mut cs = v8::ContextScope::new(scope, context); let mut cs = v8::ContextScope::new(scope, context);
let scope = cs.enter(); let scope = cs.enter();
let mut client = Client::new();
let mut inspector = V8Inspector::create(&mut isolate, &mut client);
let name = b""; let name = b"";
let name_view = StringView::from(&name[..]); let name_view = StringView::from(&name[..]);
inspector.context_created(context, 1, &name_view); inspector.context_created(context, 1, &name_view);
@ -2528,11 +2443,9 @@ fn context_from_object_template() {
let _setup_guard = setup(); let _setup_guard = setup();
let mut params = v8::Isolate::create_params(); let mut params = v8::Isolate::create_params();
params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_array_buffer_allocator(v8::new_default_allocator());
let isolate = v8::Isolate::new(params); let mut isolate = v8::Isolate::new(params);
let mut locker = v8::Locker::new(&isolate);
let scope = locker.enter();
{ {
let mut hs = v8::HandleScope::new(scope); let mut hs = v8::HandleScope::new(&mut isolate);
let scope = hs.enter(); let scope = hs.enter();
let object_templ = v8::ObjectTemplate::new(scope); let object_templ = v8::ObjectTemplate::new(scope);
let function_templ = v8::FunctionTemplate::new(scope, fortytwo_callback); let function_templ = v8::FunctionTemplate::new(scope, fortytwo_callback);