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§
source§impl<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§
source§impl<'a, T> Handle for &'a Global<T>
impl<'a, T> Handle for &'a Global<T>
type Data = T
source§fn open<'a>(&'a self, isolate: &mut Isolate) -> &'a Self::Data
fn open<'a>(&'a self, isolate: &mut Isolate) -> &'a Self::Data
Local
handle. Read moresource§unsafe fn get_unchecked(&self) -> &Self::Data
unsafe fn get_unchecked(&self) -> &Self::Data
Isolate
. Read moresource§impl<T> Handle for Global<T>
impl<T> Handle for Global<T>
type Data = T
source§fn open<'a>(&'a self, isolate: &mut Isolate) -> &'a Self::Data
fn open<'a>(&'a self, isolate: &mut Isolate) -> &'a Self::Data
Local
handle. Read moresource§unsafe fn get_unchecked(&self) -> &Self::Data
unsafe fn get_unchecked(&self) -> &Self::Data
Isolate
. Read more