pub enum ObjectKind {
Show 16 variants
Ordinary,
Array {
elements: Vec<Value>,
length: usize,
},
Function(Callable),
RegExp(RegExpData),
DisposableStack(StackState),
ArrayBuffer(Rc<RefCell<BufferStorage>>),
Collection {
entries: Vec<Option<(Value, Value)>>,
is_set: bool,
},
DataView {
buffer: Gc<JsObject>,
offset: usize,
length: ViewLength,
},
TypedArray {
buffer: Gc<JsObject>,
element: ElementType,
offset: usize,
length: ViewLength,
},
Generator(Box<GeneratorState>),
Proxy(ProxyRef),
Promise(PromiseRef),
WeakCollection {
entries: Vec<(WeakKey, Value)>,
is_set: bool,
},
WeakRef {
target: WeakKey,
},
Finalization(Box<FinalizationState>),
HostClass(Box<HostData>),
}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
entries: Vec<Option<(Value, Value)>>The entries, in insertion order.
A deleted entry leaves None behind instead of shifting its neighbours down.
That is the specification’s own model ([[MapData]] is a list whose deletions
write an empty marker), and it is load-bearing: a live iterator holds an
index into this list, so compacting it would make the iterator revisit one entry
and skip another. None slots are reclaimed only when the whole list is
rebuilt by clear or by a Set operation.
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
length: ViewLengthHow many bytes the view exposes, or that it follows the buffer.
TypedArray
A typed-array view: a window onto an ArrayBuffer.
Fields
element: ElementTypeWhat one element is.
length: ViewLengthHow many elements the view exposes, or that it follows the buffer.
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.
HostClass(Box<HostData>)
An instance of a class the host registered (JS_NewObjectProtoClass).
Deliberately not folded into Ordinary with the payload in a private property:
JS_GetOpaque has to be a class check as well as a pointer read, so that handing a
Date to a method expecting a Point is a TypeError rather than a reinterpreted
pointer.
Implementations§
Source§impl ObjectKind
impl ObjectKind
Sourcepub fn variant_name(&self) -> &'static str
pub fn variant_name(&self) -> &'static str
This variant’s name, for the memory report’s per-class census.
Not Debug: the census groups and sorts by these strings, so they have to be stable
and human-readable, and several variants carry payloads that Debug would print.