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
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
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
TypedArray
A typed-array view: a window onto an ArrayBuffer.
Fields
element: ElementTypeWhat one element is.
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
WeakRef
A WeakRef: one non-owning handle to a target object.
Fields
Finalization(Box<FinalizationState>)
A FinalizationRegistry: the cleanup callback and its live registrations.