#[repr(C)]pub struct Heap<T: GCMethods + Copy> {
pub ptr: UnsafeCell<T>,
}
Expand description
Heap values encapsulate GC concerns of an on-heap reference to a JS object. This means that every reference to a JS object on heap must be realized through this structure.
§Safety
For garbage collection to work correctly in SpiderMonkey, modifying the wrapped value triggers a GC barrier, pointing to the underlying object.
This means that after calling the set()
function with a non-null or
non-undefined value, the Heap
wrapper must not be moved, since doing
so will invalidate the local reference to wrapped value, still held by
SpiderMonkey.
For safe Heap
construction with value see Heap::boxed
function.
Fields§
§ptr: UnsafeCell<T>
Implementations§
source§impl<T: GCMethods + Copy> Heap<T>
impl<T: GCMethods + Copy> Heap<T>
sourcepub fn boxed(v: T) -> Box<Heap<T>>
pub fn boxed(v: T) -> Box<Heap<T>>
This creates a Box
-wrapped Heap value. Setting a value inside Heap
object triggers a barrier, referring to the Heap object location,
hence why it is not safe to construct a temporary Heap value, assign
a non-null value and move it (e.g. typical object construction).
Using boxed Heap value guarantees that the underlying Heap value will not be moved when constructed.
pub fn set(&self, v: T)
pub fn get(&self) -> T
pub fn get_unsafe(&self) -> *mut T
sourcepub unsafe fn handle(&self) -> Handle<T>
pub unsafe fn handle(&self) -> Handle<T>
Retrieves a Handle to the underlying value.
§Safety
This is only safe to do on a rooted object (which Heap is not, it needs to be additionally rooted), like RootedGuard, so use this only if you know what you’re doing.
§Notes
Since Heap values need to be informed when a change to underlying
value is made (e.g. via get()
), this does not allow to create
MutableHandle objects, which can bypass this and lead to crashes.
Trait Implementations§
Auto Trait Implementations§
impl<T> !Freeze for Heap<T>
impl<T> !RefUnwindSafe for Heap<T>
impl<T> Send for Heap<T>where
T: Send,
impl<T> !Sync for Heap<T>
impl<T> Unpin for Heap<T>where
T: Unpin,
impl<T> UnwindSafe for Heap<T>where
T: UnwindSafe,
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> Filterable for T
impl<T> Filterable for T
source§fn filterable(
self,
filter_name: &'static str,
) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>
fn filterable( self, filter_name: &'static str, ) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more