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);
NameTypeDescription
objJSObject *An object that has reserved slots.
indexuint32_tIndex of the reserved slot to access.
vJS::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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:139 次

字数:3504

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文