Convert any JavaScript value to a floating-point number of type jsdouble.
JSBool JS_ValueToNumber(JSContext *cx, jsval v, jsdouble *dp);
| Name | Type | Description |
|---|---|---|
cx |
JSContext * |
The context in which to perform the conversion.
Requires request. (In a JS_THREADSAFE build, the caller must be in a request on this JSContext.)
|
v |
jsval |
The value to convert. |
dp |
jsdouble * |
Out parameter. On success, *dp receives the converted floating-point value. |
JS_ValueToNumber converts a JavaScript value to a number. It implements the ToNumber operator described in
ECMA 262-3 §9.3
.
v is already a number, conversion succeeds.
v is undefined, null, false, or true, conversion succeeds, and the result is NaN, 0, 0, or 1 respectively.
v is a string, conversion proceeds as specified in
ECMA 262-3 §9.3.1
. JS_ValueToNumber always succeeds in this case, returning JS_TRUE. If the string is not a numeric string, the jsdouble dp out parameter is set to NaN.
v is an object, conversion is successful if the object's JSClass.convert callback returns a primitive value that can be converted.
On success, JS_ValueToNumber stores the converted value in *dp and returns JS_TRUE. On error or exception, it returns JS_FALSE, and the value left in *dp is undefined.
Page last modified 20:07, 5 Sep 2008 by Jorend