JS_HasInstance

JSAPI method equivalent to the instanceof operator in JavaScript.

Syntax

bool
JS_HasInstance(JSContext *cx, JS::Handle<JSObject*> obj, JS::Handle<JS::Value> v, bool *bp);
Name Type Description
cx JSContext * Pointer to a JS context from which to derive runtime information. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext.
obj JS::Handle&lt;JSObject*&gt; Constructor/prototype to test.
v JS::Handle&lt;JS::Value&gt; The value to test.
bp bool * Out parameter. On success, *bp receives the result of the test.

Description

JS_HasInstance determines if a specified JS value, v, is an instance of JS object, obj. This function is equivalent to v instanceof obj test in JavaScript. On success, JS_HasInstance stores the result of the instanceof test in *bp and returns true. On error or exception, it returns false, and the value left in *bp is undefined.

When providing a prototype as obj, the prototype's JSClass must have its hasInstance method set. Otherwise JS_HasInstance returns false.

See Also