diff --git a/src/inspector/v8_inspector.rs b/src/inspector/v8_inspector.rs index 05718373..88cdb7f7 100644 --- a/src/inspector/v8_inspector.rs +++ b/src/inspector/v8_inspector.rs @@ -4,6 +4,7 @@ use super::session::V8InspectorSession; use super::Channel; use super::StringView; use super::V8InspectorClient; +use crate::scope_traits::InIsolate; use crate::support::int; use crate::support::Delete; use crate::support::Opaque; @@ -37,7 +38,7 @@ pub struct V8Inspector(Opaque); impl V8Inspector { pub fn create( - isolate: &mut Isolate, + isolate: &mut impl InIsolate, client: &mut T, ) -> UniqueRef where @@ -45,7 +46,7 @@ impl V8Inspector { { unsafe { UniqueRef::from_raw(v8_inspector__V8Inspector__create( - isolate, + isolate.isolate(), client.as_client_mut(), )) } diff --git a/src/isolate.rs b/src/isolate.rs index 9ade32b6..0bf0bab2 100644 --- a/src/isolate.rs +++ b/src/isolate.rs @@ -8,6 +8,7 @@ use crate::support::Opaque; use crate::support::UniqueRef; use crate::Context; use crate::Function; +use crate::InIsolate; use crate::Local; use crate::Message; 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. pub struct OwnedIsolate(NonNull); +impl InIsolate for OwnedIsolate { + fn isolate(&mut self) -> &mut Isolate { + self.deref_mut() + } +} + impl Drop for OwnedIsolate { fn drop(&mut self) { unsafe { self.0.as_mut().dispose() } diff --git a/src/lib.rs b/src/lib.rs index 32dc76de..5bcb51fc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,12 +11,9 @@ //! //! let mut create_params = v8::Isolate::create_params(); //! 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 scope = locker.enter(); -//! -//! let mut handle_scope = v8::HandleScope::new(scope); +//! let mut handle_scope = v8::HandleScope::new(&mut isolate); //! let scope = handle_scope.enter(); //! //! let context = v8::Context::new(scope); @@ -154,7 +151,6 @@ pub use property_attribute::*; pub use scope::CallbackScope; pub use scope::ContextScope; pub use scope::FunctionCallbackScope; -pub use scope::Locker; pub use scope::PropertyCallbackScope; pub use scope::Scope; pub use scope_traits::*; diff --git a/src/scope.rs b/src/scope.rs index 38b6e5d1..a0feb622 100644 --- a/src/scope.rs +++ b/src/scope.rs @@ -246,49 +246,6 @@ impl<'s, X> From<&'s PromiseRejectMessage<'s>> for Scope<'s, CallbackScope> { } } -#[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 /// executed within a local scope. pub struct ContextScope { diff --git a/src/scope_traits.rs b/src/scope_traits.rs index 49171b49..e753f68b 100644 --- a/src/scope_traits.rs +++ b/src/scope_traits.rs @@ -10,7 +10,6 @@ use crate::FunctionCallbackInfo; use crate::HandleScope; use crate::Isolate; use crate::Local; -use crate::Locker; use crate::Message; use crate::Object; 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 { fn get_raw_isolate(&self) -> *mut Isolate { unsafe { v8__Context__GetIsolate(self) } diff --git a/src/script_compiler.rs b/src/script_compiler.rs index 1351d5a7..4aea1624 100644 --- a/src/script_compiler.rs +++ b/src/script_compiler.rs @@ -1,5 +1,6 @@ // Copyright 2019-2020 the Deno authors. All rights reserved. MIT license. //! For compiling scripts. +use crate::InIsolate; use crate::Isolate; use crate::Local; use crate::Module; @@ -77,11 +78,11 @@ pub enum NoCacheReason { /// Corresponds to the ParseModule abstract operation in the ECMAScript /// specification. pub fn compile_module<'a>( - isolate: &Isolate, + scope: &mut impl InIsolate, source: Source, ) -> Option> { compile_module2( - isolate, + scope, source, CompileOptions::NoCompileOptions, NoCacheReason::NoReason, @@ -90,14 +91,14 @@ pub fn compile_module<'a>( /// Same as compile_module with more options. pub fn compile_module2<'a>( - isolate: &Isolate, + scope: &mut impl InIsolate, source: Source, options: CompileOptions, no_cache_reason: NoCacheReason, ) -> Option> { unsafe { Local::from_raw(v8__ScriptCompiler__CompileModule( - isolate, + scope.isolate(), &source, options, no_cache_reason, diff --git a/src/snapshot.rs b/src/snapshot.rs index f9b1972d..018c32cd 100644 --- a/src/snapshot.rs +++ b/src/snapshot.rs @@ -17,9 +17,7 @@ extern "C" { external_references: *const intptr_t, ); fn v8__SnapshotCreator__DESTRUCT(this: &mut SnapshotCreator); - fn v8__SnapshotCreator__GetIsolate( - this: &mut SnapshotCreator, - ) -> &mut Isolate; + fn v8__SnapshotCreator__GetIsolate(this: &SnapshotCreator) -> &mut Isolate; fn v8__SnapshotCreator__CreateBlob( this: *mut SnapshotCreator, function_code_handling: FunctionCodeHandling, @@ -151,9 +149,4 @@ impl SnapshotCreator { let isolate_ptr = v8__SnapshotCreator__GetIsolate(self); 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) } - } } diff --git a/tests/compile_fail/handle_scope_escape_lifetime.rs b/tests/compile_fail/handle_scope_escape_lifetime.rs index c0f4ca87..b18591f1 100644 --- a/tests/compile_fail/handle_scope_escape_lifetime.rs +++ b/tests/compile_fail/handle_scope_escape_lifetime.rs @@ -2,8 +2,8 @@ use rusty_v8 as v8; pub fn main() { - let mut locker = v8::Locker::new(mock()); - let mut hs0 = v8::HandleScope::new(locker.enter()); + let mut isolate = v8::Isolate::new(mock()); + let mut hs0 = v8::HandleScope::new(&mut isolate); let hs0 = hs0.enter(); let _fail = { diff --git a/tests/compile_fail/handle_scope_lifetimes.rs b/tests/compile_fail/handle_scope_lifetimes.rs index b4d51d73..c2ab0500 100644 --- a/tests/compile_fail/handle_scope_lifetimes.rs +++ b/tests/compile_fail/handle_scope_lifetimes.rs @@ -2,8 +2,8 @@ use rusty_v8 as v8; pub fn main() { - let mut locker = v8::Locker::new(mock()); - let mut root_hs = v8::HandleScope::new(locker.enter()); + let mut isolate = v8::Isolate::new(mock()); + let mut root_hs = v8::HandleScope::new(&mut isolate); let root_hs = root_hs.enter(); { diff --git a/tests/compile_fail/try_catch_lifetimes.rs b/tests/compile_fail/try_catch_lifetimes.rs index 7cb8a68e..7221df93 100644 --- a/tests/compile_fail/try_catch_lifetimes.rs +++ b/tests/compile_fail/try_catch_lifetimes.rs @@ -2,7 +2,7 @@ use rusty_v8 as v8; pub fn main() { - let mut scope: v8::Scope = mock(); + let mut scope: v8::Scope = mock(); let scope = scope.enter(); let context: v8::Local = mock(); diff --git a/tests/test_api.rs b/tests/test_api.rs index 2d3094a3..acbbbd7d 100644 --- a/tests/test_api.rs +++ b/tests/test_api.rs @@ -39,11 +39,9 @@ fn handle_scope_nested() { let _setup_guard = setup(); let mut params = v8::Isolate::create_params(); params.set_array_buffer_allocator(v8::new_default_allocator()); - let isolate = v8::Isolate::new(params); - let mut locker = v8::Locker::new(&isolate); - let scope0 = locker.enter(); + let mut isolate = v8::Isolate::new(params); { - let mut hs = v8::HandleScope::new(scope0); + let mut hs = v8::HandleScope::new(&mut isolate); let scope1 = hs.enter(); { let mut hs = v8::HandleScope::new(scope1); @@ -58,11 +56,9 @@ fn handle_scope_numbers() { let _setup_guard = setup(); let mut params = v8::Isolate::create_params(); params.set_array_buffer_allocator(v8::new_default_allocator()); - let isolate = v8::Isolate::new(params); - let mut locker = v8::Locker::new(&isolate); - let scope0 = locker.enter(); + let mut isolate = v8::Isolate::new(params); { - let mut hs = v8::HandleScope::new(scope0); + let mut hs = v8::HandleScope::new(&mut isolate); let scope1 = hs.enter(); let l1 = v8::Integer::new(scope1, -123); let l2 = v8::Integer::new_from_unsigned(scope1, 456); @@ -84,9 +80,7 @@ fn global_handles() { let _setup_guard = setup(); let mut params = v8::Isolate::create_params(); params.set_array_buffer_allocator(v8::new_default_allocator()); - let isolate = v8::Isolate::new(params); - let mut locker = v8::Locker::new(&isolate); - let scope = locker.enter(); + let mut isolate = v8::Isolate::new(params); let mut g1 = v8::Global::::new(); let mut g2 = v8::Global::::new(); let mut g3 = v8::Global::::new(); @@ -94,7 +88,7 @@ fn global_handles() { let g5 = v8::Global::::new(); let mut g6 = v8::Global::::new(); { - let mut hs = v8::HandleScope::new(scope); + let mut hs = v8::HandleScope::new(&mut isolate); let scope = hs.enter(); let l1 = v8::String::new(scope, "bla").unwrap(); let l2 = v8::Integer::new(scope, 123); @@ -106,7 +100,7 @@ fn global_handles() { g6.set(scope, l6); } { - let mut hs = v8::HandleScope::new(scope); + let mut hs = v8::HandleScope::new(&mut isolate); let scope = hs.enter(); assert!(!g1.is_empty()); assert_eq!(g1.get(scope).unwrap().to_rust_string_lossy(scope), "bla"); @@ -121,13 +115,13 @@ fn global_handles() { g6.reset(scope); assert_eq!(num.value(), 100); } - g1.reset(scope); + g1.reset(&mut isolate); assert!(g1.is_empty()); - g2.reset(scope); + g2.reset(&mut isolate); assert!(g2.is_empty()); - g3.reset(scope); + g3.reset(&mut isolate); assert!(g3.is_empty()); - _g4.reset(scope); + _g4.reset(&mut isolate); assert!(_g4.is_empty()); assert!(g5.is_empty()); } @@ -137,11 +131,9 @@ fn test_string() { let _setup_guard = setup(); let mut params = v8::Isolate::create_params(); params.set_array_buffer_allocator(v8::new_default_allocator()); - let isolate = v8::Isolate::new(params); - let mut locker = v8::Locker::new(&isolate); - let scope = locker.enter(); + let mut isolate = v8::Isolate::new(params); { - let mut hs = v8::HandleScope::new(scope); + let mut hs = v8::HandleScope::new(&mut isolate); let scope = hs.enter(); let reference = "Hello 🦕 world!"; let local = v8::String::new(scope, reference).unwrap(); @@ -150,7 +142,7 @@ fn test_string() { 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 local = v8::String::empty(scope); assert_eq!(0, local.length()); @@ -158,7 +150,7 @@ fn test_string() { 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 local = v8::String::new_from_utf8(scope, b"", v8::NewStringType::Normal).unwrap(); @@ -174,11 +166,9 @@ fn escapable_handle_scope() { let _setup_guard = setup(); let mut params = v8::Isolate::create_params(); params.set_array_buffer_allocator(v8::new_default_allocator()); - let isolate = v8::Isolate::new(params); - let mut locker = v8::Locker::new(&isolate); - let scope0 = locker.enter(); + let mut isolate = v8::Isolate::new(params); { - let mut hs = v8::HandleScope::new(scope0); + let mut hs = v8::HandleScope::new(&mut isolate); let scope1 = hs.enter(); // After dropping EscapableHandleScope, we should be able to // read escaped values. @@ -219,14 +209,12 @@ fn microtasks() { let _setup_guard = setup(); let mut params = v8::Isolate::create_params(); params.set_array_buffer_allocator(v8::new_default_allocator()); - let isolate = v8::Isolate::new(params); - let mut locker = v8::Locker::new(&isolate); - let scope = locker.enter(); + let mut isolate = v8::Isolate::new(params); - 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 context = v8::Context::new(scope); let mut cs = v8::ContextScope::new(scope, context); @@ -256,11 +244,9 @@ fn array_buffer() { let _setup_guard = setup(); let mut params = v8::Isolate::create_params(); params.set_array_buffer_allocator(v8::new_default_allocator()); - let isolate = v8::Isolate::new(params); - let mut locker = v8::Locker::new(&isolate); - let scope = locker.enter(); + let mut isolate = v8::Isolate::new(params); { - let mut hs = v8::HandleScope::new(scope); + let mut hs = v8::HandleScope::new(&mut isolate); let scope = hs.enter(); let context = v8::Context::new(scope); let mut cs = v8::ContextScope::new(scope, context); @@ -305,11 +291,9 @@ fn array_buffer_with_shared_backing_store() { let _setup_guard = setup(); let mut params = v8::Isolate::create_params(); params.set_array_buffer_allocator(v8::new_default_allocator()); - let isolate = v8::Isolate::new(params); - let mut locker = v8::Locker::new(&isolate); - let scope = locker.enter(); + let mut isolate = v8::Isolate::new(params); { - let mut hs = v8::HandleScope::new(scope); + let mut hs = v8::HandleScope::new(&mut isolate); let scope = hs.enter(); let context = v8::Context::new(scope); @@ -389,11 +373,9 @@ fn try_catch() { let _setup_guard = setup(); let mut params = v8::Isolate::create_params(); params.set_array_buffer_allocator(v8::new_default_allocator()); - let isolate = v8::Isolate::new(params); - let mut locker = v8::Locker::new(&isolate); - let scope = locker.enter(); + let mut isolate = v8::Isolate::new(params); { - let mut hs = v8::HandleScope::new(scope); + let mut hs = v8::HandleScope::new(&mut isolate); let scope = hs.enter(); let context = v8::Context::new(scope); let mut cs = v8::ContextScope::new(scope, context); @@ -448,11 +430,9 @@ fn throw_exception() { let _setup_guard = setup(); let mut params = v8::Isolate::create_params(); params.set_array_buffer_allocator(v8::new_default_allocator()); - let isolate = v8::Isolate::new(params); - let mut locker = v8::Locker::new(&isolate); - let scope = locker.enter(); + let mut isolate = v8::Isolate::new(params); { - let mut hs = v8::HandleScope::new(scope); + let mut hs = v8::HandleScope::new(&mut isolate); let scope = hs.enter(); let context = v8::Context::new(scope); let mut cs = v8::ContextScope::new(scope, context); @@ -476,12 +456,10 @@ fn terminate_execution() { let _setup_guard = setup(); let mut params = v8::Isolate::create_params(); params.set_array_buffer_allocator(v8::new_default_allocator()); - let isolate = v8::Isolate::new(params); - let mut locker = v8::Locker::new(&isolate); - let scope = locker.enter(); + let mut isolate = v8::Isolate::new(params); // Originally run fine. { - let mut hs = v8::HandleScope::new(scope); + let mut hs = v8::HandleScope::new(&mut isolate); let scope = hs.enter(); let context = v8::Context::new(scope); let mut cs = v8::ContextScope::new(scope, context); @@ -494,7 +472,7 @@ fn terminate_execution() { isolate.terminate_execution(); // 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 context = v8::Context::new(scope); let mut cs = v8::ContextScope::new(scope, context); @@ -509,7 +487,7 @@ fn terminate_execution() { isolate.cancel_terminate_execution(); // Works again. { - let mut hs = v8::HandleScope::new(scope); + let mut hs = v8::HandleScope::new(&mut isolate); let scope = hs.enter(); let context = v8::Context::new(scope); let mut cs = v8::ContextScope::new(scope, context); @@ -525,11 +503,9 @@ fn request_interrupt_small_scripts() { let _setup_guard = setup(); let mut params = v8::Isolate::create_params(); params.set_array_buffer_allocator(v8::new_default_allocator()); - let isolate = v8::Isolate::new(params); - let mut locker = v8::Locker::new(&isolate); - let scope = locker.enter(); + let mut isolate = v8::Isolate::new(params); { - let mut hs = v8::HandleScope::new(scope); + let mut hs = v8::HandleScope::new(&mut isolate); let scope = hs.enter(); let context = v8::Context::new(scope); let mut cs = v8::ContextScope::new(scope, context); @@ -543,7 +519,9 @@ fn request_interrupt_small_scripts() { assert_eq!(data, std::ptr::null_mut()); 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);"); assert_eq!(CALL_COUNT.load(Ordering::SeqCst), 1); } @@ -597,10 +575,8 @@ fn add_message_listener() { } 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 context = v8::Context::new(scope); 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); - 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 context = v8::Context::new(scope); let mut cs = v8::ContextScope::new(scope, context); let scope = cs.enter(); let source = mock_source(scope, "google.com", "import.meta;"); let mut module = - v8::script_compiler::compile_module(&isolate, source).unwrap(); + v8::script_compiler::compile_module(scope, source).unwrap(); let result = module.instantiate_module(context, unexpected_module_resolve_callback); assert!(result.is_some()); @@ -674,11 +648,9 @@ fn script_compile_and_run() { let _setup_guard = setup(); let mut params = v8::Isolate::create_params(); params.set_array_buffer_allocator(v8::new_default_allocator()); - let isolate = v8::Isolate::new(params); - let mut locker = v8::Locker::new(&isolate); - let scope = locker.enter(); + let mut isolate = v8::Isolate::new(params); { - let mut hs = v8::HandleScope::new(scope); + let mut hs = v8::HandleScope::new(&mut isolate); let scope = hs.enter(); let context = v8::Context::new(scope); let mut cs = v8::ContextScope::new(scope, context); @@ -697,12 +669,10 @@ fn script_origin() { let _setup_guard = setup(); let mut params = v8::Isolate::create_params(); params.set_array_buffer_allocator(v8::new_default_allocator()); - let isolate = v8::Isolate::new(params); - let mut locker = v8::Locker::new(&isolate); - let scope = locker.enter(); + let mut isolate = v8::Isolate::new(params); { - let mut hs = v8::HandleScope::new(scope); + let mut hs = v8::HandleScope::new(&mut isolate); let scope = hs.enter(); let context = v8::Context::new(scope); let mut cs = v8::ContextScope::new(scope, context); @@ -790,11 +760,9 @@ fn test_primitives() { let _setup_guard = setup(); let mut params = v8::Isolate::create_params(); params.set_array_buffer_allocator(v8::new_default_allocator()); - let isolate = v8::Isolate::new(params); - let mut locker = v8::Locker::new(&isolate); - let scope = locker.enter(); + let mut isolate = v8::Isolate::new(params); { - let mut hs = v8::HandleScope::new(scope); + let mut hs = v8::HandleScope::new(&mut isolate); let scope = hs.enter(); let null = v8::null(scope); assert!(!null.is_undefined()); @@ -825,10 +793,8 @@ fn exception() { let _setup_guard = setup(); let mut params = v8::Isolate::create_params(); params.set_array_buffer_allocator(v8::new_default_allocator()); - let 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 isolate = v8::Isolate::new(params); + let mut hs = v8::HandleScope::new(&mut isolate); let scope = hs.enter(); let context = v8::Context::new(scope); let mut cs = v8::ContextScope::new(scope, context); @@ -854,10 +820,8 @@ fn create_message_argument_lifetimes() { let _setup_guard = setup(); let mut params = v8::Isolate::create_params(); params.set_array_buffer_allocator(v8::new_default_allocator()); - let 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 isolate = v8::Isolate::new(params); + let mut hs = v8::HandleScope::new(&mut isolate); let scope = hs.enter(); let context = v8::Context::new(scope); let mut cs = v8::ContextScope::new(scope, context); @@ -893,11 +857,9 @@ fn json() { let _setup_guard = setup(); let mut params = v8::Isolate::create_params(); params.set_array_buffer_allocator(v8::new_default_allocator()); - let isolate = v8::Isolate::new(params); - let mut locker = v8::Locker::new(&isolate); - let scope = locker.enter(); + let mut isolate = v8::Isolate::new(params); { - let mut hs = v8::HandleScope::new(scope); + let mut hs = v8::HandleScope::new(&mut isolate); let scope = hs.enter(); let context = v8::Context::new(scope); let mut cs = v8::ContextScope::new(scope, context); @@ -919,11 +881,9 @@ fn object_template() { let _setup_guard = setup(); let mut params = v8::Isolate::create_params(); params.set_array_buffer_allocator(v8::new_default_allocator()); - let isolate = v8::Isolate::new(params); - let mut locker = v8::Locker::new(&isolate); - let scope = locker.enter(); + let mut isolate = v8::Isolate::new(params); { - let mut hs = v8::HandleScope::new(scope); + let mut hs = v8::HandleScope::new(&mut isolate); let scope = hs.enter(); let object_templ = v8::ObjectTemplate::new(scope); let function_templ = v8::FunctionTemplate::new(scope, fortytwo_callback); @@ -971,11 +931,9 @@ fn object_template_from_function_template() { let _setup_guard = setup(); let mut params = v8::Isolate::create_params(); params.set_array_buffer_allocator(v8::new_default_allocator()); - let isolate = v8::Isolate::new(params); - let mut locker = v8::Locker::new(&isolate); - let scope = locker.enter(); + let mut isolate = v8::Isolate::new(params); { - let mut hs = v8::HandleScope::new(scope); + let mut hs = v8::HandleScope::new(&mut isolate); let scope = hs.enter(); let mut function_templ = v8::FunctionTemplate::new(scope, fortytwo_callback); @@ -1002,11 +960,9 @@ fn object() { let _setup_guard = setup(); let mut params = v8::Isolate::create_params(); params.set_array_buffer_allocator(v8::new_default_allocator()); - let isolate = v8::Isolate::new(params); - let mut locker = v8::Locker::new(&isolate); - let scope = locker.enter(); + let mut isolate = v8::Isolate::new(params); { - let mut hs = v8::HandleScope::new(scope); + let mut hs = v8::HandleScope::new(&mut isolate); let scope = hs.enter(); let context = v8::Context::new(scope); let mut cs = v8::ContextScope::new(scope, context); @@ -1039,11 +995,9 @@ fn array() { let _setup_guard = setup(); let mut params = v8::Isolate::create_params(); params.set_array_buffer_allocator(v8::new_default_allocator()); - let isolate = v8::Isolate::new(params); - let mut locker = v8::Locker::new(&isolate); - let scope = locker.enter(); + let mut isolate = v8::Isolate::new(params); { - let mut hs = v8::HandleScope::new(scope); + let mut hs = v8::HandleScope::new(&mut isolate); let scope = hs.enter(); let context = v8::Context::new(scope); let mut cs = v8::ContextScope::new(scope, context); @@ -1073,11 +1027,9 @@ fn create_data_property() { let _setup_guard = setup(); let mut params = v8::Isolate::create_params(); params.set_array_buffer_allocator(v8::new_default_allocator()); - let isolate = v8::Isolate::new(params); - let mut locker = v8::Locker::new(&isolate); - let scope = locker.enter(); + let mut isolate = v8::Isolate::new(params); { - let mut hs = v8::HandleScope::new(scope); + let mut hs = v8::HandleScope::new(&mut isolate); let scope = hs.enter(); let context = v8::Context::new(scope); let mut cs = v8::ContextScope::new(scope, context); @@ -1112,10 +1064,8 @@ fn object_set_accessor() { let _setup_guard = setup(); let mut params = v8::Isolate::create_params(); params.set_array_buffer_allocator(v8::new_default_allocator()); - let 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 isolate = v8::Isolate::new(params); + let mut hs = v8::HandleScope::new(&mut isolate); let scope = hs.enter(); let context = v8::Context::new(scope); let mut cs = v8::ContextScope::new(scope, context); @@ -1172,11 +1122,9 @@ fn promise_resolved() { let _setup_guard = setup(); let mut params = v8::Isolate::create_params(); params.set_array_buffer_allocator(v8::new_default_allocator()); - let isolate = v8::Isolate::new(params); - let mut locker = v8::Locker::new(&isolate); - let scope = locker.enter(); + let mut isolate = v8::Isolate::new(params); { - let mut hs = v8::HandleScope::new(scope); + let mut hs = v8::HandleScope::new(&mut isolate); let scope = hs.enter(); let context = v8::Context::new(scope); let mut cs = v8::ContextScope::new(scope, context); @@ -1208,11 +1156,9 @@ fn promise_rejected() { let _setup_guard = setup(); let mut params = v8::Isolate::create_params(); params.set_array_buffer_allocator(v8::new_default_allocator()); - let isolate = v8::Isolate::new(params); - let mut locker = v8::Locker::new(&isolate); - let scope = locker.enter(); + let mut isolate = v8::Isolate::new(params); { - let mut hs = v8::HandleScope::new(scope); + let mut hs = v8::HandleScope::new(&mut isolate); let scope = hs.enter(); let context = v8::Context::new(scope); let mut cs = v8::ContextScope::new(scope, context); @@ -1285,12 +1231,10 @@ fn function() { let _setup_guard = setup(); let mut params = v8::Isolate::create_params(); params.set_array_buffer_allocator(v8::new_default_allocator()); - let isolate = v8::Isolate::new(params); - let mut locker = v8::Locker::new(&isolate); - let scope = locker.enter(); + let mut isolate = v8::Isolate::new(params); { - let mut hs = v8::HandleScope::new(scope); + let mut hs = v8::HandleScope::new(&mut isolate); let scope = hs.enter(); let context = v8::Context::new(scope); 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()); let mut isolate = v8::Isolate::new(params); 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 context = v8::Context::new(scope); 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()); let mut isolate = v8::Isolate::new(params); 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 context = v8::Context::new(scope); let mut cs = v8::ContextScope::new(scope, context); @@ -1417,7 +1357,7 @@ fn script_compiler_source() { let source = 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()); } } @@ -1427,11 +1367,9 @@ fn module_instantiation_failures1() { let _setup_guard = setup(); let mut params = v8::Isolate::create_params(); params.set_array_buffer_allocator(v8::new_default_allocator()); - let isolate = v8::Isolate::new(params); - let mut locker = v8::Locker::new(&isolate); - let scope = locker.enter(); + let mut isolate = v8::Isolate::new(params); { - let mut hs = v8::HandleScope::new(scope); + let mut hs = v8::HandleScope::new(&mut isolate); let scope = hs.enter(); let context = v8::Context::new(scope); 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 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!(2, module.get_module_requests_length()); @@ -1504,8 +1442,7 @@ fn compile_specifier_as_module_resolve_callback<'a>( let scope = hs.enter(); let origin = mock_script_origin(scope, "module.js"); let source = v8::script_compiler::Source::new(specifier, &origin); - let module = - v8::script_compiler::compile_module(scope.isolate(), source).unwrap(); + let module = v8::script_compiler::compile_module(scope, source).unwrap(); Some(scope.escape(module)) } @@ -1514,11 +1451,9 @@ fn module_evaluation() { let _setup_guard = setup(); let mut params = v8::Isolate::create_params(); params.set_array_buffer_allocator(v8::new_default_allocator()); - let isolate = v8::Isolate::new(params); - let mut locker = v8::Locker::new(&isolate); - let scope = locker.enter(); + let mut isolate = v8::Isolate::new(params); { - let mut hs = v8::HandleScope::new(scope); + let mut hs = v8::HandleScope::new(&mut isolate); let scope = hs.enter(); let context = v8::Context::new(scope); 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 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()); let result = module.instantiate_module( @@ -1559,11 +1494,9 @@ fn primitive_array() { let _setup_guard = setup(); let mut params = v8::Isolate::create_params(); params.set_array_buffer_allocator(v8::new_default_allocator()); - let isolate = v8::Isolate::new(params); - let mut locker = v8::Locker::new(&isolate); - let scope = locker.enter(); + let mut isolate = v8::Isolate::new(params); { - let mut hs = v8::HandleScope::new(scope); + let mut hs = v8::HandleScope::new(&mut isolate); let scope = hs.enter(); let context = v8::Context::new(scope); let mut cs = v8::ContextScope::new(scope, context); @@ -1596,11 +1529,9 @@ fn equality() { let _setup_guard = setup(); let mut params = v8::Isolate::create_params(); params.set_array_buffer_allocator(v8::new_default_allocator()); - let isolate = v8::Isolate::new(params); - let mut locker = v8::Locker::new(&isolate); - let scope = locker.enter(); + let mut isolate = v8::Isolate::new(params); { - let mut hs = v8::HandleScope::new(scope); + let mut hs = v8::HandleScope::new(&mut isolate); let scope = hs.enter(); let context = v8::Context::new(scope); let mut cs = v8::ContextScope::new(scope, context); @@ -1619,11 +1550,9 @@ fn array_buffer_view() { let _setup_guard = setup(); let mut params = v8::Isolate::create_params(); params.set_array_buffer_allocator(v8::new_default_allocator()); - let isolate = v8::Isolate::new(params); - let mut locker = v8::Locker::new(&isolate); - let scope = locker.enter(); + let mut isolate = v8::Isolate::new(params); { - let mut hs = v8::HandleScope::new(scope); + let mut hs = v8::HandleScope::new(&mut isolate); let scope = hs.enter(); let context = v8::Context::new(scope); let mut cs = v8::ContextScope::new(scope, context); @@ -1654,22 +1583,24 @@ fn snapshot_creator() { // the value 3. let startup_data = { 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 context = v8::Context::new(scope); let mut cs = v8::ContextScope::new(scope, context); let scope = cs.enter(); - let source = v8::String::new(scope, "a = 1 + 2").unwrap(); let mut script = v8::Script::compile(scope, context, source, None).unwrap(); script.run(scope, context).unwrap(); snapshot_creator.set_default_context(context); + std::mem::forget(isolate); // TODO(ry) this shouldn't be necessary. } snapshot_creator @@ -1683,11 +1614,9 @@ fn snapshot_creator() { let mut params = v8::Isolate::create_params(); params.set_array_buffer_allocator(v8::new_default_allocator()); params.set_snapshot_blob(&startup_data); - let isolate = v8::Isolate::new(params); - let mut locker = v8::Locker::new(&isolate); - let scope = locker.enter(); + let mut isolate = v8::Isolate::new(params); { - let mut hs = v8::HandleScope::new(scope); + let mut hs = v8::HandleScope::new(&mut isolate); let scope = hs.enter(); let context = v8::Context::new(scope); let mut cs = v8::ContextScope::new(scope, context); @@ -1720,11 +1649,12 @@ fn external_references() { let startup_data = { let mut snapshot_creator = 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 context = v8::Context::new(scope); 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()); snapshot_creator.set_default_context(context); + + std::mem::forget(isolate); // TODO(ry) this shouldn't be necessary. } snapshot_creator @@ -1754,11 +1686,9 @@ fn external_references() { params.set_array_buffer_allocator(v8::new_default_allocator()); 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); - let scope = locker.enter(); + let mut isolate = v8::Isolate::new(params); { - let mut hs = v8::HandleScope::new(scope); + let mut hs = v8::HandleScope::new(&mut isolate); let scope = hs.enter(); let context = v8::Context::new(scope); let mut cs = v8::ContextScope::new(scope, context); @@ -1799,11 +1729,9 @@ fn uint8_array() { let _setup_guard = setup(); let mut params = v8::Isolate::create_params(); params.set_array_buffer_allocator(v8::new_default_allocator()); - let isolate = v8::Isolate::new(params); - let mut locker = v8::Locker::new(&isolate); - let scope = locker.enter(); + let mut isolate = v8::Isolate::new(params); { - let mut hs = v8::HandleScope::new(scope); + let mut hs = v8::HandleScope::new(&mut isolate); let scope = hs.enter(); let context = v8::Context::new(scope); 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); - 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 context = v8::Context::new(scope); let mut cs = v8::ContextScope::new(scope, context); @@ -1879,11 +1805,9 @@ fn shared_array_buffer() { let _setup_guard = setup(); let mut params = v8::Isolate::create_params(); params.set_array_buffer_allocator(v8::new_default_allocator()); - let isolate = v8::Isolate::new(params); - let mut locker = v8::Locker::new(&isolate); - let scope = locker.enter(); + let mut isolate = v8::Isolate::new(params); { - let mut hs = v8::HandleScope::new(scope); + let mut hs = v8::HandleScope::new(&mut isolate); let scope = hs.enter(); let context = v8::Context::new(scope); let mut cs = v8::ContextScope::new(scope, context); @@ -1950,11 +1874,9 @@ fn value_checker() { let _setup_guard = setup(); let mut params = v8::Isolate::create_params(); params.set_array_buffer_allocator(v8::new_default_allocator()); - let isolate = v8::Isolate::new(params); - let mut locker = v8::Locker::new(&isolate); - let scope = locker.enter(); + let mut isolate = v8::Isolate::new(params); { - let mut hs = v8::HandleScope::new(scope); + let mut hs = v8::HandleScope::new(&mut isolate); let scope = hs.enter(); let context = v8::Context::new(scope); let mut cs = v8::ContextScope::new(scope, context); @@ -2123,11 +2045,9 @@ fn try_from_local() { let _setup_guard = setup(); let mut params = v8::Isolate::create_params(); params.set_array_buffer_allocator(v8::new_default_allocator()); - let isolate = v8::Isolate::new(params); - let mut locker = v8::Locker::new(&isolate); - let scope = locker.enter(); + let mut isolate = v8::Isolate::new(params); { - let mut hs = v8::HandleScope::new(scope); + let mut hs = v8::HandleScope::new(&mut isolate); let scope = hs.enter(); let context = v8::Context::new(scope); let mut cs = v8::ContextScope::new(scope, context); @@ -2357,19 +2277,17 @@ fn inspector_dispatch_protocol_message() { let mut params = v8::Isolate::create_params(); params.set_array_buffer_allocator(v8::new_default_allocator()); let mut isolate = v8::Isolate::new(params); - let mut locker = v8::Locker::new(&isolate); - let scope = locker.enter(); 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 context = v8::Context::new(scope); let mut cs = v8::ContextScope::new(scope, context); 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_view = StringView::from(&name[..]); 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(); params.set_array_buffer_allocator(v8::new_default_allocator()); let mut isolate = v8::Isolate::new(params); - let mut locker = v8::Locker::new(&isolate); - let scope = locker.enter(); 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 context = v8::Context::new(scope); let mut cs = v8::ContextScope::new(scope, context); let scope = cs.enter(); - let mut client = ClientCounter::new(); - let mut inspector = V8Inspector::create(&mut isolate, &mut client); let mut channel = ChannelCounter::new(); let state = b"{}"; let state_view = StringView::from(&state[..]); @@ -2460,8 +2376,6 @@ fn inspector_console_api_message() { let mut params = v8::Isolate::create_params(); params.set_array_buffer_allocator(v8::new_default_allocator()); let mut isolate = v8::Isolate::new(params); - let mut locker = v8::Locker::new(&isolate); - let scope = locker.enter(); 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 context = v8::Context::new(scope); let mut cs = v8::ContextScope::new(scope, context); let scope = cs.enter(); - let mut client = Client::new(); - let mut inspector = V8Inspector::create(&mut isolate, &mut client); let name = b""; let name_view = StringView::from(&name[..]); inspector.context_created(context, 1, &name_view); @@ -2528,11 +2443,9 @@ fn context_from_object_template() { let _setup_guard = setup(); let mut params = v8::Isolate::create_params(); params.set_array_buffer_allocator(v8::new_default_allocator()); - let isolate = v8::Isolate::new(params); - let mut locker = v8::Locker::new(&isolate); - let scope = locker.enter(); + let mut isolate = v8::Isolate::new(params); { - let mut hs = v8::HandleScope::new(scope); + let mut hs = v8::HandleScope::new(&mut isolate); let scope = hs.enter(); let object_templ = v8::ObjectTemplate::new(scope); let function_templ = v8::FunctionTemplate::new(scope, fortytwo_callback);