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
Name Type Description
cx JSContext * A context.
obj JS::Handle&lt;JSObject*&gt; The object for which to retrieve private data.
clasp JSClass * Class against which to test the object.
args JS::CallArgs * Optional argument, used for error reporting. Added in SpiderMonkey 32
argv jsval *

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