JS_GetInstancePrivate 编辑

Retrieve the private data associated with an object, if that object is an instance of a specified class.

Syntax

void *
JS_GetInstancePrivate(JSContext *cx, JS::Handle<JSObject*> obj,
                      const JSClass *clasp, JS::CallArgs *args); // Added in JSAPI 32

void *
JS_GetInstancePrivate(JSContext *cx, JS::Handle<JSObject*> obj,
                      const JSClass *clasp, jsval *argv); // Obsolete since JSAPI 32
NameTypeDescription
cxJSContext *A context.
objJS::Handle&lt;JSObject*&gt;The object for which to retrieve private data.
claspJSClass *Class against which to test the object.
argsJS::CallArgs *Optional argument, used for error reporting. Added in SpiderMonkey 32
argvjsval *

Optional argument vector, used for error reporting. Obsolete since JSAPI 32 This must be one of the following:

  • an argv pointer created by the JavaScript engine and passed to a JSNative callback;
  • JS_ARGV(cx, vp) where vp is a pointer created by the engine and passed to a JSFastNative callback; or
  • NULL.

Description

JS_GetInstancePrivate determines if a JavaScript object, obj, is an instance of a given JSClass, clasp, and if it is, returns a pointer to the object's private data. Otherwise it returns NULL.

Note that if obj is an instance of clasp, but there is no private data currently associated with the object, or the object cannot have private data, JS_GetInstancePrivate also returns NULL.

If you pass a non-null argument vector, argv, to JS_GetInstancePrivate, and obj is not an instance of clasp, this function reports a class mismatch error before returning NULL. In this case, JS_GetInstancePrivate tests whether or not there is a function name associated with the argument vector, and if there is, reports the name in an error message using the JS_ReportError function.

See Also

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

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

发布评论

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

词条统计

浏览:81 次

字数:5311

最后编辑:7年前

编辑次数:0 次

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