Converts any JavaScript value to an object.

Syntax

bool
JS_ValueToObject(JSContext *cx, JS::HandleValue v, JS::MutableHandleObject objp);
Name Type Description
cx JSContext * The context in which to convert the value. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext.
v JS::HandleValue The value to convert.
objp JS::MutableHandleObject Out parameter. On success, *objp receives NULL or a pointer to the resulting object.

Description

JS_ValueToObject converts a specified JavaScript value, v, to an object. On success, this function stores either NULL or a pointer to the resulting object in *objp and returns true. Otherwise it returns false and the value left in *objp is unspecified.

The resulting object is subject to garbage collection unless the variable *objp is protected by a local root scope, an object property, or the JS_AddRoot function. Note that a local root scope is not sufficient to protect the resulting object in some cases involving the valueOf method!

See Also