JS ConvertValue
From MDC
Converts a JavaScript value to a value of a specific JavaScript type.
[edit] Syntax
JSBool JS_ConvertValue(JSContext *cx, jsval v, JSType type, jsval *vp);
| Name | Type | Description |
|---|---|---|
cx |
JSContext * |
The context in which to perform the conversion.
Requires request. (In a |
v |
jsval |
The value to convert. |
type |
JSType |
The type to which the value is to be converted. type must be one of JSTYPE_VOID, JSTYPE_OBJECT, JSTYPE_FUNCTION, JSTYPE_STRING, JSTYPE_NUMBER, or JSTYPE_BOOLEAN. Otherwise JS_ConvertValue reports an error. |
vp |
jsval * |
Out parameter. On success, *vp receives the converted value. |
[edit] Description
JS_ConvertValue converts a JavaScript value, v, to the specified type. On success, the converted value is stored in *vp. Typically users of this function set vp to point to v, so that if conversion is successful, v now contains the converted value.
JS_ConvertValue calls other, type-specific conversion routines based on the type argument.
Converting any JS value to JSTYPE_VOID always succeeds. The result is JSVAL_VOID.
Converting to JSTYPE_OBJECT works exactly like JS_ValueToObject.
Converting to JSTYPE_FUNCTION works exactly like JS_ValueToFunction.
Converting to JSTYPE_STRING works exactly like JS_ValueToString.
Converting to JSTYPE_NUMBER works exactly like JS_ValueToNumber.
Converting to JSTYPE_BOOLEAN works exactly like JS_ValueToBoolean.
On success, JS_ConvertValue stores the converted value in *vp and returns JS_TRUE. On error or exception, it returns JS_FALSE, and the value left in *vp is undefined.