Expose public APIs for converting doubles to signed/unsigned int per ECMA spec (bug 631132, r=bzbarsky).
authorAndreas Gal <gal@mozilla.com>
Tue, 29 Mar 2011 19:19:15 -0700
changeset 64550 8359361f8a7b64fe63ea20d9ebf6ffb770d42e7b
parent 64549 df211d75bddcfb9990841fd89353962ca6b41161
child 64551 d10c089a6888f29f4e097990b49afb1a5c16396b
push idunknown
push userunknown
push dateunknown
reviewersbzbarsky
bugs631132
milestone2.2a1pre
Expose public APIs for converting doubles to signed/unsigned int per ECMA spec (bug 631132, r=bzbarsky).
js/src/jsapi.cpp
js/src/jsapi.h
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -515,16 +515,28 @@ JS_ValueToNumber(JSContext *cx, jsval v,
 }
 
 JS_PUBLIC_API(JSBool)
 JS_DoubleIsInt32(jsdouble d, jsint *ip)
 {
     return JSDOUBLE_IS_INT32(d, (int32_t *)ip);
 }
 
+JS_PUBLIC_API(int32)
+JS_DoubleToInt32(jsdouble d)
+{
+    return js_DoubleToECMAInt32(d);
+}
+
+JS_PUBLIC_API(uint32)
+JS_DoubleToUint32(jsdouble d)
+{
+    return js_DoubleToECMAUint32(d);
+}
+
 JS_PUBLIC_API(JSBool)
 JS_ValueToECMAInt32(JSContext *cx, jsval v, int32 *ip)
 {
     CHECK_REQUEST(cx);
     assertSameCompartment(cx, v);
 
     AutoValueRooter tvr(cx, Valueify(v));
     return ValueToECMAInt32(cx, tvr.value(), (int32_t *)ip);
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -659,16 +659,22 @@ extern JS_PUBLIC_API(JSString *)
 JS_ValueToSource(JSContext *cx, jsval v);
 
 extern JS_PUBLIC_API(JSBool)
 JS_ValueToNumber(JSContext *cx, jsval v, jsdouble *dp);
 
 extern JS_PUBLIC_API(JSBool)
 JS_DoubleIsInt32(jsdouble d, jsint *ip);
 
+extern JS_PUBLIC_API(int32)
+JS_DoubleToInt32(jsdouble d);
+
+extern JS_PUBLIC_API(uint32)
+JS_DoubleToUint32(jsdouble d);
+
 /*
  * Convert a value to a number, then to an int32, according to the ECMA rules
  * for ToInt32.
  */
 extern JS_PUBLIC_API(JSBool)
 JS_ValueToECMAInt32(JSContext *cx, jsval v, int32 *ip);
 
 /*