From df950b87e781daf92364afb22f13d87b18858c80 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Fri, 4 Aug 2017 11:33:49 -0700 Subject: Remove platform-specific IsFinite, JS_PortIsNan, and GetNan. Because C++11 gives us std::isfinite(), std::isnan() and std::nan(). Bug: pdfium:459 Change-Id: I128f332ec908df6aff66ef76012288fd22d423ed Reviewed-on: https://pdfium-review.googlesource.com/10190 Reviewed-by: Lei Zhang Commit-Queue: Tom Sepez --- fpdfsdk/javascript/JS_Value.cpp | 63 +++++++++++------------------------------ 1 file changed, 17 insertions(+), 46 deletions(-) (limited to 'fpdfsdk/javascript/JS_Value.cpp') diff --git a/fpdfsdk/javascript/JS_Value.cpp b/fpdfsdk/javascript/JS_Value.cpp index 184ff82fa1..40b94fac64 100644 --- a/fpdfsdk/javascript/JS_Value.cpp +++ b/fpdfsdk/javascript/JS_Value.cpp @@ -19,12 +19,6 @@ namespace { -const uint32_t g_nan[2] = {0, 0x7FF80000}; - -double GetNan() { - return *(double*)g_nan; -} - double MakeDate(int year, int mon, int day, int hour, int min, int sec, int ms) { return JS_MakeDate(JS_MakeDay(year, mon, day), @@ -66,18 +60,6 @@ double Mod(double x, double y) { return r; } -int IsFinite(double v) { -#if defined(_MSC_VER) - return ::_finite(v); -#else - return std::fabs(v) < std::numeric_limits::max(); -#endif -} - -double ToInteger(double n) { - return (n >= 0) ? floor(n) : -floor(-n); -} - bool IsLeapYear(int year) { return (year % 4 == 0) && ((year % 100 != 0) || (year % 400 != 0)); } @@ -102,12 +84,12 @@ double TimeFromYearMonth(int y, int m) { } int Day(double t) { - return (int)floor(t / 86400000); + return static_cast(floor(t / 86400000.0)); } int YearFromTime(double t) { // estimate the time. - int y = 1970 + static_cast(t / (365.2425 * 86400000)); + int y = 1970 + static_cast(t / (365.2425 * 86400000.0)); if (TimeFromYear(y) <= t) { while (TimeFromYear(y + 1) <= t) y++; @@ -517,7 +499,7 @@ CJS_Date::CJS_Date(CJS_Runtime* pRuntime, CJS_Date::~CJS_Date() {} bool CJS_Date::IsValidDate(CJS_Runtime* pRuntime) const { - return !m_pDate.IsEmpty() && !JS_PortIsNan(pRuntime->ToDouble(m_pDate)); + return !m_pDate.IsEmpty() && !std::isnan(pRuntime->ToDouble(m_pDate)); } void CJS_Date::Attach(v8::Local pDate) { @@ -682,7 +664,7 @@ double JS_DateParse(const CFX_WideString& str) { v = funC->Call(context, context->Global(), argc, argv).ToLocalChecked(); if (v->IsNumber()) { double date = v->ToNumber(context).ToLocalChecked()->Value(); - if (!IsFinite(date)) + if (!std::isfinite(date)) return date; return JS_LocalTime(date); } @@ -692,44 +674,33 @@ double JS_DateParse(const CFX_WideString& str) { } double JS_MakeDay(int nYear, int nMonth, int nDate) { - if (!IsFinite(nYear) || !IsFinite(nMonth) || !IsFinite(nDate)) - return GetNan(); - double y = ToInteger(nYear); - double m = ToInteger(nMonth); - double dt = ToInteger(nDate); - double ym = y + floor((double)m / 12); + double y = static_cast(nYear); + double m = static_cast(nMonth); + double dt = static_cast(nDate); + double ym = y + floor(m / 12); double mn = Mod(m, 12); - - double t = TimeFromYearMonth((int)ym, (int)mn); - + double t = TimeFromYearMonth(static_cast(ym), static_cast(mn)); if (YearFromTime(t) != ym || MonthFromTime(t) != mn || DateFromTime(t) != 1) - return GetNan(); + return std::nan(""); + return Day(t) + dt - 1; } double JS_MakeTime(int nHour, int nMin, int nSec, int nMs) { - if (!IsFinite(nHour) || !IsFinite(nMin) || !IsFinite(nSec) || !IsFinite(nMs)) - return GetNan(); - - double h = ToInteger(nHour); - double m = ToInteger(nMin); - double s = ToInteger(nSec); - double milli = ToInteger(nMs); - + double h = static_cast(nHour); + double m = static_cast(nMin); + double s = static_cast(nSec); + double milli = static_cast(nMs); return h * 3600000 + m * 60000 + s * 1000 + milli; } double JS_MakeDate(double day, double time) { - if (!IsFinite(day) || !IsFinite(time)) - return GetNan(); + if (!std::isfinite(day) || !std::isfinite(time)) + return std::nan(""); return day * 86400000 + time; } -bool JS_PortIsNan(double d) { - return d != d; -} - double JS_LocalTime(double d) { return d + GetLocalTZA() + GetDaylightSavingTA(d); } -- cgit v1.2.3