JavaScript-1.5 Reference

JS_ValueToInt32 Function

Summary

Converts a JS value to a JS 32-bit integer.

Syntax

JSBool JS_ValueToInt32(JSContext *cx, jsval v, int32 *ip);
NameTypeDescription
cxJSContext *Pointer to a JS context from which to derive runtime information.
vjsvalThe JS value to convert.
ipint32 *Pointer to the JS value that contains the converted integer when the function returns.

Description

JS_ValueToInt32 converts a specified JS value, v, to a 32-bit integer (-2147483648 to 2147483647). If v is NaN, or a double and out of the 32-bit range, JS_ValueToInt32 reports an error and conversion fails. A double is rounded to the nearest integer value.

The actual conversion is performed by the object's convert operation. The converted value is stored in the int32 pointed to by ip.

You can convert a JS value to an integer if the JS value to convert is a JSVAL_INT, JSVAL_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's convert operation returns a primitive value that can be converted.

If the conversion is successful, JS_ValueToInt32 returns JS_TRUE. Otherwise, it reports an error and returns JS_FALSE.

See Also

Groups [ Function ]
Documents [ LXR ID Search ]
Entries [ JS_AddRoot | JS_ConvertArguments | JS_ConvertValue | JS_GetTypeName | JS_TypeOfValue | JS_ValueToBoolean | JS_ValueToFunction | JS_ValueToNumber | JS_ValueToObject | JS_ValueToString ]

This page was generated by APIDOC