JSGetObjectOps 编辑

Obsolete since JSAPI 17
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.

JSGetObjectOps is the type for JSClass.getObjectOps

Callback Syntax

typedef JSObjectOps *
(* JSGetObjectOps)(JSContext *cx, JSClass *clasp);
NameTypeDescription
cxJSContext *The JS context in which the new object is being created.
clsJSClass *The class of the new object.

Description

JSObjectOps is used by JS_NewObject's internals to discover the set of high-level object operations to use for new objects of the given class. All native objects have a JSClass, which is stored as a private (int-tagged) pointer in object slots. In contrast, all native and host objects have a JSObjectMap at obj->map, which may be shared among a number of objects, and which contains the JSObjectOps *ops pointer used to dispatch object operations from API calls.

Thus JSClass (which pre-dates JSObjectOps in the API) provides a low-level interface to class-specific code and data, while JSObjectOps allows for a higher level of operation, which does not use the object's class except to find the class's JSObjectOps struct, by calling clasp->getObjectOps, and to finalize the object.

If this seems backwards, that's because it is! API compatibility requires a JSClass *clasp parameter to JS_NewObject, etc. Most host objects do not need to implement the larger JSObjectOps, and can share the common JSScope code and data used by the native (js_ObjectOps, see jsobj.c) ops.

Further extension to preserve API compatibility: if this function returns a pointer to JSXMLObjectOps.base, not to JSObjectOps, then the engine calls extended hooks needed for E4X.

JSClass hooks

JSClass offerd following hook:

  • The JSClass.getObjectOps hook is called each time an object is created. It returns a pointer to a JSObjectOps which is then used as a virtual table for operations on the new object.

See Also

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

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

发布评论

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

词条统计

浏览:65 次

字数:5398

最后编辑:8年前

编辑次数:0 次

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