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.
- If
visJSVAL_NULLorJSVAL_VOID, the result isNULL. - If
vis a boolean value, a number, or a string, the result is a new wrapper object of typeBoolean,Number, orString. - Otherwise
vis an object, and the result depends on the object. Ifvis a native JavaScriptObject, this calls the object'svalueOfmethod, if any. In any case, the result is not guaranteed to be the same object asv. (Implementation note: the object'sJSObjectOps.defaultValuemethod is called withhint=JSTYPE_OBJECT.)
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!
