Skip to main content

ObjectKind

Enum ObjectKind 

Source
pub enum ObjectKind {
Show 15 variants Ordinary, Array { elements: Vec<Value>, length: usize, }, Function(Callable), RegExp(RegExpData), DisposableStack(StackState), ArrayBuffer(Rc<RefCell<BufferStorage>>), Collection { entries: Vec<(Value, Value)>, is_set: bool, }, DataView { buffer: Gc<JsObject>, offset: usize, length: usize, }, TypedArray { buffer: Gc<JsObject>, element: ElementType, offset: usize, length: usize, }, Generator(Box<GeneratorState>), Proxy(ProxyRef), Promise(PromiseRef), WeakCollection { entries: Vec<(WeakKey, Value)>, is_set: bool, }, WeakRef { target: WeakKey, }, Finalization(Box<FinalizationState>),
}
Expand description

What kind of object this is.

Variants§

§

Ordinary

An ordinary object: only its property table.

§

Array

An array: a dense element vector plus a property table for everything else.

length is stored separately rather than derived from elements.len(), so a sparse array costs nothing to poke at a far index: the reference answers a = []; a.length = 4294967295 instantly, while deriving the length from a dense vector meant allocating one Value per slot — 62 GB and 24 seconds for that one statement. An index past the vector is a hole, and length alone records how many holes there are at the end.

Invariant: elements.len() <= length. A truncation drops both, so the reverse (length < elements.len()) never holds.

Fields

§elements: Vec<Value>

The dense prefix: everything before the first trailing hole.

§length: usize

The logical length, which may exceed elements.len().

§

Function(Callable)

A function or a class constructor.

§

RegExp(RegExpData)

A regular expression: the compiled pattern, plus lastIndex as a property.

§

DisposableStack(StackState)

A DisposableStack or AsyncDisposableStack: the resources it holds.

§

ArrayBuffer(Rc<RefCell<BufferStorage>>)

An ArrayBuffer: a byte range that typed-array views share.

The bytes sit behind an Rc<RefCell<…>> rather than in the object so that every view of the buffer sees the same storage; the views hold the Gc<JsObject> of this buffer, which is what keeps it alive and what the collector traces.

§

Collection

A Map or a Set: insertion-ordered entries with SameValueZero key equality.

One variant for both, because a Set is exactly a Map whose value is unused — the difference is a flag, and is_set is what makes entries yield [v, v] pairs.

Fields

§entries: Vec<(Value, Value)>

The entries, in insertion order.

§is_set: bool

Whether this is a Set rather than a Map.

§

DataView

A DataView: a byte-oriented window onto an ArrayBuffer.

Separate from TypedArray because the two index differently: a typed array has an element type and counts elements, while a DataView is untyped and every accessor names its own width and byte offset. Sharing one variant would mean carrying an element type that is always “bytes” and a length that means something else.

Fields

§buffer: Gc<JsObject>

The buffer whose bytes this view reads.

§offset: usize

Byte offset of the view’s first byte.

§length: usize

How many bytes the view exposes.

§

TypedArray

A typed-array view: a window onto an ArrayBuffer.

Fields

§buffer: Gc<JsObject>

The buffer whose bytes this view reads.

§element: ElementType

What one element is.

§offset: usize

Byte offset of element zero.

§length: usize

How many elements the view exposes.

§

Generator(Box<GeneratorState>)

A generator object: a detached frame plus how far it got.

The frame lives here rather than in the interpreter because a suspended generator has to keep its locals and operand stack alive for as long as the script can reach the generator object — and the collector has to see them, which it only does for things hanging off a Gc.

§

Proxy(ProxyRef)

A Proxy: a stand-in that forwards every internal method to a target through a handler’s traps.

The state sits behind an Rc because Proxy.revocable hands the script a revoke function that has to reach this proxy’s two slots later, from a call site that has no pointer to the object. Revoking clears them, which also drops the collector’s references to the target and the handler.

§

Promise(PromiseRef)

A Promise.

The state sits behind an Rc for the same reason a proxy’s slots do: the resolve/reject pair handed to an executor has to settle this promise later, and those are function objects with no pointer back to it otherwise.

§

WeakCollection

A WeakMap or WeakSet: like a collection, but the keys are weak.

