pub struct Global<T> { /* private fields */ }
Expand description
An object reference that is independent of any handle scope. Where a Local handle only lives as long as the HandleScope in which it was allocated, a global handle remains valid until it is explicitly disposed using reset().
A global handle contains a reference to a storage cell within the V8 engine which holds an object value and which is updated by the garbage collector whenever the object is moved.
Implementations
sourceimpl<T> Global<T>
impl<T> Global<T>
sourcepub fn new(isolate: &mut Isolate, handle: impl Handle<Data = T>) -> Self
pub fn new(isolate: &mut Isolate, handle: impl Handle<Data = T>) -> Self
Construct a new Global from an existing Handle.
sourcepub fn into_raw(self) -> NonNull<T>
pub fn into_raw(self) -> NonNull<T>
Consume this Global
and return the underlying raw pointer.
The returned raw pointer must be converted back into a Global
by using
Global::from_raw
, otherwise the V8 value referenced by this global
handle will be pinned on the V8 heap permanently and never get garbage
collected.
sourcepub unsafe fn from_raw(isolate: &mut Isolate, data: NonNull<T>) -> Self
pub unsafe fn from_raw(isolate: &mut Isolate, data: NonNull<T>) -> Self
Converts a raw pointer created with Global::into_raw()
back to its
original Global
.
pub fn open<'a>(&'a self, scope: &mut Isolate) -> &'a T
Trait Implementations
sourceimpl<T> Handle for Global<T>
impl<T> Handle for Global<T>
type Data = T
sourcefn open<'a>(&'a self, isolate: &mut Isolate) -> &'a Self::Data
fn open<'a>(&'a self, isolate: &mut Isolate) -> &'a Self::Data
Returns a reference to the V8 heap object that this handle represents.
The handle does not get cloned, nor is it converted to a Local
handle. Read more
sourceunsafe fn get_unchecked(&self) -> &Self::Data
unsafe fn get_unchecked(&self) -> &Self::Data
Reads the inner value contained in this handle, without verifying that
the this handle is hosted by the currently active Isolate
. Read more
sourceimpl<'a, T> Handle for &'a Global<T>
impl<'a, T> Handle for &'a Global<T>
type Data = T
sourcefn open<'a>(&'a self, isolate: &mut Isolate) -> &'a Self::Data
fn open<'a>(&'a self, isolate: &mut Isolate) -> &'a Self::Data
Returns a reference to the V8 heap object that this handle represents.
The handle does not get cloned, nor is it converted to a Local
handle. Read more
sourceunsafe fn get_unchecked(&self) -> &Self::Data
unsafe fn get_unchecked(&self) -> &Self::Data
Reads the inner value contained in this handle, without verifying that
the this handle is hosted by the currently active Isolate
. Read more
impl<T> Eq for Global<T> where
T: Eq,
Auto Trait Implementations
impl<T> !RefUnwindSafe for Global<T>
impl<T> !Send for Global<T>
impl<T> !Sync for Global<T>
impl<T> Unpin for Global<T>
impl<T> !UnwindSafe for Global<T>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more