JS_GetReservedSlot

Access an object's reserved slots.

Syntax

// Added in SpiderMonkey 42
JS::Value
JS_GetReservedSlot(JSObject *obj, uint32_t index);

void
JS_SetReservedSlot(JSObject *obj, uint32_t index, JS::Value v);

// Obsolete since SpiderMonkey 42
jsval
JS_GetReservedSlot(JSObject *obj, uint32_t index);

void
JS_SetReservedSlot(JSObject *obj, uint32_t index, jsval v);
Name Type Description
obj JSObject * An object that has reserved slots.
index uint32_t Index of the reserved slot to access.
v JS::Value (in JS_SetReservedSlot) The value to store.

Description

If a JSClass has JSCLASS_HAS_RESERVED_SLOTS(n) in its flags, with n > 0, or has a non-null JSClass.reserveSlots callback, then objects of that class have n reserved slots in which the application may store data. These fields are not directly exposed to scripts.

Reserved slots may contain any JS::Value, and the garbage collector will hold the value alive as long as the object itself is alive.

Reserved slots may also contain private values to store pointer values (whose lowest bit is 0) or uint32_t, when non-JavaScript values must be stored; the garbage collector ignores such values when it sees them. (Note that private values must not be exposed directly to JavaScript. It's only legal to store and retrieve data from private values. They cannot be returned from functions, set as properties on objects, embedded in JavaScript arrays, and so on.)

New objects' reserved slots are initialized to undefined.

See Also