AcornSearch - Acorn and RISC OS information searching
RISC OS Search
containing
"Nutty quip goes here!"
Home  |  About  |  Filebase Archive  |  StrongHelp Manuals  |  Newsgroups  |  Module Database
Entry:     JS_ConvertValue (Function)
Summary:     Converts a JS value to a value of a specific JS type.
Syntax:
JSBool JS_ConvertValue(JSContext *cx, jsval v, JSType type,
jsval *vp);

     Argument     Type     Description
     cx     JSContext *     Pointer to a JS context from which to derive runtime information.
                 
     v     jsval     The JS value to convert.
                 
     type     JSType     The type to which to convert the value. type must be one of JSTYPE_VOIDJSTYPE_OBJECTJSTYPE_FUNCTIONJSTYPE_STRINGJSTYPE_NUMBER, or JSTYPE_BOOLEAN. Otherwise JS_ConvertValue reports an error.
                 
     vp     jsval *     Pointer to the JS value that contains the converted value when the function returns.
                 
Description:
JS_ConvertValue converts a specified JS value, v, to a specified JS type, type. The converted value is stored in the jsval pointed to by 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 what you specify in type. These include JS_ValueToFunctionJS_ValueToStringJS_ValueToNumber, and JS_ValueToBoolean.

Converting any JS value to JSTYPE_VOID always succeeds.

Converting to JSTYPE_OBJECT is successful if the JS value to convert is one of JSVAL_INTJSVAL_DOUBLEJSVAL_STRINGJSVAL_BOOLEAN, or JSVAL_OBJECT.

Converting to JSTYPE_FUNCTION is successful if the JS value to convert is an object for which a function class has been defined, or if the JS value is already a function.

Converting any JS value to JSTYPE_STRING always succeeds.

Converting a JS value to JSTYPE_NUMBER succeeds if the JS value to convert is a JSVAL_INTJSVAL_DOUBLE, or JSVAL_BOOLEAN. If the JS value is a JSVAL_STRING that contains numeric values and signs only, conversion also succeeds. If the JS value is a JSVAL_OBJECT, conversion is successful if the object supports its own conversion function.

Converting any JS value to JSTYPE_BOOLEAN always succeeds, except when the JS value is a JSVAL_OBJECT that does not support its own conversion routine.

If the conversion is successful, JS_ConvertValue returns JS_TRUE, and vp points to the converted value. Otherwise, it returns JS_FALSE, and vp is either undefined, or points to the current value of v, depending on how you implement your code.


See also:
JS_ConvertArguments
JS_GetTypeName
JS_TypeOfValue
JS_ValueToBoolean
JS_ValueToFunction
JS_ValueToInt32
JS_ValueToNumber
JS_ValueToObject
JS_ValueToString

[sh-index] Back to list of manuals