Specifications
Chapter 21256
JSBool JS_ValueToBoolean()
Description
Extracts a function argument from a jsval, converts it to a Boolean value (if possible), and passes
the converted value back to the caller.
Arguments
JSContext *cx, jsval v, JSBool *bp
• cx is the opaque JSContext pointer that passed to the JavaScript function.
• v is the jsval from which the boolean is to be extracted.
• bp is a pointer to a JSBool. This function stores the converted value in *bp.
Returns
A Boolean value that indicates success (JS_TRUE) or failure (JS_FALSE).
JSBool JS_ValueToObject()
Description
Extracts a function argument from a jsval, converts it to an object (if possible), and passes the
converted value back to the caller. If the object is an array, use
JS_GetArrayLength() and
JS_GetElement() to read its contents.
Arguments
JSContext *cx, jsval v, JSObject **op
• cx is the opaque JSContext pointer that passed to the JavaScript function.
• v is the jsval from which the object is to be extracted.
• op is a pointer to a (JSObject *). This function stores the converted value in *op.
Returns
A Boolean value that indicates success (JS_TRUE) or failure (JS_FALSE).
JSBool JS_StringToValue()
Description
Stores a string return value in a jsval. It allocates a new JavaScript string object.
Arguments
JSContext *cx, char *bytes, size_t sz, jsval *vp
• cx is the opaque JSContext pointer that passed to the JavaScript function.
• bytes is the string to be stored in the jsval. The string data is copied, so the caller should free
the string when it is no longer needed. If the string size is not specified (see the
sz argument),
the string must be null-terminated.
• sz is the size of the string, in bytes. If sz is 0, the length of the null-terminated string is
computed automatically.
• vp is a pointer to the jsval into which the contents of the string should be copied.