mirror of
https://github.com/denoland/rusty_v8.git
synced 2024-12-23 15:50:11 -05:00
Clean up and remove AsRef/AsMut implementations (#130)
This commit is contained in:
parent
ae4b48eb22
commit
934dd16e89
15 changed files with 22 additions and 149 deletions
|
@ -28,7 +28,7 @@ pub struct ArrayBufferView(Opaque);
|
|||
impl ArrayBufferView {
|
||||
/// Returns underlying ArrayBuffer.
|
||||
pub fn buffer<'sc>(&self) -> Option<Local<'sc, ArrayBuffer>> {
|
||||
unsafe { Local::from_raw_(v8__ArrayBufferView__Buffer(self)) }
|
||||
unsafe { Local::from_raw(v8__ArrayBufferView__Buffer(self)) }
|
||||
}
|
||||
|
||||
/// Size of a view in bytes.
|
||||
|
|
|
@ -62,15 +62,3 @@ impl Context {
|
|||
unsafe { v8__Context__GetIsolate(self) }
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<Isolate> for Context {
|
||||
fn as_ref(&self) -> &Isolate {
|
||||
unsafe { v8__Context__GetIsolate(self) }
|
||||
}
|
||||
}
|
||||
|
||||
impl AsMut<Isolate> for Context {
|
||||
fn as_mut(&mut self) -> &mut Isolate {
|
||||
unsafe { v8__Context__GetIsolate(self) }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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<HandleScope> for HandleScope {
|
||||
fn as_ref(&self) -> &Self {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl AsMut<HandleScope> for HandleScope {
|
||||
fn as_mut(&mut self) -> &mut Self {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<Isolate> for HandleScope {
|
||||
fn as_ref(&self) -> &Isolate {
|
||||
unsafe { v8__HandleScope__GetIsolate(self) }
|
||||
}
|
||||
}
|
||||
|
||||
impl AsMut<Isolate> 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<T>) -> 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<EscapableHandleScope> for EscapableHandleScope {
|
||||
fn as_ref(&self) -> &Self {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl AsMut<EscapableHandleScope> for EscapableHandleScope {
|
||||
fn as_mut(&mut self) -> &mut Self {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<Isolate> for EscapableHandleScope {
|
||||
fn as_ref(&self) -> &Isolate {
|
||||
unsafe { v8__EscapableHandleScope__GetIsolate(self) }
|
||||
}
|
||||
}
|
||||
|
||||
impl AsMut<Isolate> 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<T>(&mut self, ptr: *mut T) -> Option<Local<'sc, T>> {
|
||||
crate::Local::<'sc, T>::from_raw_(ptr)
|
||||
crate::Local::<'sc, T>::from_raw(ptr)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Isolate> for Isolate {
|
||||
fn as_ref(&self) -> &Isolate {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl AsMut<Isolate> 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<Isolate>);
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ pub fn parse<'sc>(
|
|||
mut context: Local<'sc, Context>,
|
||||
mut json_string: Local<'sc, String>,
|
||||
) -> Option<Local<'sc, Value>> {
|
||||
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<Local<'sc, String>> {
|
||||
unsafe {
|
||||
Local::from_raw_(v8__JSON__Stringify(&mut *context, &mut *json_object))
|
||||
Local::from_raw(v8__JSON__Stringify(&mut *context, &mut *json_object))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Self> {
|
||||
pub(crate) unsafe fn from_raw(ptr: *mut T) -> Option<Self> {
|
||||
Some(Self(NonNull::new(ptr)?, PhantomData))
|
||||
}
|
||||
|
||||
|
|
|
@ -41,15 +41,3 @@ impl Drop for Locker {
|
|||
unsafe { v8__Locker__DESTRUCT(self) }
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<Isolate> for Locker {
|
||||
fn as_ref(&self) -> &Isolate {
|
||||
unsafe { &*self.isolate }
|
||||
}
|
||||
}
|
||||
|
||||
impl AsMut<Isolate> for Locker {
|
||||
fn as_mut(&mut self) -> &mut Isolate {
|
||||
unsafe { &mut *self.isolate }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ impl Module {
|
|||
|
||||
/// For a module in kErrored status, this returns the corresponding exception.
|
||||
pub fn get_exception(&self) -> Local<Value> {
|
||||
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<String> {
|
||||
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
|
||||
|
|
|
@ -96,7 +96,7 @@ impl Promise {
|
|||
mut handler: Local<'sc, Function>,
|
||||
) -> Option<Local<'sc, Promise>> {
|
||||
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<Local<'sc, Promise>> {
|
||||
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<Local<'sc, Promise>> {
|
||||
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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Object> {
|
||||
unsafe { Local::from_raw_(v8__PropertyCallbackInfo__This(self)).unwrap() }
|
||||
unsafe { Local::from_raw(v8__PropertyCallbackInfo__This(self)).unwrap() }
|
||||
}
|
||||
}
|
||||
|
|
40
src/scope.rs
40
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<T> for Entered<'s, S>
|
||||
where
|
||||
S: AsRef<T>,
|
||||
{
|
||||
fn as_ref(&self) -> &T {
|
||||
self.deref().as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'s, S, T> AsMut<T> for Entered<'s, S>
|
||||
where
|
||||
S: AsMut<T>,
|
||||
{
|
||||
fn as_mut(&mut self) -> &mut T {
|
||||
self.deref_mut().as_mut()
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
impl<'s, S, T> AsRef<Entered<'s, T>> for Entered<'s, S>
|
||||
where
|
||||
S: AsRef<T>,
|
||||
{
|
||||
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<Entered<'s, T>> for Entered<'s, S>
|
||||
where
|
||||
S: AsMut<T>,
|
||||
{
|
||||
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>) }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -96,7 +96,7 @@ pub fn compile_module2<'a>(
|
|||
no_cache_reason: NoCacheReason,
|
||||
) -> Option<Local<'a, Module>> {
|
||||
unsafe {
|
||||
Local::from_raw_(v8__ScriptCompiler__CompileModule(
|
||||
Local::from_raw(v8__ScriptCompiler__CompileModule(
|
||||
isolate,
|
||||
&source,
|
||||
options,
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Local<'tc, Value>> {
|
||||
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<Local<'tc, Message>> {
|
||||
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<Local<'a, Value>> {
|
||||
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.
|
||||
|
|
Loading…
Reference in a new issue