diff --git a/src/array_buffer.rs b/src/array_buffer.rs index 9334773acb..63c301c416 100644 --- a/src/array_buffer.rs +++ b/src/array_buffer.rs @@ -240,21 +240,24 @@ impl ArrayBuffer { scope: &mut impl ToLocal<'sc>, byte_length: usize, ) -> Local<'sc, ArrayBuffer> { - let isolate = scope.isolate(); - let ptr = - unsafe { v8__ArrayBuffer__New__with_byte_length(isolate, byte_length) }; - unsafe { scope.to_local(ptr) }.unwrap() + unsafe { + scope.to_local(|scope| { + v8__ArrayBuffer__New__with_byte_length(scope.isolate(), byte_length) + }) + } + .unwrap() } pub fn with_backing_store<'sc>( scope: &mut impl ToLocal<'sc>, backing_store: &SharedRef, ) -> Local<'sc, ArrayBuffer> { - let isolate = scope.isolate(); - let ptr = unsafe { - v8__ArrayBuffer__New__with_backing_store(isolate, backing_store) - }; - unsafe { scope.to_local(ptr) }.unwrap() + unsafe { + scope.to_local(|scope| { + v8__ArrayBuffer__New__with_backing_store(scope.isolate(), backing_store) + }) + } + .unwrap() } /// Data length in bytes. diff --git a/src/array_buffer_view.rs b/src/array_buffer_view.rs index d750847078..19f91abbe2 100644 --- a/src/array_buffer_view.rs +++ b/src/array_buffer_view.rs @@ -26,7 +26,7 @@ impl ArrayBufferView { &self, scope: &'_ mut impl ToLocal<'sc>, ) -> Option> { - unsafe { scope.to_local(v8__ArrayBufferView__Buffer(self)) } + unsafe { scope.to_local(|_| v8__ArrayBufferView__Buffer(self)) } } /// Size of a view in bytes. diff --git a/src/context.rs b/src/context.rs index 67f9607c0e..fbd729838b 100644 --- a/src/context.rs +++ b/src/context.rs @@ -23,8 +23,10 @@ impl Context { /// Creates a new context. pub fn new<'sc>(scope: &mut impl ToLocal<'sc>) -> Local<'sc, Context> { // TODO: optional arguments; - let ptr = unsafe { v8__Context__New(scope.isolate(), null(), null()) }; - unsafe { scope.to_local(ptr) }.unwrap() + unsafe { + scope.to_local(|scope| v8__Context__New(scope.isolate(), null(), null())) + } + .unwrap() } /// Creates a new context using the object template as the template for @@ -33,8 +35,10 @@ impl Context { scope: &mut impl ToLocal<'sc>, templ: Local, ) -> Local<'sc, Context> { - let ptr = unsafe { v8__Context__New(scope.isolate(), &*templ, null()) }; - unsafe { scope.to_local(ptr) }.unwrap() + unsafe { + scope.to_local(|scope| v8__Context__New(scope.isolate(), &*templ, null())) + } + .unwrap() } /// Returns the global proxy object. @@ -51,7 +55,7 @@ impl Context { &self, scope: &mut impl ToLocal<'sc>, ) -> Local<'sc, Object> { - unsafe { scope.to_local(v8__Context__Global(self)) }.unwrap() + unsafe { scope.to_local(|_| v8__Context__Global(self)) }.unwrap() } /// Enter this context. After entering a context, all code compiled diff --git a/src/exception.rs b/src/exception.rs index 733aead02d..d9a4cdd8a8 100644 --- a/src/exception.rs +++ b/src/exception.rs @@ -78,10 +78,10 @@ impl StackTrace { scope: &mut impl ToLocal<'sc>, index: usize, ) -> Option> { - let isolate = scope.isolate(); unsafe { - let ptr = v8__StackTrace__GetFrame(self, isolate, index as u32); - scope.to_local(ptr) + scope.to_local(|scope| { + v8__StackTrace__GetFrame(self, scope.isolate(), index as u32) + }) } } } @@ -118,7 +118,7 @@ impl StackFrame { &self, scope: &mut impl ToLocal<'sc>, ) -> Option> { - unsafe { scope.to_local(v8__StackFrame__GetScriptName(self)) } + unsafe { scope.to_local(|_| v8__StackFrame__GetScriptName(self)) } } /// Returns the name of the resource that contains the script for the @@ -129,7 +129,9 @@ impl StackFrame { &self, scope: &mut impl ToLocal<'sc>, ) -> Option> { - unsafe { scope.to_local(v8__StackFrame__GetScriptNameOrSourceURL(self)) } + unsafe { + scope.to_local(|_| v8__StackFrame__GetScriptNameOrSourceURL(self)) + } } /// Returns the name of the function associated with this stack frame. @@ -137,7 +139,7 @@ impl StackFrame { &self, scope: &mut impl ToLocal<'sc>, ) -> Option> { - unsafe { scope.to_local(v8__StackFrame__GetFunctionName(self)) } + unsafe { scope.to_local(|_| v8__StackFrame__GetFunctionName(self)) } } /// Returns whether or not the associated function is compiled via a call to @@ -165,7 +167,7 @@ impl StackFrame { impl Message { pub fn get<'sc>(&self, scope: &mut impl ToLocal<'sc>) -> Local<'sc, String> { - unsafe { scope.to_local(v8__Message__Get(self)) }.unwrap() + unsafe { scope.to_local(|_| v8__Message__Get(self)) }.unwrap() } /// Exception stack trace. By default stack traces are not captured for @@ -175,7 +177,7 @@ impl Message { &self, scope: &mut impl ToLocal<'sc>, ) -> Option> { - unsafe { scope.to_local(v8__Message__GetStackTrace(self)) } + unsafe { scope.to_local(|_| v8__Message__GetStackTrace(self)) } } pub fn get_source_line<'s>( @@ -183,7 +185,7 @@ impl Message { scope: &mut impl ToLocal<'s>, context: Local, ) -> Option> { - unsafe { scope.to_local(v8__Message__GetSourceLine(self, &*context)) } + unsafe { scope.to_local(|_| v8__Message__GetSourceLine(self, &*context)) } } /// Returns the resource name for the script from where the function causing @@ -192,7 +194,7 @@ impl Message { &self, scope: &mut impl ToLocal<'s>, ) -> Option> { - unsafe { scope.to_local(v8__Message__GetScriptResourceName(self)) } + unsafe { scope.to_local(|_| v8__Message__GetScriptResourceName(self)) } } /// Returns the number, 1-based, of the line where the error occurred. @@ -260,55 +262,57 @@ impl Exception { scope: &mut impl ToLocal<'sc>, message: Local, ) -> Local<'sc, Value> { - let isolate = scope.isolate(); - isolate.enter(); - let e = unsafe { v8__Exception__Error(&*message) }; - isolate.exit(); - unsafe { scope.to_local(e) }.unwrap() + scope.isolate().enter(); + let e = + unsafe { scope.to_local(|_| v8__Exception__Error(&*message)) }.unwrap(); + scope.isolate().exit(); + e } pub fn range_error<'sc>( scope: &mut impl ToLocal<'sc>, message: Local, ) -> Local<'sc, Value> { - let isolate = scope.isolate(); - isolate.enter(); - let e = unsafe { v8__Exception__RangeError(&*message) }; - isolate.exit(); - unsafe { scope.to_local(e) }.unwrap() + scope.isolate().enter(); + let e = unsafe { scope.to_local(|_| v8__Exception__RangeError(&*message)) } + .unwrap(); + scope.isolate().exit(); + e } pub fn reference_error<'sc>( scope: &mut impl ToLocal<'sc>, message: Local, ) -> Local<'sc, Value> { - let isolate = scope.isolate(); - isolate.enter(); - let e = unsafe { v8__Exception__ReferenceError(&*message) }; - isolate.exit(); - unsafe { scope.to_local(e) }.unwrap() + scope.isolate().enter(); + let e = + unsafe { scope.to_local(|_| v8__Exception__ReferenceError(&*message)) } + .unwrap(); + scope.isolate().exit(); + e } pub fn syntax_error<'sc>( scope: &mut impl ToLocal<'sc>, message: Local, ) -> Local<'sc, Value> { - let isolate = scope.isolate(); - isolate.enter(); - let e = unsafe { v8__Exception__SyntaxError(&*message) }; - isolate.exit(); - unsafe { scope.to_local(e) }.unwrap() + scope.isolate().enter(); + let e = + unsafe { scope.to_local(|_| v8__Exception__SyntaxError(&*message)) } + .unwrap(); + scope.isolate().exit(); + e } pub fn type_error<'sc>( scope: &mut impl ToLocal<'sc>, message: Local, ) -> Local<'sc, Value> { - let isolate = scope.isolate(); - isolate.enter(); - let e = unsafe { v8__Exception__TypeError(&*message) }; - isolate.exit(); - unsafe { scope.to_local(e) }.unwrap() + scope.isolate().enter(); + let e = unsafe { scope.to_local(|_| v8__Exception__TypeError(&*message)) } + .unwrap(); + scope.isolate().exit(); + e } /// Creates an error message for the given exception. @@ -318,9 +322,12 @@ impl Exception { scope: &mut impl ToLocal<'sc>, exception: Local, ) -> Local<'sc, Message> { - let isolate = scope.isolate(); - let ptr = unsafe { v8__Exception__CreateMessage(isolate, &*exception) }; - unsafe { scope.to_local(ptr) }.unwrap() + unsafe { + scope.to_local(|scope| { + v8__Exception__CreateMessage(scope.isolate(), &*exception) + }) + } + .unwrap() } /// Returns the original stack trace that was captured at the creation time @@ -329,6 +336,6 @@ impl Exception { scope: &mut impl ToLocal<'sc>, exception: Local, ) -> Option> { - unsafe { scope.to_local(v8__Exception__GetStackTrace(&*exception)) } + unsafe { scope.to_local(|_| v8__Exception__GetStackTrace(&*exception)) } } } diff --git a/src/function.rs b/src/function.rs index afa536777c..a4552a1d8c 100644 --- a/src/function.rs +++ b/src/function.rs @@ -96,7 +96,7 @@ impl<'cb> ReturnValue<'cb> { &mut self, scope: &mut impl ToLocal<'sc>, ) -> Local<'sc, Value> { - unsafe { scope.to_local(v8__ReturnValue__Get(self)) }.unwrap() + unsafe { scope.to_local(|_| v8__ReturnValue__Get(self)) }.unwrap() } } @@ -291,7 +291,7 @@ impl Function { callback: impl MapFnTo, ) -> Option> { unsafe { - scope.to_local(v8__Function__New(&*context, callback.map_fn_to())) + scope.to_local(|_| v8__Function__New(&*context, callback.map_fn_to())) } } @@ -304,11 +304,9 @@ impl Function { callback: impl MapFnTo, ) -> Option> { unsafe { - scope.to_local(v8__Function__NewWithData( - &*context, - callback.map_fn_to(), - &*data, - )) + scope.to_local(|_| { + v8__Function__NewWithData(&*context, callback.map_fn_to(), &*data) + }) } } @@ -323,7 +321,8 @@ impl Function { let argc = int::try_from(args.len()).unwrap(); let argv = args.as_ptr(); unsafe { - scope.to_local(v8__Function__Call(self, &*context, &*recv, argc, argv)) + scope + .to_local(|_| v8__Function__Call(self, &*context, &*recv, argc, argv)) } } } diff --git a/src/global.rs b/src/global.rs index ffae933622..f63bc37ca6 100644 --- a/src/global.rs +++ b/src/global.rs @@ -74,13 +74,13 @@ impl Global { &self, scope: &mut impl ToLocal<'sc>, ) -> Option> { - let isolate = scope.isolate(); - self.check_isolate(isolate); + self.check_isolate(scope.isolate()); self .value .map(|g| g.as_ptr() as *const Data) - .map(|g| unsafe { v8__Local__New(isolate, g) }) - .and_then(|l| unsafe { scope.to_local(l as *const T) }) + .and_then(|g| unsafe { + scope.to_local(|scope| v8__Local__New(scope.isolate(), g) as *const T) + }) } /// If non-empty, destroy the underlying storage cell diff --git a/src/module.rs b/src/module.rs index bfe573f9aa..1bac8748d8 100644 --- a/src/module.rs +++ b/src/module.rs @@ -213,6 +213,6 @@ impl Module { scope: &mut impl ToLocal<'sc>, context: Local, ) -> Option> { - unsafe { scope.to_local(v8__Module__Evaluate(&*self, &*context)) } + unsafe { scope.to_local(|_| v8__Module__Evaluate(&*self, &*context)) } } } diff --git a/src/number.rs b/src/number.rs index fd467331c2..9f35ee4213 100644 --- a/src/number.rs +++ b/src/number.rs @@ -20,8 +20,8 @@ impl Number { scope: &mut impl ToLocal<'sc>, value: f64, ) -> Local<'sc, Number> { - let local = unsafe { v8__Number__New(scope.isolate(), value) }; - unsafe { scope.to_local(local) }.unwrap() + unsafe { scope.to_local(|scope| v8__Number__New(scope.isolate(), value)) } + .unwrap() } pub fn value(&self) -> f64 { @@ -34,16 +34,19 @@ impl Integer { scope: &mut impl ToLocal<'sc>, value: i32, ) -> Local<'sc, Integer> { - let local = unsafe { v8__Integer__New(scope.isolate(), value) }; - unsafe { scope.to_local(local) }.unwrap() + unsafe { scope.to_local(|scope| v8__Integer__New(scope.isolate(), value)) } + .unwrap() } pub fn new_from_unsigned<'sc>( scope: &mut impl ToLocal<'sc>, value: u32, ) -> Local<'sc, Integer> { - let local = unsafe { v8__Integer__NewFromUnsigned(scope.isolate(), value) }; - unsafe { scope.to_local(local) }.unwrap() + unsafe { + scope + .to_local(|scope| v8__Integer__NewFromUnsigned(scope.isolate(), value)) + } + .unwrap() } pub fn value(&self) -> i64 { diff --git a/src/object.rs b/src/object.rs index c263528ad3..26a894b576 100644 --- a/src/object.rs +++ b/src/object.rs @@ -86,8 +86,7 @@ extern "C" { impl Object { /// Creates an empty object. pub fn new<'sc>(scope: &mut impl ToLocal<'sc>) -> Local<'sc, Object> { - let ptr = unsafe { v8__Object__New(scope.isolate()) }; - unsafe { scope.to_local(ptr) }.unwrap() + unsafe { scope.to_local(|scope| v8__Object__New(scope.isolate())) }.unwrap() } /// Creates a JavaScript object with the given properties, and @@ -106,15 +105,17 @@ impl Object { let names = Local::slice_into_raw(names); let values = Local::slice_into_raw(values); unsafe { - let object = v8__Object__New__with_prototype_and_properties( - scope.isolate(), - &*prototype_or_null, - names.as_ptr(), - values.as_ptr(), - names.len(), - ); - scope.to_local(object).unwrap() + scope.to_local(|scope| { + v8__Object__New__with_prototype_and_properties( + scope.isolate(), + &*prototype_or_null, + names.as_ptr(), + values.as_ptr(), + names.len(), + ) + }) } + .unwrap() } /// Set only return Just(true) or Empty(), so if it should never fail, use @@ -191,10 +192,7 @@ impl Object { context: Local, key: Local, ) -> Option> { - unsafe { - let ptr = v8__Object__Get(self, &*context, &*key); - scope.to_local(ptr) - } + unsafe { scope.to_local(|_| v8__Object__Get(self, &*context, &*key)) } } pub fn get_index<'a>( @@ -203,10 +201,7 @@ impl Object { context: Local, index: u32, ) -> Option> { - unsafe { - let ptr = v8__Object__GetIndex(self, &*context, index); - scope.to_local(ptr) - } + unsafe { scope.to_local(|_| v8__Object__GetIndex(self, &*context, index)) } } /// Get the prototype object. This does not skip objects marked to be @@ -215,10 +210,7 @@ impl Object { &self, scope: &mut impl ToLocal<'a>, ) -> Option> { - unsafe { - let ptr = v8__Object__GetPrototype(self); - scope.to_local(ptr) - } + unsafe { scope.to_local(|_| v8__Object__GetPrototype(self)) } } /// Note: SideEffectType affects the getter only, not the setter. @@ -248,10 +240,7 @@ impl Object { &self, scope: &mut impl ToLocal<'a>, ) -> Local<'a, Context> { - unsafe { - let ptr = v8__Object__CreationContext(self); - scope.to_local(ptr).unwrap() - } + unsafe { scope.to_local(|_| v8__Object__CreationContext(self)) }.unwrap() } } @@ -262,8 +251,8 @@ impl Array { scope: &mut impl ToLocal<'sc>, length: i32, ) -> Local<'sc, Array> { - let ptr = unsafe { v8__Array__New(scope.isolate(), length) }; - unsafe { scope.to_local(ptr) }.unwrap() + unsafe { scope.to_local(|scope| v8__Array__New(scope.isolate(), length)) } + .unwrap() } /// Creates a JavaScript array out of a Local array with a known length. @@ -275,14 +264,16 @@ impl Array { return Self::new(scope, 0); } let elements = Local::slice_into_raw(elements); - let ptr = unsafe { - v8__Array__New_with_elements( - scope.isolate(), - elements.as_ptr(), - elements.len(), - ) - }; - unsafe { scope.to_local(ptr) }.unwrap() + unsafe { + scope.to_local(|scope| { + v8__Array__New_with_elements( + scope.isolate(), + elements.as_ptr(), + elements.len(), + ) + }) + } + .unwrap() } pub fn length(&self) -> u32 { @@ -300,7 +291,6 @@ impl Map { &self, scope: &mut impl ToLocal<'sc>, ) -> Local<'sc, Array> { - let ptr = unsafe { v8__Map__As__Array(self) }; - unsafe { scope.to_local(ptr) }.unwrap() + unsafe { scope.to_local(|_| v8__Map__As__Array(self)) }.unwrap() } } diff --git a/src/primitive_array.rs b/src/primitive_array.rs index 918946c68f..17343a482f 100644 --- a/src/primitive_array.rs +++ b/src/primitive_array.rs @@ -33,9 +33,12 @@ impl PrimitiveArray { scope: &mut impl ToLocal<'sc>, length: usize, ) -> Local<'sc, PrimitiveArray> { - let ptr = - unsafe { v8__PrimitiveArray__New(scope.isolate(), length as int) }; - unsafe { scope.to_local(ptr) }.unwrap() + unsafe { + scope.to_local(|scope| { + v8__PrimitiveArray__New(scope.isolate(), length as int) + }) + } + .unwrap() } pub fn length(&self) -> usize { @@ -58,8 +61,11 @@ impl PrimitiveArray { scope: &mut impl ToLocal<'sc>, index: usize, ) -> Local<'sc, Primitive> { - let ptr = - unsafe { v8__PrimitiveArray__Get(self, scope.isolate(), index as int) }; - unsafe { scope.to_local(ptr) }.unwrap() + unsafe { + scope.to_local(|scope| { + v8__PrimitiveArray__Get(self, scope.isolate(), index as int) + }) + } + .unwrap() } } diff --git a/src/primitives.rs b/src/primitives.rs index 26831e38ff..c77b57e2d3 100644 --- a/src/primitives.rs +++ b/src/primitives.rs @@ -12,13 +12,11 @@ extern "C" { } pub fn null<'sc>(scope: &mut impl ToLocal<'sc>) -> Local<'sc, Primitive> { - let ptr = unsafe { v8__Null(scope.isolate()) }; - unsafe { scope.to_local(ptr) }.unwrap() + unsafe { scope.to_local(|scope| v8__Null(scope.isolate())) }.unwrap() } pub fn undefined<'sc>(scope: &mut impl ToLocal<'sc>) -> Local<'sc, Primitive> { - let ptr = unsafe { v8__Undefined(scope.isolate()) }; - unsafe { scope.to_local(ptr) }.unwrap() + unsafe { scope.to_local(|scope| v8__Undefined(scope.isolate())) }.unwrap() } impl Boolean { @@ -26,7 +24,7 @@ impl Boolean { scope: &mut impl ToLocal<'sc>, value: bool, ) -> Local<'sc, Boolean> { - let ptr = unsafe { v8__Boolean__New(scope.isolate(), value) }; - unsafe { scope.to_local(ptr) }.unwrap() + unsafe { scope.to_local(|scope| v8__Boolean__New(scope.isolate(), value)) } + .unwrap() } } diff --git a/src/promise.rs b/src/promise.rs index ce6addadc3..3188443ee0 100644 --- a/src/promise.rs +++ b/src/promise.rs @@ -83,7 +83,7 @@ impl Promise { &self, scope: &mut impl ToLocal<'sc>, ) -> Local<'sc, Value> { - unsafe { scope.to_local(v8__Promise__Result(&*self)) }.unwrap() + unsafe { scope.to_local(|_| v8__Promise__Result(&*self)) }.unwrap() } /// Register a rejection handler with a promise. @@ -135,7 +135,7 @@ impl PromiseResolver { scope: &mut impl ToLocal<'sc>, context: Local<'sc, Context>, ) -> Option> { - unsafe { scope.to_local(v8__Promise__Resolver__New(&*context)) } + unsafe { scope.to_local(|_| v8__Promise__Resolver__New(&*context)) } } /// Extract the associated promise. @@ -143,7 +143,7 @@ impl PromiseResolver { &self, scope: &mut impl ToLocal<'sc>, ) -> Local<'sc, Promise> { - unsafe { scope.to_local(v8__Promise__Resolver__GetPromise(&*self)) } + unsafe { scope.to_local(|_| v8__Promise__Resolver__GetPromise(&*self)) } .unwrap() } diff --git a/src/proxy.rs b/src/proxy.rs index 347958ab86..86a6ff27ba 100644 --- a/src/proxy.rs +++ b/src/proxy.rs @@ -25,8 +25,7 @@ impl Proxy { handler: Local, ) -> Option> { unsafe { - let ptr = v8__Proxy__New(&*context, &*target, &*handler); - scope.to_local(ptr) + scope.to_local(|_| v8__Proxy__New(&*context, &*target, &*handler)) } } @@ -34,14 +33,14 @@ impl Proxy { &mut self, scope: &mut impl ToLocal<'sc>, ) -> Local<'sc, Value> { - unsafe { scope.to_local(v8__Proxy__GetHandler(&*self)) }.unwrap() + unsafe { scope.to_local(|_| v8__Proxy__GetHandler(&*self)) }.unwrap() } pub fn get_target<'sc>( &mut self, scope: &mut impl ToLocal<'sc>, ) -> Local<'sc, Value> { - unsafe { scope.to_local(v8__Proxy__GetTarget(&*self)) }.unwrap() + unsafe { scope.to_local(|_| v8__Proxy__GetTarget(&*self)) }.unwrap() } pub fn is_revoked(&mut self) -> bool { diff --git a/src/scope_traits.rs b/src/scope_traits.rs index fecb8bff7c..17ba3166bf 100644 --- a/src/scope_traits.rs +++ b/src/scope_traits.rs @@ -151,8 +151,11 @@ extern "C" { /// When scope implements this trait, this means that Local handles can be /// created inside it. pub trait ToLocal<'s>: InIsolate { - unsafe fn to_local(&mut self, ptr: *const T) -> Option> { - Local::from_raw(ptr) + unsafe fn to_local *const T>( + &mut self, + f: F, + ) -> Option> { + Local::from_raw(f(self)) } fn get_current_context(&mut self) -> Option> { diff --git a/src/script.rs b/src/script.rs index 2f406dfe24..103b50a96c 100644 --- a/src/script.rs +++ b/src/script.rs @@ -48,14 +48,15 @@ impl Script { source: Local, origin: Option<&ScriptOrigin>, ) -> Option> { - let ptr = unsafe { - v8__Script__Compile( - &*context, - &*source, - origin.map(|r| r as *const _).unwrap_or(null()), - ) - }; - unsafe { scope.to_local(ptr) } + unsafe { + scope.to_local(|_| { + v8__Script__Compile( + &*context, + &*source, + origin.map(|r| r as *const _).unwrap_or(null()), + ) + }) + } } /// Runs the script returning the resulting value. It will be run in the @@ -66,7 +67,7 @@ impl Script { scope: &mut impl ToLocal<'sc>, context: Local, ) -> Option> { - unsafe { scope.to_local(v8__Script__Run(self, &*context)) } + unsafe { scope.to_local(|_| v8__Script__Run(self, &*context)) } } } diff --git a/src/shared_array_buffer.rs b/src/shared_array_buffer.rs index 5d9651b213..0cdfeaac00 100644 --- a/src/shared_array_buffer.rs +++ b/src/shared_array_buffer.rs @@ -61,11 +61,15 @@ impl SharedArrayBuffer { scope: &mut impl ToLocal<'sc>, backing_store: &SharedRef, ) -> Local<'sc, SharedArrayBuffer> { - let isolate = scope.isolate(); - let ptr = unsafe { - v8__SharedArrayBuffer__New__with_backing_store(isolate, backing_store) - }; - unsafe { scope.to_local(ptr) }.unwrap() + unsafe { + scope.to_local(|scope| { + v8__SharedArrayBuffer__New__with_backing_store( + scope.isolate(), + backing_store, + ) + }) + } + .unwrap() } /// Data length in bytes. diff --git a/src/string.rs b/src/string.rs index 46c7e3c64a..fbfdf0acd9 100644 --- a/src/string.rs +++ b/src/string.rs @@ -64,10 +64,10 @@ bitflags! { impl String { pub fn empty<'sc>(scope: &mut impl ToLocal<'sc>) -> Local<'sc, String> { - let ptr = unsafe { v8__String__Empty(scope.isolate()) }; // FIXME(bnoordhuis) v8__String__Empty() is infallible so there // is no need to box up the result, only to unwrap it again. - unsafe { scope.to_local(ptr) }.unwrap() + unsafe { scope.to_local(|scope| v8__String__Empty(scope.isolate())) } + .unwrap() } pub fn new_from_utf8<'sc>( @@ -78,15 +78,17 @@ impl String { if buffer.is_empty() { return Some(Self::empty(scope)); } - let ptr = unsafe { - v8__String__NewFromUtf8( - scope.isolate(), - buffer.as_ptr() as *const char, - new_type, - buffer.len().try_into().ok()?, - ) - }; - unsafe { scope.to_local(ptr) } + let buffer_len = buffer.len().try_into().ok()?; + unsafe { + scope.to_local(|scope| { + v8__String__NewFromUtf8( + scope.isolate(), + buffer.as_ptr() as *const char, + new_type, + buffer_len, + ) + }) + } } /// Returns the number of characters (UTF-16 code units) in this string. diff --git a/src/template.rs b/src/template.rs index dc17a63494..01840bc122 100644 --- a/src/template.rs +++ b/src/template.rs @@ -70,10 +70,12 @@ impl FunctionTemplate { scope: &mut impl ToLocal<'sc>, callback: impl MapFnTo, ) -> Local<'sc, FunctionTemplate> { - let ptr = unsafe { - v8__FunctionTemplate__New(scope.isolate(), callback.map_fn_to()) - }; - unsafe { scope.to_local(ptr) }.unwrap() + unsafe { + scope.to_local(|scope| { + v8__FunctionTemplate__New(scope.isolate(), callback.map_fn_to()) + }) + } + .unwrap() } /// Returns the unique function instance in the current execution context. @@ -83,7 +85,7 @@ impl FunctionTemplate { context: Local, ) -> Option> { unsafe { - scope.to_local(v8__FunctionTemplate__GetFunction(&*self, &*context)) + scope.to_local(|_| v8__FunctionTemplate__GetFunction(&*self, &*context)) } } @@ -98,9 +100,12 @@ impl FunctionTemplate { impl ObjectTemplate { /// Creates an object template. pub fn new<'sc>(scope: &mut impl ToLocal<'sc>) -> Local<'sc, ObjectTemplate> { - let ptr = - unsafe { v8__ObjectTemplate__New(scope.isolate(), std::ptr::null()) }; - unsafe { scope.to_local(ptr) }.unwrap() + unsafe { + scope.to_local(|scope| { + v8__ObjectTemplate__New(scope.isolate(), std::ptr::null()) + }) + } + .unwrap() } /// Creates an object template from a function template. @@ -108,8 +113,10 @@ impl ObjectTemplate { scope: &mut impl ToLocal<'sc>, templ: Local, ) -> Local<'sc, ObjectTemplate> { - let ptr = unsafe { v8__ObjectTemplate__New(scope.isolate(), &*templ) }; - unsafe { scope.to_local(ptr) }.unwrap() + unsafe { + scope.to_local(|scope| v8__ObjectTemplate__New(scope.isolate(), &*templ)) + } + .unwrap() } /// Creates a new instance of this object template. @@ -118,7 +125,8 @@ impl ObjectTemplate { scope: &mut impl ToLocal<'a>, context: Local, ) -> Option> { - let ptr = unsafe { v8__ObjectTemplate__NewInstance(self, &*context) }; - unsafe { scope.to_local(ptr) } + unsafe { + scope.to_local(|_| v8__ObjectTemplate__NewInstance(self, &*context)) + } } } diff --git a/src/try_catch.rs b/src/try_catch.rs index e132a839c4..c49b2c167e 100644 --- a/src/try_catch.rs +++ b/src/try_catch.rs @@ -119,7 +119,7 @@ impl<'tc> TryCatch<'tc> { &self, scope: &mut impl ToLocal<'sc>, ) -> Option> { - unsafe { scope.to_local(v8__TryCatch__Exception(&self.0)) } + unsafe { scope.to_local(|_| v8__TryCatch__Exception(&self.0)) } } /// Returns the message associated with this exception. If there is @@ -131,7 +131,7 @@ impl<'tc> TryCatch<'tc> { &self, scope: &mut impl ToLocal<'sc>, ) -> Option> { - unsafe { scope.to_local(v8__TryCatch__Message(&self.0)) } + unsafe { scope.to_local(|_| v8__TryCatch__Message(&self.0)) } } /// Returns the .stack property of the thrown object. If no .stack @@ -141,7 +141,7 @@ impl<'tc> TryCatch<'tc> { scope: &mut impl ToLocal<'sc>, context: Local, ) -> Option> { - unsafe { scope.to_local(v8__TryCatch__StackTrace(&self.0, &*context)) } + unsafe { scope.to_local(|_| v8__TryCatch__StackTrace(&self.0, &*context)) } } /// Clears any exceptions that may have been caught by this try/catch block.