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 dropped.
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.
You can create a v8::Local
out of v8::Global
using
v8::Local::new(scope, global_handle)
.
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 moreimpl<T> Eq for Global<T>where
T: Eq,
Auto Trait Implementations§
impl<T> Freeze for Global<T>
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§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)