From 8544587944909a30b3f2c4210975b22fde9c2602 Mon Sep 17 00:00:00 2001 From: Andreas Gal Date: Tue, 29 Mar 2011 19:19:15 -0700 Subject: [PATCH] Expose public APIs for converting doubles to signed/unsigned int per ECMA spec (bug 631132, r=bzbarsky). --- js/src/jsapi.cpp | 12 ++++++++++++ js/src/jsapi.h | 6 ++++++ 2 files changed, 18 insertions(+) diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index 66b4cf676bd..3c5bbf91da3 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -520,6 +520,18 @@ 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) { diff --git a/js/src/jsapi.h b/js/src/jsapi.h index eeadeb03e57..ad87606ec97 100644 --- a/js/src/jsapi.h +++ b/js/src/jsapi.h @@ -664,6 +664,12 @@ 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.