diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index 49acfc9bbc3..f40d6a99f3e 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -127,19 +127,19 @@ JS_Now() JS_PUBLIC_API(jsval) JS_GetNaNValue(JSContext *cx) { - return DOUBLE_TO_JSVAL(cx->runtime->jsNaN); + return cx->runtime->NaNValue; } JS_PUBLIC_API(jsval) JS_GetNegativeInfinityValue(JSContext *cx) { - return DOUBLE_TO_JSVAL(cx->runtime->jsNegativeInfinity); + return cx->runtime->negativeInfinityValue; } JS_PUBLIC_API(jsval) JS_GetPositiveInfinityValue(JSContext *cx) { - return DOUBLE_TO_JSVAL(cx->runtime->jsPositiveInfinity); + return cx->runtime->positiveInfinityValue; } JS_PUBLIC_API(jsval) diff --git a/js/src/jsarray.cpp b/js/src/jsarray.cpp index 272f42e15cf..80075bd056c 100644 --- a/js/src/jsarray.cpp +++ b/js/src/jsarray.cpp @@ -1708,11 +1708,11 @@ InitArrayElements(JSContext *cx, JSObject *obj, jsuint start, jsuint count, jsva JS_ASSERT(start == MAXINDEX); jsval tmp[2] = {JSVAL_NULL, JSVAL_NULL}; - jsdouble* dp = js_NewWeaklyRootedDouble(cx, MAXINDEX); - if (!dp) - return JS_FALSE; - tmp[0] = DOUBLE_TO_JSVAL(dp); JSAutoTempValueRooter tvr(cx, JS_ARRAY_LENGTH(tmp), tmp); + if (!js_NewDoubleInRootedValue(cx, MAXINDEX, &tmp[0])) + return JS_FALSE; + jsdouble *dp = JSVAL_TO_DOUBLE(tmp[0]); + JS_ASSERT(*dp == MAXINDEX); JSAutoTempIdRooter idr(cx); do { tmp[1] = *vector++; diff --git a/js/src/jsbuiltins.cpp b/js/src/jsbuiltins.cpp index f491f3efdc2..6a56e5ba035 100644 --- a/js/src/jsbuiltins.cpp +++ b/js/src/jsbuiltins.cpp @@ -66,8 +66,6 @@ using namespace avmplus; using namespace nanojit; -extern jsdouble js_NaN; - JS_FRIEND_API(void) js_SetTraceableNativeFailed(JSContext *cx) { diff --git a/js/src/jscntxt.h b/js/src/jscntxt.h index faeb4d1f1c1..042b8e8a142 100644 --- a/js/src/jscntxt.h +++ b/js/src/jscntxt.h @@ -533,9 +533,9 @@ struct JSRuntime { JSSetSlotRequest *setSlotRequests; /* Well-known numbers held for use by this runtime's contexts. */ - jsdouble *jsNaN; - jsdouble *jsNegativeInfinity; - jsdouble *jsPositiveInfinity; + jsval NaNValue; + jsval negativeInfinityValue; + jsval positiveInfinityValue; #ifdef JS_THREADSAFE JSLock *deflatedStringCacheLock; diff --git a/js/src/jsdate.cpp b/js/src/jsdate.cpp index 5b0157fcab3..749d33679b2 100644 --- a/js/src/jsdate.cpp +++ b/js/src/jsdate.cpp @@ -478,7 +478,7 @@ msFromTime(jsdouble t) #define TIMECLIP(d) ((JSDOUBLE_IS_FINITE(d) \ && !((d < 0 ? -d : d) > HalfTimeDomain)) \ - ? js_DoubleToInteger(d + (+0.)) : *cx->runtime->jsNaN) + ? js_DoubleToInteger(d + (+0.)) : js_NaN) /** * end of ECMA 'support' functions @@ -595,7 +595,7 @@ date_msecFromArgs(JSContext *cx, uintN argc, jsval *argv, jsdouble *rval) return JS_FALSE; /* return NaN if any arg is not finite */ if (!JSDOUBLE_IS_FINITE(d)) { - *rval = *cx->runtime->jsNaN; + *rval = js_NaN; return JS_TRUE; } array[loop] = js_DoubleToInteger(d); @@ -1164,16 +1164,16 @@ date_parse(JSContext *cx, uintN argc, jsval *vp) jsdouble result; if (argc == 0) { - *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN); - return JS_TRUE; + *vp = cx->runtime->NaNValue; + return true; } str = js_ValueToString(cx, vp[2]); if (!str) return JS_FALSE; vp[2] = STRING_TO_JSVAL(str); if (!date_parseString(str, &result)) { - *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN); - return JS_TRUE; + *vp = cx->runtime->NaNValue; + return true; } result = TIMECLIP(result); @@ -1218,11 +1218,10 @@ SetDateToNaN(JSContext *cx, JSObject *obj, jsval *vp = NULL) { JS_ASSERT(OBJ_GET_CLASS(cx, obj) == &js_DateClass); - jsval nan = DOUBLE_TO_JSVAL(cx->runtime->jsNaN); - obj->fslots[JSSLOT_LOCAL_TIME] = nan; - obj->fslots[JSSLOT_UTC_TIME] = nan; + obj->fslots[JSSLOT_LOCAL_TIME] = cx->runtime->NaNValue; + obj->fslots[JSSLOT_UTC_TIME] = cx->runtime->NaNValue; if (vp) - *vp = nan; + *vp = cx->runtime->NaNValue; } /* @@ -1233,7 +1232,7 @@ SetUTCTime(JSContext *cx, JSObject *obj, jsdouble t, jsval *vp = NULL) { JS_ASSERT(OBJ_GET_CLASS(cx, obj) == &js_DateClass); - obj->fslots[JSSLOT_LOCAL_TIME] = DOUBLE_TO_JSVAL(cx->runtime->jsNaN); + obj->fslots[JSSLOT_LOCAL_TIME] = cx->runtime->NaNValue; if (!js_NewDoubleInRootedValue(cx, t, &obj->fslots[JSSLOT_UTC_TIME])) return false; if (vp) @@ -1248,33 +1247,24 @@ SetUTCTime(JSContext *cx, JSObject *obj, jsdouble t, jsval *vp = NULL) static JSBool GetAndCacheLocalTime(JSContext *cx, JSObject *obj, jsval *vp, jsdouble *dp) { - jsval v; - jsdouble result; - jsdouble *cached; - if (!obj || !JS_InstanceOf(cx, obj, &js_DateClass, vp ? vp + 2 : NULL)) - return JS_FALSE; - v = obj->fslots[JSSLOT_LOCAL_TIME]; - - result = *JSVAL_TO_DOUBLE(v); + return false; + jsval *slotp = &obj->fslots[JSSLOT_LOCAL_TIME]; + jsdouble result = *JSVAL_TO_DOUBLE(*vp); if (JSDOUBLE_IS_NaN(result)) { - if (!GetUTCTime(cx, obj, vp, &result)) - return JS_FALSE; + result = *JSVAL_TO_DOUBLE(obj->fslots[JSSLOT_UTC_TIME]); /* if result is NaN, it couldn't be finite. */ if (JSDOUBLE_IS_FINITE(result)) result = LocalTime(result); - cached = js_NewWeaklyRootedDouble(cx, result); - if (!cached) - return JS_FALSE; - - obj->fslots[JSSLOT_LOCAL_TIME] = DOUBLE_TO_JSVAL(cached); + if (!js_NewDoubleInRootedValue(cx, result, slotp)) + return false; } *dp = result; - return JS_TRUE; + return true; } /* diff --git a/js/src/jsmath.cpp b/js/src/jsmath.cpp index 53e4c69eade..b26a0ae678f 100644 --- a/js/src/jsmath.cpp +++ b/js/src/jsmath.cpp @@ -56,8 +56,6 @@ #include "jslibmath.h" #include "jsobj.h" -extern jsdouble js_NaN; - #ifndef M_E #define M_E 2.7182818284590452354 #endif @@ -109,7 +107,7 @@ math_abs(JSContext *cx, uintN argc, jsval *vp) jsdouble x, z; if (argc == 0) { - *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN); + *vp = cx->runtime->NaNValue; return JS_TRUE; } x = js_ValueToNumber(cx, &vp[2]); @@ -125,7 +123,7 @@ math_acos(JSContext *cx, uintN argc, jsval *vp) jsdouble x, z; if (argc == 0) { - *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN); + *vp = cx->runtime->NaNValue; return JS_TRUE; } x = js_ValueToNumber(cx, &vp[2]); @@ -133,7 +131,7 @@ math_acos(JSContext *cx, uintN argc, jsval *vp) return JS_FALSE; #if defined(SOLARIS) && defined(__GNUC__) if (x < -1 || 1 < x) { - *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN); + *vp = cx->runtime->NaNValue; return JS_TRUE; } #endif @@ -147,7 +145,7 @@ math_asin(JSContext *cx, uintN argc, jsval *vp) jsdouble x, z; if (argc == 0) { - *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN); + *vp = cx->runtime->NaNValue; return JS_TRUE; } x = js_ValueToNumber(cx, &vp[2]); @@ -155,7 +153,7 @@ math_asin(JSContext *cx, uintN argc, jsval *vp) return JS_FALSE; #if defined(SOLARIS) && defined(__GNUC__) if (x < -1 || 1 < x) { - *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN); + *vp = cx->runtime->NaNValue; return JS_TRUE; } #endif @@ -169,7 +167,7 @@ math_atan(JSContext *cx, uintN argc, jsval *vp) jsdouble x, z; if (argc == 0) { - *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN); + *vp = cx->runtime->NaNValue; return JS_TRUE; } x = js_ValueToNumber(cx, &vp[2]); @@ -215,7 +213,7 @@ math_atan2(JSContext *cx, uintN argc, jsval *vp) jsdouble x, y; if (argc <= 1) { - *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN); + *vp = cx->runtime->NaNValue; return JS_TRUE; } x = js_ValueToNumber(cx, &vp[2]); @@ -243,7 +241,7 @@ js_math_ceil(JSContext *cx, uintN argc, jsval *vp) jsdouble x, z; if (argc == 0) { - *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN); + *vp = cx->runtime->NaNValue; return JS_TRUE; } x = js_ValueToNumber(cx, &vp[2]); @@ -259,7 +257,7 @@ math_cos(JSContext *cx, uintN argc, jsval *vp) jsdouble x, z; if (argc == 0) { - *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN); + *vp = cx->runtime->NaNValue; return JS_TRUE; } x = js_ValueToNumber(cx, &vp[2]); @@ -275,7 +273,7 @@ math_exp(JSContext *cx, uintN argc, jsval *vp) jsdouble x, z; if (argc == 0) { - *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN); + *vp = cx->runtime->NaNValue; return JS_TRUE; } x = js_ValueToNumber(cx, &vp[2]); @@ -283,11 +281,11 @@ math_exp(JSContext *cx, uintN argc, jsval *vp) return JS_FALSE; #ifdef _WIN32 if (!JSDOUBLE_IS_NaN(x)) { - if (x == *cx->runtime->jsPositiveInfinity) { - *vp = DOUBLE_TO_JSVAL(cx->runtime->jsPositiveInfinity); + if (x == js_PositiveInfinity) { + *vp = cx->runtime->positiveInfinityValue; return JS_TRUE; } - if (x == *cx->runtime->jsNegativeInfinity) { + if (x == js_NegativeInfinity) { *vp = JSVAL_ZERO; return JS_TRUE; } @@ -303,7 +301,7 @@ js_math_floor(JSContext *cx, uintN argc, jsval *vp) jsdouble x, z; if (argc == 0) { - *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN); + *vp = cx->runtime->NaNValue; return JS_TRUE; } x = js_ValueToNumber(cx, &vp[2]); @@ -319,7 +317,7 @@ math_log(JSContext *cx, uintN argc, jsval *vp) jsdouble x, z; if (argc == 0) { - *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN); + *vp = cx->runtime->NaNValue; return JS_TRUE; } x = js_ValueToNumber(cx, &vp[2]); @@ -327,7 +325,7 @@ math_log(JSContext *cx, uintN argc, jsval *vp) return JS_FALSE; #if defined(SOLARIS) && defined(__GNUC__) if (x < 0) { - *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN); + *vp = cx->runtime->NaNValue; return JS_TRUE; } #endif @@ -338,12 +336,12 @@ math_log(JSContext *cx, uintN argc, jsval *vp) JSBool js_math_max(JSContext *cx, uintN argc, jsval *vp) { - jsdouble x, z = *cx->runtime->jsNegativeInfinity; + jsdouble x, z = js_NegativeInfinity; jsval *argv; uintN i; if (argc == 0) { - *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNegativeInfinity); + *vp = cx->runtime->negativeInfinityValue; return JS_TRUE; } argv = vp + 2; @@ -352,7 +350,7 @@ js_math_max(JSContext *cx, uintN argc, jsval *vp) if (JSVAL_IS_NULL(argv[i])) return JS_FALSE; if (JSDOUBLE_IS_NaN(x)) { - *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN); + *vp = cx->runtime->NaNValue; return JS_TRUE; } if (x == 0 && x == z) { @@ -368,12 +366,12 @@ js_math_max(JSContext *cx, uintN argc, jsval *vp) JSBool js_math_min(JSContext *cx, uintN argc, jsval *vp) { - jsdouble x, z = *cx->runtime->jsPositiveInfinity; + jsdouble x, z = js_PositiveInfinity; jsval *argv; uintN i; if (argc == 0) { - *vp = DOUBLE_TO_JSVAL(cx->runtime->jsPositiveInfinity); + *vp = cx->runtime->positiveInfinityValue; return JS_TRUE; } argv = vp + 2; @@ -382,7 +380,7 @@ js_math_min(JSContext *cx, uintN argc, jsval *vp) if (JSVAL_IS_NULL(argv[i])) return JS_FALSE; if (JSDOUBLE_IS_NaN(x)) { - *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN); + *vp = cx->runtime->NaNValue; return JS_TRUE; } if (x == 0 && x == z) { @@ -401,7 +399,7 @@ math_pow(JSContext *cx, uintN argc, jsval *vp) jsdouble x, y, z; if (argc <= 1) { - *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN); + *vp = cx->runtime->NaNValue; return JS_TRUE; } x = js_ValueToNumber(cx, &vp[2]); @@ -415,7 +413,7 @@ math_pow(JSContext *cx, uintN argc, jsval *vp) * we need to wrap the libm call to make it ECMA compliant. */ if (!JSDOUBLE_IS_FINITE(y) && (x == 1.0 || x == -1.0)) { - *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN); + *vp = cx->runtime->NaNValue; return JS_TRUE; } /* pow(x, +-0) is always 1, even for x = NaN. */ @@ -492,7 +490,7 @@ js_math_round(JSContext *cx, uintN argc, jsval *vp) jsdouble x, z; if (argc == 0) { - *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN); + *vp = cx->runtime->NaNValue; return JS_TRUE; } x = js_ValueToNumber(cx, &vp[2]); @@ -508,7 +506,7 @@ math_sin(JSContext *cx, uintN argc, jsval *vp) jsdouble x, z; if (argc == 0) { - *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN); + *vp = cx->runtime->NaNValue; return JS_TRUE; } x = js_ValueToNumber(cx, &vp[2]); @@ -524,7 +522,7 @@ math_sqrt(JSContext *cx, uintN argc, jsval *vp) jsdouble x, z; if (argc == 0) { - *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN); + *vp = cx->runtime->NaNValue; return JS_TRUE; } x = js_ValueToNumber(cx, &vp[2]); @@ -540,7 +538,7 @@ math_tan(JSContext *cx, uintN argc, jsval *vp) jsdouble x, z; if (argc == 0) { - *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN); + *vp = cx->runtime->NaNValue; return JS_TRUE; } x = js_ValueToNumber(cx, &vp[2]); @@ -602,12 +600,10 @@ static jsdouble FASTCALL math_exp_tn(JSContext *cx, jsdouble d) { if (!JSDOUBLE_IS_NaN(d)) { - if (d == *cx->runtime->jsPositiveInfinity) { - return *cx->runtime->jsPositiveInfinity; - } - if (d == *cx->runtime->jsNegativeInfinity) { + if (d == js_PositiveInfinity) + return js_PositiveInfinity; + if (d == js_NegativeInfinity) return 0.0; - } } return exp(d); } diff --git a/js/src/jsnum.cpp b/js/src/jsnum.cpp index 9cb21293752..43dc6874b2f 100644 --- a/js/src/jsnum.cpp +++ b/js/src/jsnum.cpp @@ -141,7 +141,7 @@ num_parseFloat(JSContext *cx, uintN argc, jsval *vp) const jschar *bp, *end, *ep; if (argc == 0) { - *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN); + *vp = cx->runtime->NaNValue; return JS_TRUE; } str = js_ValueToString(cx, vp[2]); @@ -151,7 +151,7 @@ num_parseFloat(JSContext *cx, uintN argc, jsval *vp) if (!js_strtod(cx, bp, end, &ep, &d)) return JS_FALSE; if (ep == bp) { - *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN); + *vp = cx->runtime->NaNValue; return JS_TRUE; } return js_NewNumberInRootedValue(cx, d, vp); @@ -183,7 +183,7 @@ num_parseInt(JSContext *cx, uintN argc, jsval *vp) const jschar *bp, *end, *ep; if (argc == 0) { - *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN); + *vp = cx->runtime->NaNValue; return JS_TRUE; } if (argc > 1) { @@ -194,7 +194,7 @@ num_parseInt(JSContext *cx, uintN argc, jsval *vp) radix = 0; } if (radix != 0 && (radix < 2 || radix > 36)) { - *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN); + *vp = cx->runtime->NaNValue; return JS_TRUE; } @@ -210,7 +210,7 @@ num_parseInt(JSContext *cx, uintN argc, jsval *vp) if (!js_strtointeger(cx, bp, end, &ep, radix, &d)) return JS_FALSE; if (ep == bp) { - *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN); + *vp = cx->runtime->NaNValue; return JS_TRUE; } return js_NewNumberInRootedValue(cx, d, vp); @@ -669,7 +669,8 @@ static JSConstDoubleSpec number_constants[] = { }; jsdouble js_NaN; - +jsdouble js_PositiveInfinity; +jsdouble js_NegativeInfinity; #if (defined __GNUC__ && defined __i386__) @@ -694,41 +695,37 @@ inline void FIX_FPU() { JSBool js_InitRuntimeNumberState(JSContext *cx) { - JSRuntime *rt; - jsdpun u; - struct lconv *locale; + JS_STATIC_ASSERT(JSVAL_NULL == jsval(0)); - rt = cx->runtime; - JS_ASSERT(!rt->jsNaN); + JSRuntime *rt = cx->runtime; + JS_ASSERT(JSVAL_IS_NULL(rt->NaNValue)); FIX_FPU(); + jsdpun u; u.s.hi = JSDOUBLE_HI32_EXPMASK | JSDOUBLE_HI32_MANTMASK; u.s.lo = 0xffffffff; number_constants[NC_NaN].dval = js_NaN = u.d; - rt->jsNaN = js_NewWeaklyRootedDouble(cx, js_NaN); - if (!rt->jsNaN) - return JS_FALSE; + if (!js_NewDoubleInRootedValue(cx, u.d, &rt->NaNValue)) + return false; u.s.hi = JSDOUBLE_HI32_EXPMASK; u.s.lo = 0x00000000; - number_constants[NC_POSITIVE_INFINITY].dval = u.d; - rt->jsPositiveInfinity = js_NewWeaklyRootedDouble(cx, u.d); - if (!rt->jsPositiveInfinity) - return JS_FALSE; + number_constants[NC_POSITIVE_INFINITY].dval = js_PositiveInfinity = u.d; + if (!js_NewDoubleInRootedValue(cx, u.d, &rt->positiveInfinityValue)) + return false; u.s.hi = JSDOUBLE_HI32_SIGNBIT | JSDOUBLE_HI32_EXPMASK; u.s.lo = 0x00000000; - number_constants[NC_NEGATIVE_INFINITY].dval = u.d; - rt->jsNegativeInfinity = js_NewWeaklyRootedDouble(cx, u.d); - if (!rt->jsNegativeInfinity) - return JS_FALSE; + number_constants[NC_NEGATIVE_INFINITY].dval = js_NegativeInfinity = u.d; + if (!js_NewDoubleInRootedValue(cx, u.d, &rt->negativeInfinityValue)) + return false; u.s.hi = 0; u.s.lo = 1; number_constants[NC_MIN_VALUE].dval = u.d; - locale = localeconv(); + struct lconv *locale = localeconv(); rt->thousandsSeparator = JS_strdup(cx, locale->thousands_sep ? locale->thousands_sep : "'"); rt->decimalSeparator = @@ -742,15 +739,18 @@ js_InitRuntimeNumberState(JSContext *cx) void js_TraceRuntimeNumberState(JSTracer *trc) { - JSRuntime *rt; + JSRuntime *rt = trc->context->runtime; - rt = trc->context->runtime; - if (rt->jsNaN) - JS_CALL_DOUBLE_TRACER(trc, rt->jsNaN, "NaN"); - if (rt->jsPositiveInfinity) - JS_CALL_DOUBLE_TRACER(trc, rt->jsPositiveInfinity, "+Infinity"); - if (rt->jsNegativeInfinity) - JS_CALL_DOUBLE_TRACER(trc, rt->jsNegativeInfinity, "-Infinity"); + if (!JSVAL_IS_NULL(rt->NaNValue)) + JS_CALL_DOUBLE_TRACER(trc, JSVAL_TO_DOUBLE(rt->NaNValue), "NaN"); + if (!JSVAL_IS_NULL(rt->positiveInfinityValue)) { + JS_CALL_DOUBLE_TRACER(trc, JSVAL_TO_DOUBLE(rt->positiveInfinityValue), + "+Infinity"); + } + if (!JSVAL_IS_NULL(rt->negativeInfinityValue)) { + JS_CALL_DOUBLE_TRACER(trc, JSVAL_TO_DOUBLE(rt->negativeInfinityValue), + "-Infinity"); + } } void @@ -758,13 +758,13 @@ js_FinishRuntimeNumberState(JSContext *cx) { JSRuntime *rt = cx->runtime; - rt->jsNaN = NULL; - rt->jsNegativeInfinity = NULL; - rt->jsPositiveInfinity = NULL; + rt->NaNValue = JSVAL_NULL; + rt->negativeInfinityValue = JSVAL_NULL; + rt->positiveInfinityValue = JSVAL_NULL; - cx->free((void *)rt->thousandsSeparator); - cx->free((void *)rt->decimalSeparator); - cx->free((void *)rt->numGrouping); + cx->free((void *) rt->thousandsSeparator); + cx->free((void *) rt->decimalSeparator); + cx->free((void *) rt->numGrouping); rt->thousandsSeparator = rt->decimalSeparator = rt->numGrouping = NULL; } @@ -790,14 +790,13 @@ js_InitNumberClass(JSContext *cx, JSObject *obj) /* ECMA 15.1.1.1 */ rt = cx->runtime; - if (!JS_DefineProperty(cx, obj, js_NaN_str, DOUBLE_TO_JSVAL(rt->jsNaN), + if (!JS_DefineProperty(cx, obj, js_NaN_str, rt->NaNValue, NULL, NULL, JSPROP_PERMANENT)) { return NULL; } /* ECMA 15.1.1.2 */ - if (!JS_DefineProperty(cx, obj, js_Infinity_str, - DOUBLE_TO_JSVAL(rt->jsPositiveInfinity), + if (!JS_DefineProperty(cx, obj, js_Infinity_str, rt->positiveInfinityValue, NULL, NULL, JSPROP_PERMANENT)) { return NULL; } @@ -942,7 +941,7 @@ js_ValueToNumber(JSContext *cx, jsval *vp) jsval v; JSString *str; const jschar *bp, *end, *ep; - jsdouble d, *dp; + jsdouble d; JSObject *obj; v = *vp; @@ -1020,9 +1019,8 @@ js_ValueToNumber(JSContext *cx, jsval *vp) break; } - dp = cx->runtime->jsNaN; - *vp = DOUBLE_TO_JSVAL(dp); - return *dp; + *vp = cx->runtime->NaNValue; + return js_NaN; } int32 @@ -1193,15 +1191,15 @@ js_strtod(JSContext *cx, const jschar *s, const jschar *send, if ((negative = (*istr == '-')) != 0 || *istr == '+') istr++; if (*istr == 'I' && !strncmp(istr, js_Infinity_str, sizeof js_Infinity_str - 1)) { - d = *(negative ? cx->runtime->jsNegativeInfinity : cx->runtime->jsPositiveInfinity); + d = negative ? js_NegativeInfinity : js_PositiveInfinity; estr = istr + 8; } else { int err; d = JS_strtod(cstr, &estr, &err); if (d == HUGE_VAL) - d = *cx->runtime->jsPositiveInfinity; + d = js_PositiveInfinity; else if (d == -HUGE_VAL) - d = *cx->runtime->jsNegativeInfinity; + d = js_NegativeInfinity; } i = estr - cstr; @@ -1336,7 +1334,7 @@ js_strtointeger(JSContext *cx, const jschar *s, const jschar *send, return JS_FALSE; } if (err == JS_DTOA_ERANGE && value == HUGE_VAL) - value = *cx->runtime->jsPositiveInfinity; + value = js_PositiveInfinity; cx->free(cstr); } else if ((base & (base - 1)) == 0) { /* diff --git a/js/src/jsnum.h b/js/src/jsnum.h index dea4737df00..f3e7a253dfe 100644 --- a/js/src/jsnum.h +++ b/js/src/jsnum.h @@ -169,6 +169,8 @@ JS_HASH_DOUBLE(jsdouble d) #endif extern jsdouble js_NaN; +extern jsdouble js_PositiveInfinity; +extern jsdouble js_NegativeInfinity; /* Initialize number constants and runtime state for the first context. */ extern JSBool diff --git a/js/src/jsops.cpp b/js/src/jsops.cpp index 5d0dab85116..1448943c5fb 100644 --- a/js/src/jsops.cpp +++ b/js/src/jsops.cpp @@ -1095,15 +1095,15 @@ BEGIN_CASE(JSOP_DIV) #ifdef XP_WIN /* XXX MSVC miscompiles such that (NaN == 0) */ if (JSDOUBLE_IS_NaN(d2)) - rval = DOUBLE_TO_JSVAL(rt->jsNaN); + rval = rt->NaNValue; else #endif if (d == 0 || JSDOUBLE_IS_NaN(d)) - rval = DOUBLE_TO_JSVAL(rt->jsNaN); + rval = rt->NaNValue; else if (JSDOUBLE_IS_NEG(d) != JSDOUBLE_IS_NEG(d2)) - rval = DOUBLE_TO_JSVAL(rt->jsNegativeInfinity); + rval = rt->negativeInfinityValue; else - rval = DOUBLE_TO_JSVAL(rt->jsPositiveInfinity); + rval = rt->positiveInfinityValue; STORE_OPND(-1, rval); } else { d /= d2; @@ -1116,7 +1116,7 @@ BEGIN_CASE(JSOP_MOD) FETCH_NUMBER(cx, -2, d); regs.sp--; if (d2 == 0) { - STORE_OPND(-1, DOUBLE_TO_JSVAL(rt->jsNaN)); + STORE_OPND(-1, rt->NaNValue); } else { d = js_fmod(d, d2); STORE_NUMBER(cx, -1, d); diff --git a/js/src/jsparse.cpp b/js/src/jsparse.cpp index cfba4a438ec..0880b060278 100644 --- a/js/src/jsparse.cpp +++ b/js/src/jsparse.cpp @@ -8449,15 +8449,15 @@ FoldBinaryNumeric(JSContext *cx, JSOp op, JSParseNode *pn1, JSParseNode *pn2, #if defined(XP_WIN) /* XXX MSVC miscompiles such that (NaN == 0) */ if (JSDOUBLE_IS_NaN(d2)) - d = *cx->runtime->jsNaN; + d = js_NaN; else #endif if (d == 0 || JSDOUBLE_IS_NaN(d)) - d = *cx->runtime->jsNaN; + d = js_NaN; else if (JSDOUBLE_IS_NEG(d) != JSDOUBLE_IS_NEG(d2)) - d = *cx->runtime->jsNegativeInfinity; + d = js_NegativeInfinity; else - d = *cx->runtime->jsPositiveInfinity; + d = js_PositiveInfinity; } else { d /= d2; } @@ -8465,7 +8465,7 @@ FoldBinaryNumeric(JSContext *cx, JSOp op, JSParseNode *pn1, JSParseNode *pn2, case JSOP_MOD: if (d2 == 0) { - d = *cx->runtime->jsNaN; + d = js_NaN; } else { d = js_fmod(d, d2); } diff --git a/js/src/jsstr.cpp b/js/src/jsstr.cpp index 5a54d566b29..cf8405850bb 100644 --- a/js/src/jsstr.cpp +++ b/js/src/jsstr.cpp @@ -1004,7 +1004,6 @@ out_of_range: } #ifdef JS_TRACER -extern jsdouble js_NaN; jsdouble FASTCALL js_String_p_charCodeAt(JSString* str, jsdouble d) diff --git a/js/src/jstracer.cpp b/js/src/jstracer.cpp index 548be2d9da8..acca03c7365 100644 --- a/js/src/jstracer.cpp +++ b/js/src/jstracer.cpp @@ -8659,7 +8659,7 @@ TraceRecorder::equalityHelper(jsval l, jsval r, LIns* l_ins, LIns* r_ins, args[0] = l_ins, args[1] = cx_ins; l_ins = lir->insCall(&js_BooleanOrUndefinedToNumber_ci, args); l = (l == JSVAL_VOID) - ? DOUBLE_TO_JSVAL(cx->runtime->jsNaN) + ? cx->runtime->NaNValue : INT_TO_JSVAL(l == JSVAL_TRUE); return equalityHelper(l, r, l_ins, r_ins, negate, tryBranchAfterCond, rval); @@ -8673,7 +8673,7 @@ TraceRecorder::equalityHelper(jsval l, jsval r, LIns* l_ins, LIns* r_ins, args[0] = r_ins, args[1] = cx_ins; r_ins = lir->insCall(&js_BooleanOrUndefinedToNumber_ci, args); r = (r == JSVAL_VOID) - ? DOUBLE_TO_JSVAL(cx->runtime->jsNaN) + ? cx->runtime->NaNValue : INT_TO_JSVAL(r == JSVAL_TRUE); return equalityHelper(l, r, l_ins, r_ins, negate, tryBranchAfterCond, rval); diff --git a/js/src/jsxml.cpp b/js/src/jsxml.cpp index 53df64fa418..de62a2bbfa5 100644 --- a/js/src/jsxml.cpp +++ b/js/src/jsxml.cpp @@ -5578,7 +5578,7 @@ xml_childIndex(JSContext *cx, uintN argc, jsval *vp) NON_LIST_XML_METHOD_PROLOG; parent = xml->parent; if (!parent || xml->xml_class == JSXML_CLASS_ATTRIBUTE) { - *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN); + *vp = cx->runtime->NaNValue; return JS_TRUE; } for (i = 0, n = JSXML_LENGTH(parent); i < n; i++) {