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) ...@@ -217,7 +217,7 @@ JSValueRef JSValueMakeNumber(JSContextRef ctx, double value)
// generated internally to JavaScriptCore naturally have that representation, // generated internally to JavaScriptCore naturally have that representation,
// but an external NaN might not. // but an external NaN might not.
if (isnan(value)) if (isnan(value))
value = std::numeric_limits<double>::quiet_NaN(); value = QNaN;
return toRef(exec, jsNumber(value)); return toRef(exec, jsNumber(value));
} }
...@@ -282,7 +282,7 @@ double JSValueToNumber(JSContextRef ctx, JSValueRef value, JSValueRef* exception ...@@ -282,7 +282,7 @@ double JSValueToNumber(JSContextRef ctx, JSValueRef value, JSValueRef* exception
if (exception) if (exception)
*exception = toRef(exec, exec->exception()); *exception = toRef(exec, exec->exception());
exec->clearException(); exec->clearException();
number = std::numeric_limits<double>::quiet_NaN(); number = QNaN;
} }
return number; 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> 2012-11-03 Filip Pizlo <fpizlo@apple.com>
Baseline JIT should use structure watchpoints whenever possible Baseline JIT should use structure watchpoints whenever possible
......
...@@ -2416,7 +2416,7 @@ void SpeculativeJIT::compileGetByValOnFloatTypedArray(const TypedArrayDescriptor ...@@ -2416,7 +2416,7 @@ void SpeculativeJIT::compileGetByValOnFloatTypedArray(const TypedArrayDescriptor
case 8: { case 8: {
m_jit.loadDouble(MacroAssembler::BaseIndex(storageReg, propertyReg, MacroAssembler::TimesEight), resultReg); m_jit.loadDouble(MacroAssembler::BaseIndex(storageReg, propertyReg, MacroAssembler::TimesEight), resultReg);
MacroAssembler::Jump notNaN = m_jit.branchDouble(MacroAssembler::DoubleEqual, resultReg, 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); m_jit.loadDouble(&NaN, resultReg);
notNaN.link(&m_jit); notNaN.link(&m_jit);
break; break;
......
...@@ -1612,7 +1612,7 @@ JIT::JumpList JIT::emitFloatTypedArrayGetByVal(Instruction*, PatchableJump& badT ...@@ -1612,7 +1612,7 @@ JIT::JumpList JIT::emitFloatTypedArrayGetByVal(Instruction*, PatchableJump& badT
case 8: { case 8: {
loadDouble(BaseIndex(base, property, TimesEight), fpRegT0); loadDouble(BaseIndex(base, property, TimesEight), fpRegT0);
Jump notNaN = branchDouble(DoubleEqual, fpRegT0, 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); loadDouble(&NaN, fpRegT0);
notNaN.link(this); notNaN.link(this);
break; break;
......
...@@ -74,8 +74,8 @@ private: ...@@ -74,8 +74,8 @@ private:
// Lazily allocate the table, populate with NaN->NaN mapping. // Lazily allocate the table, populate with NaN->NaN mapping.
m_cache = static_cast<CacheEntry*>(fastMalloc(s_cacheSize * sizeof(CacheEntry))); m_cache = static_cast<CacheEntry*>(fastMalloc(s_cacheSize * sizeof(CacheEntry)));
for (unsigned x = 0; x < s_cacheSize; ++x) { for (unsigned x = 0; x < s_cacheSize; ++x) {
m_cache[x].operand = std::numeric_limits<double>::quiet_NaN(); m_cache[x].operand = QNaN;
m_cache[x].result = std::numeric_limits<double>::quiet_NaN(); m_cache[x].result = QNaN;
} }
} }
......
...@@ -131,7 +131,7 @@ JSObject* constructDate(ExecState* exec, JSGlobalObject* globalObject, const Arg ...@@ -131,7 +131,7 @@ JSObject* constructDate(ExecState* exec, JSGlobalObject* globalObject, const Arg
|| (numArgs >= 5 && !isfinite(doubleArguments[4])) || (numArgs >= 5 && !isfinite(doubleArguments[4]))
|| (numArgs >= 6 && !isfinite(doubleArguments[5])) || (numArgs >= 6 && !isfinite(doubleArguments[5]))
|| (numArgs >= 7 && !isfinite(doubleArguments[6]))) || (numArgs >= 7 && !isfinite(doubleArguments[6])))
value = std::numeric_limits<double>::quiet_NaN(); value = QNaN;
else { else {
GregorianDateTime t; GregorianDateTime t;
int year = JSC::toInt32(doubleArguments[0]); int year = JSC::toInt32(doubleArguments[0]);
......
...@@ -45,8 +45,8 @@ namespace JSC { ...@@ -45,8 +45,8 @@ namespace JSC {
private: private:
DateInstanceData() DateInstanceData()
: m_gregorianDateTimeCachedForMS(std::numeric_limits<double>::quiet_NaN()) : m_gregorianDateTimeCachedForMS(QNaN)
, m_gregorianDateTimeUTCCachedForMS(std::numeric_limits<double>::quiet_NaN()) , m_gregorianDateTimeUTCCachedForMS(QNaN)
{ {
} }
}; };
...@@ -61,7 +61,7 @@ namespace JSC { ...@@ -61,7 +61,7 @@ namespace JSC {
void reset() void reset()
{ {
for (size_t i = 0; i < cacheSize; ++i) 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) DateInstanceData* add(double d)
......
...@@ -48,7 +48,7 @@ JSValue InterruptedExecutionError::defaultValue(const JSObject*, ExecState* exec ...@@ -48,7 +48,7 @@ JSValue InterruptedExecutionError::defaultValue(const JSObject*, ExecState* exec
{ {
if (hint == PreferString) if (hint == PreferString)
return jsNontrivialString(exec, String(ASCIILiteral("JavaScript execution exceeded timeout."))); return jsNontrivialString(exec, String(ASCIILiteral("JavaScript execution exceeded timeout.")));
return JSValue(std::numeric_limits<double>::quiet_NaN()); return JSValue(QNaN);
} }
JSObject* createInterruptedExecutionException(JSGlobalData* globalData) JSObject* createInterruptedExecutionException(JSGlobalData* globalData)
...@@ -75,7 +75,7 @@ JSValue TerminatedExecutionError::defaultValue(const JSObject*, ExecState* exec, ...@@ -75,7 +75,7 @@ JSValue TerminatedExecutionError::defaultValue(const JSObject*, ExecState* exec,
{ {
if (hint == PreferString) if (hint == PreferString)
return jsNontrivialString(exec, String(ASCIILiteral("JavaScript execution terminated."))); return jsNontrivialString(exec, String(ASCIILiteral("JavaScript execution terminated.")));
return JSValue(std::numeric_limits<double>::quiet_NaN()); return JSValue(QNaN);
} }
JSObject* createTerminatedExecutionException(JSGlobalData* globalData) JSObject* createTerminatedExecutionException(JSGlobalData* globalData)
......
...@@ -279,7 +279,7 @@ namespace JSC { ...@@ -279,7 +279,7 @@ namespace JSC {
return true; return true;
} }
ASSERT(isUndefined()); ASSERT(isUndefined());
number = std::numeric_limits<double>::quiet_NaN(); number = QNaN;
value = *this; value = *this;
return true; return true;
} }
......
...@@ -247,7 +247,7 @@ double parseDateFromNullTerminatedCharacters(ExecState* exec, const char* dateSt ...@@ -247,7 +247,7 @@ double parseDateFromNullTerminatedCharacters(ExecState* exec, const char* dateSt
int offset; int offset;
double ms = WTF::parseDateFromNullTerminatedCharacters(dateString, haveTZ, offset); double ms = WTF::parseDateFromNullTerminatedCharacters(dateString, haveTZ, offset);
if (isnan(ms)) if (isnan(ms))
return std::numeric_limits<double>::quiet_NaN(); return QNaN;
// fall back to local timezone // fall back to local timezone
if (!haveTZ) { if (!haveTZ) {
......
...@@ -170,7 +170,7 @@ JSGlobalData::JSGlobalData(GlobalDataType globalDataType, HeapType heapType) ...@@ -170,7 +170,7 @@ JSGlobalData::JSGlobalData(GlobalDataType globalDataType, HeapType heapType)
, sizeOfLastScratchBuffer(0) , sizeOfLastScratchBuffer(0)
#endif #endif
, dynamicGlobalObject(0) , dynamicGlobalObject(0)
, cachedUTCOffset(std::numeric_limits<double>::quiet_NaN()) , cachedUTCOffset(QNaN)
, m_enabledProfiler(0) , m_enabledProfiler(0)
, m_regExpCache(new RegExpCache(this)) , m_regExpCache(new RegExpCache(this))
#if ENABLE(REGEXP_TRACING) #if ENABLE(REGEXP_TRACING)
...@@ -400,10 +400,10 @@ JSGlobalData::ClientData::~ClientData() ...@@ -400,10 +400,10 @@ JSGlobalData::ClientData::~ClientData()
void JSGlobalData::resetDateCache() void JSGlobalData::resetDateCache()
{ {
cachedUTCOffset = std::numeric_limits<double>::quiet_NaN(); cachedUTCOffset = QNaN;
dstOffsetCache.reset(); dstOffsetCache.reset();
cachedDateString = String(); cachedDateString = String();
cachedDateStringValue = std::numeric_limits<double>::quiet_NaN(); cachedDateStringValue = QNaN;
dateInstanceCache.reset(); dateInstanceCache.reset();
} }
......
...@@ -276,7 +276,7 @@ static double parseInt(const String& s, const CharType* data, int radix) ...@@ -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. // 8.a If R < 2 or R > 36, then return NaN.
if (radix < 2 || radix > 36) 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 // 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 // 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) ...@@ -299,7 +299,7 @@ static double parseInt(const String& s, const CharType* data, int radix)
// 12. If Z is empty, return NaN. // 12. If Z is empty, return NaN.
if (!sawDigit) if (!sawDigit)
return std::numeric_limits<double>::quiet_NaN(); return QNaN;
// Alternate code path for certain large numbers. // Alternate code path for certain large numbers.
if (number >= mantissaOverflowLowerBound) { if (number >= mantissaOverflowLowerBound) {
...@@ -397,7 +397,7 @@ static double jsStrDecimalLiteral(const CharType*& data, const CharType* end) ...@@ -397,7 +397,7 @@ static double jsStrDecimalLiteral(const CharType*& data, const CharType* end)
} }
// Not a number. // Not a number.
return std::numeric_limits<double>::quiet_NaN(); return QNaN;
} }
template <typename CharType> template <typename CharType>
...@@ -427,7 +427,7 @@ static double toDouble(const CharType* characters, unsigned size) ...@@ -427,7 +427,7 @@ static double toDouble(const CharType* characters, unsigned size)
break; break;
} }
if (characters != endCharacters) if (characters != endCharacters)
return std::numeric_limits<double>::quiet_NaN(); return QNaN;
return number; return number;
} }
...@@ -443,7 +443,7 @@ double jsToNumber(const String& s) ...@@ -443,7 +443,7 @@ double jsToNumber(const String& s)
return c - '0'; return c - '0';
if (isStrWhiteSpace(c)) if (isStrWhiteSpace(c))
return 0; return 0;
return std::numeric_limits<double>::quiet_NaN(); return QNaN;
} }
if (s.is8Bit()) if (s.is8Bit())
...@@ -459,7 +459,7 @@ static double parseFloat(const String& s) ...@@ -459,7 +459,7 @@ static double parseFloat(const String& s)
UChar c = s[0]; UChar c = s[0];
if (isASCIIDigit(c)) if (isASCIIDigit(c))
return c - '0'; return c - '0';
return std::numeric_limits<double>::quiet_NaN(); return QNaN;
} }
if (s.is8Bit()) { if (s.is8Bit()) {
...@@ -474,7 +474,7 @@ static double parseFloat(const String& s) ...@@ -474,7 +474,7 @@ static double parseFloat(const String& s)
// Empty string. // Empty string.
if (data == end) if (data == end)
return std::numeric_limits<double>::quiet_NaN(); return QNaN;
return jsStrDecimalLiteral(data, end); return jsStrDecimalLiteral(data, end);
} }
...@@ -490,7 +490,7 @@ static double parseFloat(const String& s) ...@@ -490,7 +490,7 @@ static double parseFloat(const String& s)
// Empty string. // Empty string.
if (data == end) if (data == end)
return std::numeric_limits<double>::quiet_NaN(); return QNaN;
return jsStrDecimalLiteral(data, end); return jsStrDecimalLiteral(data, end);
} }
......
...@@ -62,7 +62,7 @@ double JSValue::toNumberSlowCase(ExecState* exec) const ...@@ -62,7 +62,7 @@ double JSValue::toNumberSlowCase(ExecState* exec) const
return asCell()->toNumber(exec); return asCell()->toNumber(exec);
if (isTrue()) if (isTrue())
return 1.0; 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 JSObject* JSValue::toObjectSlowCase(ExecState* exec, JSGlobalObject* globalObject) const
......
...@@ -35,6 +35,10 @@ ...@@ -35,6 +35,10 @@
namespace JSC { 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 ExecState;
class JSCell; class JSCell;
class JSGlobalData; class JSGlobalData;
......
...@@ -62,7 +62,7 @@ namespace JSC { ...@@ -62,7 +62,7 @@ namespace JSC {
inline JSValue jsNaN() inline JSValue jsNaN()
{ {
return JSValue(std::numeric_limits<double>::quiet_NaN()); return JSValue(QNaN);
} }
inline JSValue::JSValue(char i) inline JSValue::JSValue(char i)
......
...@@ -175,7 +175,7 @@ EncodedJSValue JSC_HOST_CALL mathProtoFuncMax(ExecState* exec) ...@@ -175,7 +175,7 @@ EncodedJSValue JSC_HOST_CALL mathProtoFuncMax(ExecState* exec)
for (unsigned k = 0; k < argsCount; ++k) { for (unsigned k = 0; k < argsCount; ++k) {
double val = exec->argument(k).toNumber(exec); double val = exec->argument(k).toNumber(exec);
if (isnan(val)) { if (isnan(val)) {
result = std::numeric_limits<double>::quiet_NaN(); result = QNaN;
break; break;
} }
if (val > result || (val == 0 && result == 0 && !signbit(val))) if (val > result || (val == 0 && result == 0 && !signbit(val)))
...@@ -191,7 +191,7 @@ EncodedJSValue JSC_HOST_CALL mathProtoFuncMin(ExecState* exec) ...@@ -191,7 +191,7 @@ EncodedJSValue JSC_HOST_CALL mathProtoFuncMin(ExecState* exec)
for (unsigned k = 0; k < argsCount; ++k) { for (unsigned k = 0; k < argsCount; ++k) {
double val = exec->argument(k).toNumber(exec); double val = exec->argument(k).toNumber(exec);
if (isnan(val)) { if (isnan(val)) {
result = std::numeric_limits<double>::quiet_NaN(); result = QNaN;
break; break;
} }
if (val < result || (val == 0 && result == 0 && signbit(val))) 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