diff --git a/Source/JavaScriptCore/API/JSValueRef.cpp b/Source/JavaScriptCore/API/JSValueRef.cpp index de84508c1803495dc7a7676f3d62df81290b12f1..5ff7c03c609fb64be76d7217aa322922b7f84e79 100644 --- a/Source/JavaScriptCore/API/JSValueRef.cpp +++ b/Source/JavaScriptCore/API/JSValueRef.cpp @@ -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::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::quiet_NaN(); + number = QNaN; } return number; } diff --git a/Source/JavaScriptCore/ChangeLog b/Source/JavaScriptCore/ChangeLog index 57178d001229da998b14904be275891233234dd4..a8508fab175d0c7685c563e727cd20ca239b1b26 100644 --- a/Source/JavaScriptCore/ChangeLog +++ b/Source/JavaScriptCore/ChangeLog @@ -1,3 +1,53 @@ +2012-11-04 Filip Pizlo + + 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::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 Baseline JIT should use structure watchpoints whenever possible diff --git a/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp b/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp index 3625785e147d32c235449aa8098ef88d2b651a6a..6bedd6d68512855aceb5cf56a78097bbea1e531f 100644 --- a/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp +++ b/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp @@ -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::quiet_NaN(); + static const double NaN = QNaN; m_jit.loadDouble(&NaN, resultReg); notNaN.link(&m_jit); break; diff --git a/Source/JavaScriptCore/jit/JITPropertyAccess.cpp b/Source/JavaScriptCore/jit/JITPropertyAccess.cpp index e5c128e959f20ba1fb3f9dc773efa26b81760cf1..c21526422140c5bed988a07c50c9a107bf8ad605 100644 --- a/Source/JavaScriptCore/jit/JITPropertyAccess.cpp +++ b/Source/JavaScriptCore/jit/JITPropertyAccess.cpp @@ -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::quiet_NaN(); + static const double NaN = QNaN; loadDouble(&NaN, fpRegT0); notNaN.link(this); break; diff --git a/Source/JavaScriptCore/runtime/CachedTranscendentalFunction.h b/Source/JavaScriptCore/runtime/CachedTranscendentalFunction.h index f31b4a07f2ddc2ab1767f5cb94f0aea7b1b48335..62a01dbcb446750ec451768215682ffe7fc9190f 100644 --- a/Source/JavaScriptCore/runtime/CachedTranscendentalFunction.h +++ b/Source/JavaScriptCore/runtime/CachedTranscendentalFunction.h @@ -74,8 +74,8 @@ private: // Lazily allocate the table, populate with NaN->NaN mapping. m_cache = static_cast(fastMalloc(s_cacheSize * sizeof(CacheEntry))); for (unsigned x = 0; x < s_cacheSize; ++x) { - m_cache[x].operand = std::numeric_limits::quiet_NaN(); - m_cache[x].result = std::numeric_limits::quiet_NaN(); + m_cache[x].operand = QNaN; + m_cache[x].result = QNaN; } } diff --git a/Source/JavaScriptCore/runtime/DateConstructor.cpp b/Source/JavaScriptCore/runtime/DateConstructor.cpp index f78e8bf5561ffecbf394cff4fe10115f4193c88c..9a162e9e785d44c157b28a94f70b69e3faef29d2 100644 --- a/Source/JavaScriptCore/runtime/DateConstructor.cpp +++ b/Source/JavaScriptCore/runtime/DateConstructor.cpp @@ -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::quiet_NaN(); + value = QNaN; else { GregorianDateTime t; int year = JSC::toInt32(doubleArguments[0]); diff --git a/Source/JavaScriptCore/runtime/DateInstanceCache.h b/Source/JavaScriptCore/runtime/DateInstanceCache.h index 153582f6740eece156810ee6f4d819bca1fbf689..e186516e86bde40fc45c870461e38a0c92fb0da8 100644 --- a/Source/JavaScriptCore/runtime/DateInstanceCache.h +++ b/Source/JavaScriptCore/runtime/DateInstanceCache.h @@ -45,8 +45,8 @@ namespace JSC { private: DateInstanceData() - : m_gregorianDateTimeCachedForMS(std::numeric_limits::quiet_NaN()) - , m_gregorianDateTimeUTCCachedForMS(std::numeric_limits::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::quiet_NaN(); + m_cache[i].key = QNaN; } DateInstanceData* add(double d) diff --git a/Source/JavaScriptCore/runtime/ExceptionHelpers.cpp b/Source/JavaScriptCore/runtime/ExceptionHelpers.cpp index a3281b6d6c0475003382aa270f841fd6b24bc13e..a4368a2bb1a67563e6deffc39dc78079f465e266 100644 --- a/Source/JavaScriptCore/runtime/ExceptionHelpers.cpp +++ b/Source/JavaScriptCore/runtime/ExceptionHelpers.cpp @@ -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::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::quiet_NaN()); + return JSValue(QNaN); } JSObject* createTerminatedExecutionException(JSGlobalData* globalData) diff --git a/Source/JavaScriptCore/runtime/JSCell.h b/Source/JavaScriptCore/runtime/JSCell.h index a39af128391ebff320c4141113bbe4d59d48cafe..2bb9b1e519b16f6bd613e95b8af768c3a8bb25de 100644 --- a/Source/JavaScriptCore/runtime/JSCell.h +++ b/Source/JavaScriptCore/runtime/JSCell.h @@ -279,7 +279,7 @@ namespace JSC { return true; } ASSERT(isUndefined()); - number = std::numeric_limits::quiet_NaN(); + number = QNaN; value = *this; return true; } diff --git a/Source/JavaScriptCore/runtime/JSDateMath.cpp b/Source/JavaScriptCore/runtime/JSDateMath.cpp index c54147ef280cb1fcc9779b46624c25f34d8d2fe6..cd3948fcf383c8dadb74e104c4779a9a445dfe30 100644 --- a/Source/JavaScriptCore/runtime/JSDateMath.cpp +++ b/Source/JavaScriptCore/runtime/JSDateMath.cpp @@ -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::quiet_NaN(); + return QNaN; // fall back to local timezone if (!haveTZ) { diff --git a/Source/JavaScriptCore/runtime/JSGlobalData.cpp b/Source/JavaScriptCore/runtime/JSGlobalData.cpp index 5fb682bdb088dd3e22a07fb2a0acb25ec148222d..12a28e341fb02ab98732fe20d5e63565884a01ed 100644 --- a/Source/JavaScriptCore/runtime/JSGlobalData.cpp +++ b/Source/JavaScriptCore/runtime/JSGlobalData.cpp @@ -170,7 +170,7 @@ JSGlobalData::JSGlobalData(GlobalDataType globalDataType, HeapType heapType) , sizeOfLastScratchBuffer(0) #endif , dynamicGlobalObject(0) - , cachedUTCOffset(std::numeric_limits::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::quiet_NaN(); + cachedUTCOffset = QNaN; dstOffsetCache.reset(); cachedDateString = String(); - cachedDateStringValue = std::numeric_limits::quiet_NaN(); + cachedDateStringValue = QNaN; dateInstanceCache.reset(); } diff --git a/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp b/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp index 8b1acb25a88fa57d4df23bd1c8e618086f8b829e..7ac76d350d0810203db31c8f9683286d4dd8bf44 100644 --- a/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp +++ b/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp @@ -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::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::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::quiet_NaN(); + return QNaN; } template @@ -427,7 +427,7 @@ static double toDouble(const CharType* characters, unsigned size) break; } if (characters != endCharacters) - return std::numeric_limits::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::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::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::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::quiet_NaN(); + return QNaN; return jsStrDecimalLiteral(data, end); } diff --git a/Source/JavaScriptCore/runtime/JSValue.cpp b/Source/JavaScriptCore/runtime/JSValue.cpp index a5cdf700b4143286d4adb3d8842df024e19d4f9e..e7f8cad17cdec42ecae28ef08aad30c794a3b312 100644 --- a/Source/JavaScriptCore/runtime/JSValue.cpp +++ b/Source/JavaScriptCore/runtime/JSValue.cpp @@ -62,7 +62,7 @@ double JSValue::toNumberSlowCase(ExecState* exec) const return asCell()->toNumber(exec); if (isTrue()) return 1.0; - return isUndefined() ? std::numeric_limits::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 diff --git a/Source/JavaScriptCore/runtime/JSValue.h b/Source/JavaScriptCore/runtime/JSValue.h index 7b5c81aa97067549fffa17fbd96772c9142cc956..bd9b9046625e6f3e2e73c2fe7c70cc28b8a3885b 100644 --- a/Source/JavaScriptCore/runtime/JSValue.h +++ b/Source/JavaScriptCore/runtime/JSValue.h @@ -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::quiet_NaN()) + class ExecState; class JSCell; class JSGlobalData; diff --git a/Source/JavaScriptCore/runtime/JSValueInlineMethods.h b/Source/JavaScriptCore/runtime/JSValueInlineMethods.h index 52b7478901ac5240966c8710d3ef60adf3a1ba88..224982e9e3449076d6a971379e182b204ff7ac04 100644 --- a/Source/JavaScriptCore/runtime/JSValueInlineMethods.h +++ b/Source/JavaScriptCore/runtime/JSValueInlineMethods.h @@ -62,7 +62,7 @@ namespace JSC { inline JSValue jsNaN() { - return JSValue(std::numeric_limits::quiet_NaN()); + return JSValue(QNaN); } inline JSValue::JSValue(char i) diff --git a/Source/JavaScriptCore/runtime/MathObject.cpp b/Source/JavaScriptCore/runtime/MathObject.cpp index 2f4df375aec03e6980c6f88a8cc5c6eea4e8f1cf..7634487adcde16ccf478fc3ab6e0ab0b8f35aa94 100644 --- a/Source/JavaScriptCore/runtime/MathObject.cpp +++ b/Source/JavaScriptCore/runtime/MathObject.cpp @@ -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::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::quiet_NaN(); + result = QNaN; break; } if (val < result || (val == 0 && result == 0 && signbit(val)))