Struct mozjs_sys::jsgc::Heap

source ·
#[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>

source

pub fn boxed(v: T) -> Box<Heap<T>>
where Heap<T>: Default,

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.

source

pub fn set(&self, v: T)

source

pub fn get(&self) -> T

source

pub fn get_unsafe(&self) -> *mut T

source

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§

source§

impl<T: Debug + GCMethods + Copy> Debug for Heap<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T> Default for Heap<*mut T>

source§

fn default() -> Heap<*mut T>

Returns the “default value” for a type. Read more
source§

impl Default for Heap<Value>

source§

fn default() -> Heap<Value>

Returns the “default value” for a type. Read more
source§

impl<T: GCMethods + Copy> Drop for Heap<T>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<T: GCMethods + Copy + PartialEq> PartialEq for Heap<T>

source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> Filterable for T

source§

fn filterable( self, filter_name: &'static str, ) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>

Creates a filterable data provider with the given name for debugging. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> ErasedDestructor for T
where T: 'static,

source§

impl<T> MaybeSendSync for T