45 |
#if defined(XP_WIN) || defined(XP_OS2) |
#if defined(XP_WIN) || defined(XP_OS2) |
46 |
#include <float.h> |
#include <float.h> |
47 |
#endif |
#endif |
48 |
|
#ifdef XP_OS2 |
49 |
|
#define _PC_53 PC_53 |
50 |
|
#define _MCW_EM MCW_EM |
51 |
|
#define _MCW_PC MCW_PC |
52 |
|
#endif |
53 |
#include <locale.h> |
#include <locale.h> |
54 |
#include <limits.h> |
#include <limits.h> |
55 |
#include <math.h> |
#include <math.h> |
266 |
} else { |
} else { |
267 |
v = JSVAL_ZERO; |
v = JSVAL_ZERO; |
268 |
} |
} |
269 |
if (!(cx->fp->flags & JSFRAME_CONSTRUCTING)) { |
if (!JS_IsConstructing(cx)) { |
270 |
*rval = v; |
*rval = v; |
271 |
return JS_TRUE; |
return JS_TRUE; |
272 |
} |
} |
303 |
#endif |
#endif |
304 |
|
|
305 |
/* The buf must be big enough for MIN_INT to fit including '-' and '\0'. */ |
/* The buf must be big enough for MIN_INT to fit including '-' and '\0'. */ |
306 |
char * |
static char * |
307 |
js_IntToCString(jsint i, jsint base, char *buf, size_t bufSize) |
IntToCString(jsint i, jsint base, char *buf, size_t bufSize) |
308 |
{ |
{ |
309 |
char *cp; |
char *cp; |
310 |
jsuint u; |
jsuint u; |
368 |
return JS_FALSE; |
return JS_FALSE; |
369 |
if (base < 2 || base > 36) { |
if (base < 2 || base > 36) { |
370 |
char numBuf[12]; |
char numBuf[12]; |
371 |
char *numStr = js_IntToCString(base, 10, numBuf, sizeof numBuf); |
char *numStr = IntToCString(base, 10, numBuf, sizeof numBuf); |
372 |
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_BAD_RADIX, |
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_BAD_RADIX, |
373 |
numStr); |
numStr); |
374 |
return JS_FALSE; |
return JS_FALSE; |
792 |
return js_NewDoubleInRootedValue(cx, d, vp); |
return js_NewDoubleInRootedValue(cx, d, vp); |
793 |
} |
} |
794 |
|
|
795 |
char * |
JSBool |
796 |
js_NumberToCString(JSContext *cx, jsdouble d, jsint base, char *buf, size_t bufSize) |
js_NewWeaklyRootedNumber(JSContext *cx, jsdouble d, jsval *rval) |
797 |
|
{ |
798 |
|
jsint i; |
799 |
|
if (JSDOUBLE_IS_INT(d, i) && INT_FITS_IN_JSVAL(i)) { |
800 |
|
*rval = INT_TO_JSVAL(i); |
801 |
|
return JS_TRUE; |
802 |
|
} |
803 |
|
return JS_NewDoubleValue(cx, d, rval); |
804 |
|
} |
805 |
|
|
806 |
|
/* |
807 |
|
* Convert a number to C string. The buf must be large enough to accommodate |
808 |
|
* the result, including '-' and '\0', if base == 10 or d is an integer that |
809 |
|
* fits in 32 bits. The caller must free the resulting pointer if it does not |
810 |
|
* point into buf. |
811 |
|
*/ |
812 |
|
static char * |
813 |
|
NumberToCString(JSContext *cx, jsdouble d, jsint base, char *buf, size_t bufSize) |
814 |
{ |
{ |
815 |
jsint i; |
jsint i; |
816 |
char *numStr; |
char *numStr; |
817 |
|
|
818 |
JS_ASSERT(bufSize >= DTOSTR_STANDARD_BUFFER_SIZE); |
JS_ASSERT(bufSize >= DTOSTR_STANDARD_BUFFER_SIZE); |
819 |
if (JSDOUBLE_IS_INT(d, i)) { |
if (JSDOUBLE_IS_INT(d, i)) { |
820 |
numStr = js_IntToCString(i, base, buf, bufSize); |
numStr = IntToCString(i, base, buf, bufSize); |
821 |
} else { |
} else { |
822 |
if (base == 10) |
if (base == 10) |
823 |
numStr = JS_dtostr(buf, bufSize, DTOSTR_STANDARD, 0, d); |
numStr = JS_dtostr(buf, bufSize, DTOSTR_STANDARD, 0, d); |
834 |
static JSString * JS_FASTCALL |
static JSString * JS_FASTCALL |
835 |
NumberToStringWithBase(JSContext *cx, jsdouble d, jsint base) |
NumberToStringWithBase(JSContext *cx, jsdouble d, jsint base) |
836 |
{ |
{ |
837 |
char buf[DTOSTR_STANDARD_BUFFER_SIZE]; |
/* |
838 |
|
* The longest possible result here that would need to fit in buf is |
839 |
|
* (-0x80000000).toString(2), which has length 33. (This can produce |
840 |
|
* longer results, but in those cases buf is not used; see comment at |
841 |
|
* NumberToCString.) |
842 |
|
*/ |
843 |
|
char buf[34]; |
844 |
char *numStr; |
char *numStr; |
845 |
|
JSString *s; |
846 |
|
|
847 |
if (base < 2 || base > 36) |
if (base < 2 || base > 36) |
848 |
return NULL; |
return NULL; |
849 |
numStr = js_NumberToCString(cx, d, base, buf, sizeof buf); |
numStr = NumberToCString(cx, d, base, buf, sizeof buf); |
850 |
if (!numStr) |
if (!numStr) |
851 |
return NULL; |
return NULL; |
852 |
return JS_NewStringCopyZ(cx, numStr); |
s = JS_NewStringCopyZ(cx, numStr); |
853 |
|
if (!(numStr >= buf && numStr < buf + sizeof buf)) |
854 |
|
free(numStr); |
855 |
|
return s; |
856 |
} |
} |
857 |
|
|
858 |
JSString * JS_FASTCALL |
JSString * JS_FASTCALL |