diff --git a/src/array_buffer_view.rs b/src/array_buffer_view.rs index f8a79a7d..4927e413 100644 --- a/src/array_buffer_view.rs +++ b/src/array_buffer_view.rs @@ -28,7 +28,7 @@ pub struct ArrayBufferView(Opaque); impl ArrayBufferView { /// Returns underlying ArrayBuffer. pub fn buffer<'sc>(&self) -> Option> { - unsafe { Local::from_raw_(v8__ArrayBufferView__Buffer(self)) } + unsafe { Local::from_raw(v8__ArrayBufferView__Buffer(self)) } } /// Size of a view in bytes. diff --git a/src/context.rs b/src/context.rs index 2e229154..61f729b2 100644 --- a/src/context.rs +++ b/src/context.rs @@ -62,15 +62,3 @@ impl Context { unsafe { v8__Context__GetIsolate(self) } } } - -impl AsRef for Context { - fn as_ref(&self) -> &Isolate { - unsafe { v8__Context__GetIsolate(self) } - } -} - -impl AsMut for Context { - fn as_mut(&mut self) -> &mut Isolate { - unsafe { v8__Context__GetIsolate(self) } - } -} diff --git a/src/function.rs b/src/function.rs index c2d88b8b..f2b0ddeb 100644 --- a/src/function.rs +++ b/src/function.rs @@ -86,7 +86,6 @@ impl<'cb> ReturnValue<'cb> { pub struct FunctionCallbackInfo(Opaque); impl InIsolate for FunctionCallbackInfo { - #[allow(clippy::cast_ref_to_mut)] fn isolate(&mut self) -> &mut Isolate { self.get_isolate() } diff --git a/src/handle_scope.rs b/src/handle_scope.rs index 962f2ca0..21b2c88f 100644 --- a/src/handle_scope.rs +++ b/src/handle_scope.rs @@ -1,6 +1,7 @@ use std::mem::MaybeUninit; use crate::isolate::Isolate; +use crate::scope::Entered; use crate::scope::Scope; use crate::scope::Scoped; use crate::InIsolate; @@ -54,30 +55,6 @@ impl Drop for HandleScope { } } -impl AsRef for HandleScope { - fn as_ref(&self) -> &Self { - self - } -} - -impl AsMut for HandleScope { - fn as_mut(&mut self) -> &mut Self { - self - } -} - -impl AsRef for HandleScope { - fn as_ref(&self) -> &Isolate { - unsafe { v8__HandleScope__GetIsolate(self) } - } -} - -impl AsMut for HandleScope { - fn as_mut(&mut self) -> &mut Isolate { - unsafe { v8__HandleScope__GetIsolate(self) } - } -} - /// A HandleScope which first allocates a handle in the current scope /// which will be later filled with the escape value. #[repr(C)] @@ -92,7 +69,7 @@ impl EscapableHandleScope { /// Cannot be called twice. pub fn escape<'parent, T>(&mut self, value: Local) -> Local<'parent, T> { unsafe { - Local::from_raw_(v8__EscapableHandleScope__Escape( + Local::from_raw(v8__EscapableHandleScope__Escape( self, value.as_ptr() as *mut Value, ) as *mut T) @@ -115,32 +92,6 @@ impl Drop for EscapableHandleScope { } } -impl AsRef for EscapableHandleScope { - fn as_ref(&self) -> &Self { - self - } -} - -impl AsMut for EscapableHandleScope { - fn as_mut(&mut self) -> &mut Self { - self - } -} - -impl AsRef for EscapableHandleScope { - fn as_ref(&self) -> &Isolate { - unsafe { v8__EscapableHandleScope__GetIsolate(self) } - } -} - -impl AsMut for EscapableHandleScope { - fn as_mut(&mut self) -> &mut Isolate { - unsafe { v8__EscapableHandleScope__GetIsolate(self) } - } -} - -use crate::scope::Entered; - impl<'s> InIsolate for Entered<'s, HandleScope> { fn isolate(&mut self) -> &mut Isolate { unsafe { v8__HandleScope__GetIsolate(self) } @@ -155,7 +106,7 @@ impl<'s> InIsolate for Entered<'s, EscapableHandleScope> { pub trait ToLocal<'sc>: InIsolate { unsafe fn to_local(&mut self, ptr: *mut T) -> Option> { - crate::Local::<'sc, T>::from_raw_(ptr) + crate::Local::<'sc, T>::from_raw(ptr) } } diff --git a/src/isolate.rs b/src/isolate.rs index 4aca45d0..6394bc76 100644 --- a/src/isolate.rs +++ b/src/isolate.rs @@ -162,7 +162,7 @@ impl Isolate { ) -> Local<'sc, Value> { unsafe { let ptr = v8__Isolate__ThrowException(self, &exception); - Local::from_raw_(ptr).unwrap() + Local::from_raw(ptr).unwrap() } } @@ -173,18 +173,6 @@ impl Isolate { } } -impl AsRef for Isolate { - fn as_ref(&self) -> &Isolate { - self - } -} - -impl AsMut for Isolate { - fn as_mut(&mut self) -> &mut Isolate { - self - } -} - /// Same as Isolate but gets disposed when it goes out of scope. pub struct OwnedIsolate(NonNull); diff --git a/src/json.rs b/src/json.rs index d56a510a..5c7e218d 100644 --- a/src/json.rs +++ b/src/json.rs @@ -22,7 +22,7 @@ pub fn parse<'sc>( mut context: Local<'sc, Context>, mut json_string: Local<'sc, String>, ) -> Option> { - unsafe { Local::from_raw_(v8__JSON__Parse(&mut *context, &mut *json_string)) } + unsafe { Local::from_raw(v8__JSON__Parse(&mut *context, &mut *json_string)) } } /// Tries to stringify the JSON-serializable object `json_object` and returns @@ -32,6 +32,6 @@ pub fn stringify<'sc>( mut json_object: Local<'sc, Value>, ) -> Option> { unsafe { - Local::from_raw_(v8__JSON__Stringify(&mut *context, &mut *json_object)) + Local::from_raw(v8__JSON__Stringify(&mut *context, &mut *json_object)) } } diff --git a/src/local.rs b/src/local.rs index 5f64b61f..e13dbf08 100644 --- a/src/local.rs +++ b/src/local.rs @@ -49,7 +49,7 @@ impl<'sc, T> Clone for Local<'sc, T> { } impl<'sc, T> Local<'sc, T> { - pub(crate) unsafe fn from_raw_(ptr: *mut T) -> Option { + pub(crate) unsafe fn from_raw(ptr: *mut T) -> Option { Some(Self(NonNull::new(ptr)?, PhantomData)) } diff --git a/src/locker.rs b/src/locker.rs index b63ddb0d..cb66aee7 100644 --- a/src/locker.rs +++ b/src/locker.rs @@ -41,15 +41,3 @@ impl Drop for Locker { unsafe { v8__Locker__DESTRUCT(self) } } } - -impl AsRef for Locker { - fn as_ref(&self) -> &Isolate { - unsafe { &*self.isolate } - } -} - -impl AsMut for Locker { - fn as_mut(&mut self) -> &mut Isolate { - unsafe { &mut *self.isolate } - } -} diff --git a/src/module.rs b/src/module.rs index 99d12af5..66b901a6 100644 --- a/src/module.rs +++ b/src/module.rs @@ -87,7 +87,7 @@ impl Module { /// For a module in kErrored status, this returns the corresponding exception. pub fn get_exception(&self) -> Local { - unsafe { Local::from_raw_(v8__Module__GetException(self)).unwrap() } + unsafe { Local::from_raw(v8__Module__GetException(self)).unwrap() } } /// Returns the number of modules requested by this module. @@ -98,7 +98,7 @@ impl Module { /// Returns the ith module specifier in this module. /// i must be < self.get_module_requests_length() and >= 0. pub fn get_module_request(&self, i: usize) -> Local { - unsafe { Local::from_raw_(v8__Module__GetModuleRequest(self, i)).unwrap() } + unsafe { Local::from_raw(v8__Module__GetModuleRequest(self, i)).unwrap() } } /// Returns the source location (line number and column number) of the ith diff --git a/src/promise.rs b/src/promise.rs index a3ddd330..587a6d35 100644 --- a/src/promise.rs +++ b/src/promise.rs @@ -96,7 +96,7 @@ impl Promise { mut handler: Local<'sc, Function>, ) -> Option> { unsafe { - Local::from_raw_(v8__Promise__Catch( + Local::from_raw(v8__Promise__Catch( &mut *self, &mut *context, &mut *handler, @@ -113,7 +113,7 @@ impl Promise { mut handler: Local<'sc, Function>, ) -> Option> { unsafe { - Local::from_raw_(v8__Promise__Then( + Local::from_raw(v8__Promise__Then( &mut *self, &mut *context, &mut *handler, @@ -132,7 +132,7 @@ impl Promise { mut on_rejected: Local<'sc, Function>, ) -> Option> { unsafe { - Local::from_raw_(v8__Promise__Then2( + Local::from_raw(v8__Promise__Then2( &mut *self, &mut *context, &mut *on_fulfilled, @@ -205,7 +205,7 @@ pub struct PromiseRejectMessage<'msg>([usize; 3], PhantomData<&'msg ()>); impl<'msg> PromiseRejectMessage<'msg> { pub fn get_promise(&self) -> Local<'msg, Promise> { unsafe { - Local::from_raw_(v8__PromiseRejectMessage__GetPromise(self)).unwrap() + Local::from_raw(v8__PromiseRejectMessage__GetPromise(self)).unwrap() } } @@ -215,7 +215,7 @@ impl<'msg> PromiseRejectMessage<'msg> { pub fn get_value(&self) -> Local<'msg, Value> { unsafe { - Local::from_raw_(v8__PromiseRejectMessage__GetValue(self)).unwrap() + Local::from_raw(v8__PromiseRejectMessage__GetValue(self)).unwrap() } } } diff --git a/src/property.rs b/src/property.rs index 2065d404..137366d5 100644 --- a/src/property.rs +++ b/src/property.rs @@ -30,12 +30,11 @@ impl PropertyCallbackInfo { } } - #[allow(clippy::mut_from_ref)] pub fn get_isolate(&mut self) -> &mut Isolate { unsafe { v8__PropertyCallbackInfo__GetIsolate(self) } } pub fn this(&self) -> Local { - unsafe { Local::from_raw_(v8__PropertyCallbackInfo__This(self)).unwrap() } + unsafe { Local::from_raw(v8__PropertyCallbackInfo__This(self)).unwrap() } } } diff --git a/src/scope.rs b/src/scope.rs index ed360bc4..1bdde1c5 100644 --- a/src/scope.rs +++ b/src/scope.rs @@ -107,43 +107,3 @@ impl<'s, S> DerefMut for Entered<'s, S> { unsafe { &mut *(self as *mut _ as *mut S) } } } - -/* -impl<'s, S, T> AsRef for Entered<'s, S> -where - S: AsRef, -{ - fn as_ref(&self) -> &T { - self.deref().as_ref() - } -} - -impl<'s, S, T> AsMut for Entered<'s, S> -where - S: AsMut, -{ - fn as_mut(&mut self) -> &mut T { - self.deref_mut().as_mut() - } -} -*/ - -impl<'s, S, T> AsRef> for Entered<'s, S> -where - S: AsRef, -{ - fn as_ref(&self) -> &Entered<'s, T> { - let t: &T = self.deref().as_ref(); - unsafe { &*(t as *const _ as *const Entered<'s, T>) } - } -} - -impl<'s, S, T> AsMut> for Entered<'s, S> -where - S: AsMut, -{ - fn as_mut(&mut self) -> &mut Entered<'s, T> { - let t: &mut T = self.deref_mut().as_mut(); - unsafe { &mut *(t as *mut _ as *mut Entered<'s, T>) } - } -} diff --git a/src/script_compiler.rs b/src/script_compiler.rs index 0ae42c57..0b51756b 100644 --- a/src/script_compiler.rs +++ b/src/script_compiler.rs @@ -96,7 +96,7 @@ pub fn compile_module2<'a>( no_cache_reason: NoCacheReason, ) -> Option> { unsafe { - Local::from_raw_(v8__ScriptCompiler__CompileModule( + Local::from_raw(v8__ScriptCompiler__CompileModule( isolate, &source, options, diff --git a/src/script_or_module.rs b/src/script_or_module.rs index c9048834..3423b0a9 100644 --- a/src/script_or_module.rs +++ b/src/script_or_module.rs @@ -25,7 +25,7 @@ impl ScriptOrModule { pub fn get_resource_name(&self) -> Local<'_, Value> { unsafe { let ptr = v8__ScriptOrModule__GetResourceName(self); - Local::from_raw_(ptr).unwrap() + Local::from_raw(ptr).unwrap() } } @@ -34,7 +34,7 @@ impl ScriptOrModule { pub fn get_host_defined_options(&self) -> Local<'_, PrimitiveArray> { unsafe { let ptr = v8__ScriptOrModule__GetHostDefinedOptions(self); - Local::from_raw_(ptr).unwrap() + Local::from_raw(ptr).unwrap() } } } diff --git a/src/try_catch.rs b/src/try_catch.rs index e1501da6..1be8bca8 100644 --- a/src/try_catch.rs +++ b/src/try_catch.rs @@ -112,7 +112,7 @@ impl<'tc> TryCatch<'tc> { /// /// The returned handle is valid until this TryCatch block has been destroyed. pub fn exception(&self) -> Option> { - unsafe { Local::from_raw_(v8__TryCatch__Exception(&self.0)) } + unsafe { Local::from_raw(v8__TryCatch__Exception(&self.0)) } } /// Returns the .stack property of the thrown object. If no .stack @@ -131,7 +131,7 @@ impl<'tc> TryCatch<'tc> { /// The returned handle is valid until this TryCatch block has been /// destroyed. pub fn message(&self) -> Option> { - unsafe { Local::from_raw_(v8__TryCatch__Message(&self.0)) } + unsafe { Local::from_raw(v8__TryCatch__Message(&self.0)) } } /// Clears any exceptions that may have been caught by this try/catch block. @@ -152,7 +152,7 @@ impl<'tc> TryCatch<'tc> { /// ReThrow; the caller must return immediately to where the exception /// is caught. pub fn rethrow<'a>(&'_ mut self) -> Option> { - unsafe { Local::from_raw_(v8__TryCatch__ReThrow(&mut self.0)) } + unsafe { Local::from_raw(v8__TryCatch__ReThrow(&mut self.0)) } } /// Returns true if verbosity is enabled.