The distinction lives entirely in Trace: a Collection traces its keys, a WeakCollection does not. An entry keyed by an otherwise-unreachable object is therefore reclaimed together with that object instead of keeping it alive, and the entry simply stops being found — upgrade fails and a liveness sweep drops the pair. That is the “ephemeron” behaviour WeakMap promises, and it falls out of reference counting rather than needing a second collection pass.

Fields

§entries: Vec<(WeakKey, Value)>

The entries, in insertion order, keyed by a non-owning handle.

§is_set: bool

Whether this is a WeakSet rather than a WeakMap.

§

WeakRef

A WeakRef: one non-owning handle to a target object.

Fields

§target: WeakKey

The target. Once upgrade fails the reference is dead for good, because a box whose strong count reached zero never comes back.

A WeakKey rather than a WeakGc<JsObject>, because a symbol is a valid target too — new WeakRef(Symbol()) works and deref has to answer it back.

§

Finalization(Box<FinalizationState>)

A FinalizationRegistry: the cleanup callback and its live registrations.

Trait Implementations§

Source§

impl Trace for ObjectKind

Source§

fn trace(&self, tracer: &mut Tracer<'_>)

Report every Gc owned by self to tracer.
Source§

fn external_bytes(&self) -> usize

Bytes this value owns outside its own box: a string’s buffer, an array’s element vector, a buffer’s bytes. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for ObjectKind

§

impl !Send for ObjectKind

§

impl !Sync for ObjectKind

§

impl !UnwindSafe for ObjectKind

§

impl Forget for ObjectKind

§

impl Freeze for ObjectKind
where *const u8 is !null: Freeze, PhantomData<Value>: Freeze, *const GcBox<CompiledCode> is !null: Freeze, *const GcBox<ClosureEnv> is !null: Freeze, *const GcBox<JsString> is !null: Freeze, *const GcBox<JsObject> is !null: Freeze, *const GcBox<JsSymbol> is !null: Freeze, *const GcBox<BigInt> is !null: Freeze, *const RcInner<RefCell<Box<dyn for<'i> FnMut(&mut Interp<'i>, Value, &[Value]) -> Result<Value, Signal>>>> is !null: Freeze, PhantomData<RcInner<RefCell<Box<dyn for<'i> FnMut(&mut Interp<'i>, Value, &[Value]) -> Result<Value, Signal>>>>>: Freeze, *const RcInner<RefCell<ProxyState>> is !null: Freeze, PhantomData<RcInner<RefCell<ProxyState>>>: Freeze, *const GcBox<Cell> is !null: Freeze, *const RcInner<Regex> is !null: Freeze, PhantomData<RcInner<Regex>>: Freeze, PhantomData<u8>: Freeze, PhantomData<(Value, Value)>: Freeze, *const RcInner<RefCell<BufferStorage>> is !null: Freeze, PhantomData<RcInner<RefCell<BufferStorage>>>: Freeze, *const GeneratorState is !null: Freeze, PhantomData<GeneratorState>: Freeze, *const RcInner<RefCell<PromiseState>> is !null: Freeze, PhantomData<RcInner<RefCell<PromiseState>>>: Freeze, PhantomData<(WeakKey, Value)>: Freeze, *const FinalizationState is !null: Freeze, PhantomData<FinalizationState>: Freeze,

§

impl Move for ObjectKind

§

impl Unpin for ObjectKind
where *const u8 is !null: Unpin, *const GcBox<JsString> is !null: Unpin, *const GcBox<JsObject> is !null: Unpin, *const GcBox<JsSymbol> is !null: Unpin, *const GcBox<BigInt> is !null: Unpin, *const GcBox<CompiledCode> is !null: Unpin, *const GcBox<ClosureEnv> is !null: Unpin, Rc<RefCell<Box<dyn for<'i> FnMut(&mut Interp<'i>, Value, &[Value]) -> Result<Value, Signal>>>>: Unpin, Rc<RefCell<ProxyState>>: Unpin, *const GcBox<Cell> is !null: Unpin, Rc<Regex>: Unpin, Rc<RefCell<BufferStorage>>: Unpin, Box<GeneratorState>: Unpin, Rc<RefCell<PromiseState>>: Unpin, Box<FinalizationState>: Unpin,

§

impl UnsafeUnpin for ObjectKind

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.