Commit 3494d02f authored by fpizlo@apple.com's avatar fpizlo@apple.com

Reduce the verbosity of referring to QNaN in JavaScriptCore

https://bugs.webkit.org/show_bug.cgi?id=101174

Reviewed by Geoffrey Garen.

Introduces a #define QNaN in JSValue.h, and replaces all previous uses of
std::numeric_limits<double>::quiet_NaN() with QNaN.

* API/JSValueRef.cpp:
(JSValueMakeNumber):
(JSValueToNumber):
* dfg/DFGSpeculativeJIT.cpp:
(JSC::DFG::SpeculativeJIT::compileGetByValOnFloatTypedArray):
* jit/JITPropertyAccess.cpp:
(JSC::JIT::emitFloatTypedArrayGetByVal):
* runtime/CachedTranscendentalFunction.h:
(JSC::CachedTranscendentalFunction::initialize):
* runtime/DateConstructor.cpp:
(JSC::constructDate):
* runtime/DateInstanceCache.h:
(JSC::DateInstanceData::DateInstanceData):
(JSC::DateInstanceCache::reset):
* runtime/ExceptionHelpers.cpp:
(JSC::InterruptedExecutionError::defaultValue):
(JSC::TerminatedExecutionError::defaultValue):
* runtime/JSCell.h:
(JSC::JSValue::getPrimitiveNumber):
* runtime/JSDateMath.cpp:
(JSC::parseDateFromNullTerminatedCharacters):
* runtime/JSGlobalData.cpp:
(JSC::JSGlobalData::JSGlobalData):
(JSC::JSGlobalData::resetDateCache):
* runtime/JSGlobalObjectFunctions.cpp:
(JSC::parseInt):
(JSC::jsStrDecimalLiteral):
(JSC::toDouble):
(JSC::jsToNumber):
(JSC::parseFloat):
* runtime/JSValue.cpp:
(JSC::JSValue::toNumberSlowCase):
* runtime/JSValue.h:
(JSC):
* runtime/JSValueInlineMethods.h:
(JSC::jsNaN):
* runtime/MathObject.cpp:
(JSC::mathProtoFuncMax):
(JSC::mathProtoFuncMin):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@133493 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 86d6cb5f
......@@ -217,7 +217,7 @@ JSValueRef JSValueMakeNumber(JSContextRef ctx, double value)
// generated internally to JavaScriptCore naturally have that representation,
// but an external NaN might not.
if (isnan(value))
value = std::numeric_limits<double>::quiet_NaN();
value = QNaN;
return toRef(exec, jsNumber(value));
}
......@@ -282,7 +282,7 @@ double JSValueToNumber(JSContextRef ctx, JSValueRef value, JSValueRef* exception
if (exception)
*exception = toRef(exec, exec->exception());
exec->clearException();
number = std::numeric_limits<double>::quiet_NaN();
number = QNaN;
}
return number;
}
......
2012-11-04 Filip Pizlo <fpizlo@apple.com>
Reduce the verbosity of referring to QNaN in JavaScriptCore
https://bugs.webkit.org/show_bug.cgi?id=101174
Reviewed by Geoffrey Garen.
Introduces a #define QNaN in JSValue.h, and replaces all previous uses of
std::numeric_limits<double>::quiet_NaN() with QNaN.
* API/JSValueRef.cpp:
(JSValueMakeNumber):
(JSValueToNumber):
* dfg/DFGSpeculativeJIT.cpp:
(JSC::DFG::SpeculativeJIT::compileGetByValOnFloatTypedArray):
* jit/JITPropertyAccess.cpp:
(JSC::JIT::emitFloatTypedArrayGetByVal):
* runtime/CachedTranscendentalFunction.h:
(JSC::CachedTranscendentalFunction::initialize):
* runtime/DateConstructor.cpp:
(JSC::constructDate):
* runtime/DateInstanceCache.h:
(JSC::DateInstanceData::DateInstanceData):
(JSC::DateInstanceCache::reset):
* runtime/ExceptionHelpers.cpp:
(JSC::InterruptedExecutionError::defaultValue):
(JSC::TerminatedExecutionError::defaultValue):
* runtime/JSCell.h:
(JSC::JSValue::getPrimitiveNumber):
* runtime/JSDateMath.cpp:
(JSC::parseDateFromNullTerminatedCharacters):
* runtime/JSGlobalData.cpp:
(JSC::JSGlobalData::JSGlobalData):
(JSC::JSGlobalData::resetDateCache):
* runtime/JSGlobalObjectFunctions.cpp:
(JSC::parseInt):
(JSC::jsStrDecimalLiteral):
(JSC::toDouble):
(JSC::jsToNumber):
(JSC::parseFloat):
* runtime/JSValue.cpp:
(JSC::JSValue::toNumberSlowCase):
* runtime/JSValue.h:
(JSC):
* runtime/JSValueInlineMethods.h:
(JSC::jsNaN):
* runtime/MathObject.cpp:
(JSC::mathProtoFuncMax):
(JSC::mathProtoFuncMin):
2012-11-03 Filip Pizlo <fpizlo@apple.com>
Baseline JIT should use structure watchpoints whenever possible
......
......@@ -2416,7 +2416,7 @@ void SpeculativeJIT::compileGetByValOnFloatTypedArray(const TypedArrayDescriptor
case 8: {
m_jit.loadDouble(MacroAssembler::BaseIndex(storageReg, propertyReg, MacroAssembler::TimesEight), resultReg);
MacroAssembler::Jump notNaN = m_jit.branchDouble(MacroAssembler::DoubleEqual, resultReg, resultReg);
static const double NaN = std::numeric_limits<double>::quiet_NaN();
static const double NaN = QNaN;
m_jit.loadDouble(&NaN, resultReg);
notNaN.link(&m_jit);
break;
......
......@@ -1612,7 +1612,7 @@ JIT::JumpList JIT::emitFloatTypedArrayGetByVal(Instruction*, PatchableJump& badT
case 8: {
loadDouble(BaseIndex(base, property, TimesEight), fpRegT0);
Jump notNaN = branchDouble(DoubleEqual, fpRegT0, fpRegT0);
static const double NaN = std::numeric_limits<double>::quiet_NaN();
static const double NaN = QNaN;
loadDouble(&NaN, fpRegT0);
notNaN.link(this);
break;
......
......@@ -74,8 +74,8 @@ private:
// Lazily allocate the table, populate with NaN->NaN mapping.
m_cache = static_cast<CacheEntry*>(fastMalloc(s_cacheSize * sizeof(CacheEntry)));
for (unsigned x = 0; x < s_cacheSize; ++x) {
m_cache[x].operand = std::numeric_limits<double>::quiet_NaN();
m_cache[x].result = std::numeric_limits<double>::quiet_NaN();
m_cache[x].operand = QNaN;
m_cache[x].result = QNaN;
}
}
......
......@@ -131,7 +131,7 @@ JSObject* constructDate(ExecState* exec, JSGlobalObject* globalObject, const Arg
|| (numArgs >= 5 && !isfinite(doubleArguments[4]))
|| (numArgs >= 6 && !isfinite(doubleArguments[5]))
|| (numArgs >= 7 && !isfinite(doubleArguments[6])))
value = std::numeric_limits<double>::quiet_NaN();
value = QNaN;
else {
GregorianDateTime t;
int year = JSC::toInt32(doubleArguments[0]);
......
......@@ -45,8 +45,8 @@ namespace JSC {
private:
DateInstanceData()
: m_gregorianDateTimeCachedForMS(std::numeric_limits<double>::quiet_NaN())
, m_gregorianDateTimeUTCCachedForMS(std::numeric_limits<double>::quiet_NaN())
: m_gregorianDateTimeCachedForMS(QNaN)
, m_gregorianDateTimeUTCCachedForMS(QNaN)
{
}
};
......@@ -61,7 +61,7 @@ namespace JSC {
void reset()
{
for (size_t i = 0; i < cacheSize; ++i)
m_cache[i].key = std::numeric_limits<double>::quiet_NaN();
m_cache[i].key = QNaN;
}
DateInstanceData* add(double d)
......
......@@ -48,7 +48,7 @@ JSValue InterruptedExecutionError::defaultValue(const JSObject*, ExecState* exec
{
if (hint == PreferString)
return jsNontrivialString(exec, String(ASCIILiteral("JavaScript execution exceeded timeout.")));
return JSValue(std::numeric_limits<double>::quiet_NaN());
return JSValue(QNaN);
}
JSObject* createInterruptedExecutionException(JSGlobalData* globalData)
......@@ -75,7 +75,7 @@ JSValue TerminatedExecutionError::defaultValue(const JSObject*, ExecState* exec,
{
if (hint == PreferString)
return jsNontrivialString(exec, String(ASCIILiteral("JavaScript execution terminated.")));
return JSValue(std::numeric_limits<double>::quiet_NaN());
return JSValue(QNaN);
}
JSObject* createTerminatedExecutionException(JSGlobalData* globalData)
......
......@@ -279,7 +279,7 @@ namespace JSC {
return true;
}
ASSERT(isUndefined());
number = std::numeric_limits<double>::quiet_NaN();
number = QNaN;
value = *this;
return true;
}
......
......@@ -247,7 +247,7 @@ double parseDateFromNullTerminatedCharacters(ExecState* exec, const char* dateSt
int offset;
double ms = WTF::parseDateFromNullTerminatedCharacters(dateString, haveTZ, offset);
if (isnan(ms))
return std::numeric_limits<double>::quiet_NaN();
return QNaN;
// fall back to local timezone
if (!haveTZ) {
......
......@@ -170,7 +170,7 @@ JSGlobalData::JSGlobalData(GlobalDataType globalDataType, HeapType heapType)
, sizeOfLastScratchBuffer(0)
#endif
, dynamicGlobalObject(0)
, cachedUTCOffset(std::numeric_limits<double>::quiet_NaN())
, cachedUTCOffset(QNaN)
, m_enabledProfiler(0)
, m_regExpCache(new RegExpCache(this))
#if ENABLE(REGEXP_TRACING)
......@@ -400,10 +400,10 @@ JSGlobalData::ClientData::~ClientData()
void JSGlobalData::resetDateCache()
{
cachedUTCOffset = std::numeric_limits<double>::quiet_NaN();
cachedUTCOffset = QNaN;
dstOffsetCache.reset();
cachedDateString = String();
cachedDateStringValue = std::numeric_limits<double>::quiet_NaN();
cachedDateStringValue = QNaN;
dateInstanceCache.reset();
}
......
......@@ -276,7 +276,7 @@ static double parseInt(const String& s, const CharType* data, int radix)
// 8.a If R < 2 or R > 36, then return NaN.
if (radix < 2 || radix > 36)
return std::numeric_limits<double>::quiet_NaN();
return QNaN;
// 13. Let mathInt be the mathematical integer value that is represented by Z in radix-R notation, using the letters
// A-Z and a-z for digits with values 10 through 35. (However, if R is 10 and Z contains more than 20 significant
......@@ -299,7 +299,7 @@ static double parseInt(const String& s, const CharType* data, int radix)
// 12. If Z is empty, return NaN.
if (!sawDigit)
return std::numeric_limits<double>::quiet_NaN();
return QNaN;
// Alternate code path for certain large numbers.
if (number >= mantissaOverflowLowerBound) {
......@@ -397,7 +397,7 @@ static double jsStrDecimalLiteral(const CharType*& data, const CharType* end)
}
// Not a number.
return std::numeric_limits<double>::quiet_NaN();
return QNaN;
}
template <typename CharType>
......@@ -427,7 +427,7 @@ static double toDouble(const CharType* characters, unsigned size)
break;
}
if (characters != endCharacters)
return std::numeric_limits<double>::quiet_NaN();
return QNaN;
return number;
}
......@@ -443,7 +443,7 @@ double jsToNumber(const String& s)
return c - '0';
if (isStrWhiteSpace(c))
return 0;
return std::numeric_limits<double>::quiet_NaN();
return QNaN;
}
if (s.is8Bit())
......@@ -459,7 +459,7 @@ static double parseFloat(const String& s)
UChar c = s[0];
if (isASCIIDigit(c))
return c - '0';
return std::numeric_limits<double>::quiet_NaN();
return QNaN;
}
if (s.is8Bit()) {
......@@ -474,7 +474,7 @@ static double parseFloat(const String& s)
// Empty string.
if (data == end)
return std::numeric_limits<double>::quiet_NaN();
return QNaN;
return jsStrDecimalLiteral(data, end);
}
......@@ -490,7 +490,7 @@ static double parseFloat(const String& s)
// Empty string.
if (data == end)
return std::numeric_limits<double>::quiet_NaN();
return QNaN;
return jsStrDecimalLiteral(data, end);
}
......
......@@ -62,7 +62,7 @@ double JSValue::toNumberSlowCase(ExecState* exec) const
return asCell()->toNumber(exec);
if (isTrue())
return 1.0;
return isUndefined() ? std::numeric_limits<double>::quiet_NaN() : 0; // null and false both convert to 0.
return isUndefined() ? QNaN : 0; // null and false both convert to 0.
}
JSObject* JSValue::toObjectSlowCase(ExecState* exec, JSGlobalObject* globalObject) const
......
......@@ -35,6 +35,10 @@
namespace JSC {
// This is used a lot throughout JavaScriptCore for everything from value boxing to marking
// values as being missing, so it is useful to have it abbreviated.
#define QNaN (std::numeric_limits<double>::quiet_NaN())
class ExecState;
class JSCell;
class JSGlobalData;
......
......@@ -62,7 +62,7 @@ namespace JSC {
inline JSValue jsNaN()
{
return JSValue(std::numeric_limits<double>::quiet_NaN());
return JSValue(QNaN);
}
inline JSValue::JSValue(char i)
......
......@@ -175,7 +175,7 @@ EncodedJSValue JSC_HOST_CALL mathProtoFuncMax(ExecState* exec)
for (unsigned k = 0; k < argsCount; ++k) {
double val = exec->argument(k).toNumber(exec);
if (isnan(val)) {
result = std::numeric_limits<double>::quiet_NaN();
result = QNaN;
break;
}
if (val > result || (val == 0 && result == 0 && !signbit(val)))
......@@ -191,7 +191,7 @@ EncodedJSValue JSC_HOST_CALL mathProtoFuncMin(ExecState* exec)
for (unsigned k = 0; k < argsCount; ++k) {
double val = exec->argument(k).toNumber(exec);
if (isnan(val)) {
result = std::numeric_limits<double>::quiet_NaN();
result = QNaN;
break;
}
if (val < result || (val == 0 && result == 0 && signbit(val)))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment