Bug 858131 - rewrite FloatingPoint.h to be C++-only instead of C-compatible C++; r+original-author=Waldo

This commit is contained in:
Nathan Froyd
2013-05-01 16:55:13 -04:00
parent a8c98e44fe
commit d80f045a6c
57 changed files with 344 additions and 319 deletions

View File

@@ -53,6 +53,8 @@ using namespace js;
using namespace js::types;
using mozilla::ArrayLength;
using mozilla::IsFinite;
using mozilla::IsNaN;
/*
* The JS 'Date' object is patterned after the Java 'Date' object.
@@ -128,7 +130,7 @@ IsLeapYear(double year)
inline double
DaysInYear(double year)
{
if (!MOZ_DOUBLE_IS_FINITE(year))
if (!IsFinite(year))
return js_NaN;
return IsLeapYear(year) ? 366 : 365;
}
@@ -151,7 +153,7 @@ TimeFromYear(double y)
static double
YearFromTime(double t)
{
if (!MOZ_DOUBLE_IS_FINITE(t))
if (!IsFinite(t))
return js_NaN;
JS_ASSERT(ToInteger(t) == t);
@@ -183,14 +185,14 @@ DaysInFebruary(double year)
inline double
DayWithinYear(double t, double year)
{
JS_ASSERT_IF(MOZ_DOUBLE_IS_FINITE(t), YearFromTime(t) == year);
JS_ASSERT_IF(IsFinite(t), YearFromTime(t) == year);
return Day(t) - DayFromYear(year);
}
static double
MonthFromTime(double t)
{
if (!MOZ_DOUBLE_IS_FINITE(t))
if (!IsFinite(t))
return js_NaN;
double year = YearFromTime(t);
@@ -226,7 +228,7 @@ MonthFromTime(double t)
static double
DateFromTime(double t)
{
if (!MOZ_DOUBLE_IS_FINITE(t))
if (!IsFinite(t))
return js_NaN;
double year = YearFromTime(t);
@@ -309,7 +311,7 @@ static double
MakeDay(double year, double month, double date)
{
/* Step 1. */
if (!MOZ_DOUBLE_IS_FINITE(year) || !MOZ_DOUBLE_IS_FINITE(month) || !MOZ_DOUBLE_IS_FINITE(date))
if (!IsFinite(year) || !IsFinite(month) || !IsFinite(date))
return js_NaN;
/* Steps 2-4. */
@@ -339,7 +341,7 @@ inline double
MakeDate(double day, double time)
{
/* Step 1. */
if (!MOZ_DOUBLE_IS_FINITE(day) || !MOZ_DOUBLE_IS_FINITE(time))
if (!IsFinite(day) || !IsFinite(time))
return js_NaN;
/* Step 2. */
@@ -405,7 +407,7 @@ EquivalentYearForDST(int year)
static double
DaylightSavingTA(double t, DateTimeInfo *dtInfo)
{
if (!MOZ_DOUBLE_IS_FINITE(t))
if (!IsFinite(t))
return js_NaN;
/*
@@ -486,10 +488,10 @@ static double
MakeTime(double hour, double min, double sec, double ms)
{
/* Step 1. */
if (!MOZ_DOUBLE_IS_FINITE(hour) ||
!MOZ_DOUBLE_IS_FINITE(min) ||
!MOZ_DOUBLE_IS_FINITE(sec) ||
!MOZ_DOUBLE_IS_FINITE(ms))
if (!IsFinite(hour) ||
!IsFinite(min) ||
!IsFinite(sec) ||
!IsFinite(ms))
{
return js_NaN;
}
@@ -619,7 +621,7 @@ date_msecFromArgs(JSContext *cx, CallArgs args, double *rval)
if (!ToNumber(cx, args[loop], &d))
return JS_FALSE;
/* return NaN if any arg is not finite */
if (!MOZ_DOUBLE_IS_FINITE(d)) {
if (!IsFinite(d)) {
*rval = js_NaN;
return JS_TRUE;
}
@@ -1281,7 +1283,7 @@ FillLocalTimeSlots(DateTimeInfo *dtInfo, JSObject *obj)
double utcTime = obj->getDateUTCTime().toNumber();
if (!MOZ_DOUBLE_IS_FINITE(utcTime)) {
if (!IsFinite(utcTime)) {
for (size_t ind = JSObject::JSSLOT_DATE_COMPONENTS_START;
ind < JSObject::DATE_CLASS_RESERVED_SLOTS;
ind++) {
@@ -1483,7 +1485,7 @@ date_getUTCFullYear_impl(JSContext *cx, CallArgs args)
JS_ASSERT(IsDate(args.thisv()));
double result = args.thisv().toObject().getDateUTCTime().toNumber();
if (MOZ_DOUBLE_IS_FINITE(result))
if (IsFinite(result))
result = YearFromTime(result);
args.rval().setNumber(result);
@@ -1558,7 +1560,7 @@ date_getUTCDate_impl(JSContext *cx, CallArgs args)
JS_ASSERT(IsDate(args.thisv()));
double result = args.thisv().toObject().getDateUTCTime().toNumber();
if (MOZ_DOUBLE_IS_FINITE(result))
if (IsFinite(result))
result = DateFromTime(result);
args.rval().setNumber(result);
@@ -1597,7 +1599,7 @@ date_getUTCDay_impl(JSContext *cx, CallArgs args)
JS_ASSERT(IsDate(args.thisv()));
double result = args.thisv().toObject().getDateUTCTime().toNumber();
if (MOZ_DOUBLE_IS_FINITE(result))
if (IsFinite(result))
result = WeekDay(result);
args.rval().setNumber(result);
@@ -1636,7 +1638,7 @@ date_getUTCHours_impl(JSContext *cx, CallArgs args)
JS_ASSERT(IsDate(args.thisv()));
double result = args.thisv().toObject().getDateUTCTime().toNumber();
if (MOZ_DOUBLE_IS_FINITE(result))
if (IsFinite(result))
result = HourFromTime(result);
args.rval().setNumber(result);
@@ -1675,7 +1677,7 @@ date_getUTCMinutes_impl(JSContext *cx, CallArgs args)
JS_ASSERT(IsDate(args.thisv()));
double result = args.thisv().toObject().getDateUTCTime().toNumber();
if (MOZ_DOUBLE_IS_FINITE(result))
if (IsFinite(result))
result = MinFromTime(result);
args.rval().setNumber(result);
@@ -1718,7 +1720,7 @@ date_getUTCMilliseconds_impl(JSContext *cx, CallArgs args)
JS_ASSERT(IsDate(args.thisv()));
double result = args.thisv().toObject().getDateUTCTime().toNumber();
if (MOZ_DOUBLE_IS_FINITE(result))
if (IsFinite(result))
result = msFromTime(result);
args.rval().setNumber(result);
@@ -2312,7 +2314,7 @@ static double
ThisLocalTimeOrZero(HandleObject date, DateTimeInfo *dtInfo)
{
double t = date->getDateUTCTime().toNumber();
if (MOZ_DOUBLE_IS_NaN(t))
if (IsNaN(t))
return +0;
return LocalTime(t, dtInfo);
}
@@ -2321,7 +2323,7 @@ static double
ThisUTCTimeOrZero(HandleObject date)
{
double t = date->getDateUTCTime().toNumber();
return MOZ_DOUBLE_IS_NaN(t) ? +0 : t;
return IsNaN(t) ? +0 : t;
}
/* ES5 15.9.5.40. */
@@ -2429,7 +2431,7 @@ date_setYear_impl(JSContext *cx, CallArgs args)
return false;
/* Step 3. */
if (MOZ_DOUBLE_IS_NaN(y)) {
if (IsNaN(y)) {
SetUTCTime(thisObj, js_NaN, args.rval().address());
return true;
}
@@ -2508,7 +2510,7 @@ date_toGMTString_impl(JSContext *cx, CallArgs args)
double utctime = args.thisv().toObject().getDateUTCTime().toNumber();
char buf[100];
if (!MOZ_DOUBLE_IS_FINITE(utctime))
if (!IsFinite(utctime))
JS_snprintf(buf, sizeof buf, js_NaN_date_str);
else
print_gmt_string(buf, sizeof buf, utctime);
@@ -2534,7 +2536,7 @@ date_toISOString_impl(JSContext *cx, CallArgs args)
JS_ASSERT(IsDate(args.thisv()));
double utctime = args.thisv().toObject().getDateUTCTime().toNumber();
if (!MOZ_DOUBLE_IS_FINITE(utctime)) {
if (!IsFinite(utctime)) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_INVALID_DATE);
return false;
}
@@ -2574,7 +2576,7 @@ date_toJSON(JSContext *cx, unsigned argc, Value *vp)
return false;
/* Step 3. */
if (tv.isDouble() && !MOZ_DOUBLE_IS_FINITE(tv.toDouble())) {
if (tv.isDouble() && !IsFinite(tv.toDouble())) {
args.rval().setNull();
return true;
}
@@ -2641,7 +2643,7 @@ date_format(JSContext *cx, double date, formatspec format, MutableHandleValue rv
size_t i, tzlen;
PRMJTime split;
if (!MOZ_DOUBLE_IS_FINITE(date)) {
if (!IsFinite(date)) {
JS_snprintf(buf, sizeof buf, js_NaN_date_str);
} else {
JS_ASSERT(TimeClip(date) == date);
@@ -2752,7 +2754,7 @@ ToLocaleFormatHelper(JSContext *cx, HandleObject obj, const char *format, Mutabl
double utctime = obj->getDateUTCTime().toNumber();
char buf[100];
if (!MOZ_DOUBLE_IS_FINITE(utctime)) {
if (!IsFinite(utctime)) {
JS_snprintf(buf, sizeof buf, js_NaN_date_str);
} else {
int result_len;
@@ -3120,7 +3122,7 @@ js_Date(JSContext *cx, unsigned argc, Value *vp)
if (!date_msecFromArgs(cx, args, &msec_time))
return false;
if (MOZ_DOUBLE_IS_FINITE(msec_time)) {
if (IsFinite(msec_time)) {
msec_time = UTC(msec_time, &cx->runtime->dateTimeInfo);
msec_time = TimeClip(msec_time);
}
@@ -3203,7 +3205,7 @@ js_NewDateObject(JSContext *cx, int year, int mon, int mday,
JS_FRIEND_API(JSBool)
js_DateIsValid(JSObject *obj)
{
return obj->isDate() && !MOZ_DOUBLE_IS_NaN(obj->getDateUTCTime().toNumber());
return obj->isDate() && !IsNaN(obj->getDateUTCTime().toNumber());
}
JS_FRIEND_API(int)
@@ -3212,7 +3214,7 @@ js_DateGetYear(JSContext *cx, JSObject *obj)
/* Preserve legacy API behavior of returning 0 for invalid dates. */
JS_ASSERT(obj);
double localtime = GetCachedLocalTime(&cx->runtime->dateTimeInfo, obj);
if (MOZ_DOUBLE_IS_NaN(localtime))
if (IsNaN(localtime))
return 0;
return (int) YearFromTime(localtime);
@@ -3223,7 +3225,7 @@ js_DateGetMonth(JSContext *cx, JSObject *obj)
{
JS_ASSERT(obj);
double localtime = GetCachedLocalTime(&cx->runtime->dateTimeInfo, obj);
if (MOZ_DOUBLE_IS_NaN(localtime))
if (IsNaN(localtime))
return 0;
return (int) MonthFromTime(localtime);
@@ -3234,7 +3236,7 @@ js_DateGetDate(JSContext *cx, JSObject *obj)
{
JS_ASSERT(obj);
double localtime = GetCachedLocalTime(&cx->runtime->dateTimeInfo, obj);
if (MOZ_DOUBLE_IS_NaN(localtime))
if (IsNaN(localtime))
return 0;
return (int) DateFromTime(localtime);
@@ -3245,7 +3247,7 @@ js_DateGetHours(JSContext *cx, JSObject *obj)
{
JS_ASSERT(obj);
double localtime = GetCachedLocalTime(&cx->runtime->dateTimeInfo, obj);
if (MOZ_DOUBLE_IS_NaN(localtime))
if (IsNaN(localtime))
return 0;
return (int) HourFromTime(localtime);
@@ -3256,7 +3258,7 @@ js_DateGetMinutes(JSContext *cx, JSObject *obj)
{
JS_ASSERT(obj);
double localtime = GetCachedLocalTime(&cx->runtime->dateTimeInfo, obj);
if (MOZ_DOUBLE_IS_NaN(localtime))
if (IsNaN(localtime))
return 0;
return (int) MinFromTime(localtime);
@@ -3269,7 +3271,7 @@ js_DateGetSeconds(JSObject *obj)
return 0;
double utctime = obj->getDateUTCTime().toNumber();
if (MOZ_DOUBLE_IS_NaN(utctime))
if (IsNaN(utctime))
return 0;
return (int) SecFromTime(utctime);
}