Skip to main content

ObjectKind

Enum ObjectKind 

Source
pub enum ObjectKind {
Show 17 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>), Reference(RefTarget),
}
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<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.

§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: ViewLength

How many bytes the view exposes, or that it follows the buffer.

§

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: ViewLength

How 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

§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.

§

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.

§

Reference(RefTarget)

A specification Reference (§6.2.5), held as a value so that an lvalue can be resolved once and used twice.

x *= f() must read x before f() runs and store to the same binding afterwards (§13.15.3 steps 1–7). Re-resolving the name after the right-hand side gives a different binding when f runs a direct eval("var x"), which creates a shadowing local — that is exactly what compound-assignment/S11.13.2_A6.* check.

A reference never escapes to script: it lives on the operand stack between the make_*_ref that builds it and the get_ref_value/put_ref_value that consume it, which is why it can be an ordinary object rather than a new Value variant.

Implementations§

Source§

impl ObjectKind

Source

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.

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<ModuleRecord> is !null: Freeze, *const GcBox<Cell> is !null: Freeze, *const RcInner<Regex> is !null: Freeze, PhantomData<RcInner<Regex>>: Freeze, *const RcInner<[u8]> is !null: Freeze, PhantomData<RcInner<[u8]>>: Freeze, *const RcInner<Vec<u8>> is !null: Freeze, PhantomData<RcInner<Vec<u8>>>: Freeze, PhantomData<u8>: Freeze, PhantomData<(Value, Value)>: Freeze, *const RcInner<RefCell<BufferStorage>> is !null: Freeze, PhantomData<RcInner<RefCell<BufferStorage>>>: Freeze, PhantomData<Option<(Value, Value)>>: 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, *const HostData is !null: Freeze, PhantomData<HostData>: 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<ModuleRecord> is !null: Unpin, *const GcBox<Cell> is !null: Unpin, Rc<Regex>: Unpin, Rc<[u8]>: Unpin, Rc<Vec<u8>>: Unpin, Rc<RefCell<BufferStorage>>: Unpin, Box<GeneratorState>: Unpin, Rc<RefCell<PromiseState>>: Unpin, Box<FinalizationState>: Unpin, Box<HostData>: Unpin,

§

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

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.