summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@nokia.com>2012-05-07 11:21:11 +0200
committerSimon Hausmann <simon.hausmann@nokia.com>2012-05-07 11:21:11 +0200
commit2cf6c8816a73e0132bd8fa3b509d62d7c51b6e47 (patch)
tree988e8c5b116dd0466244ae2fe5af8ee9be926d76 /Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp
parentdd91e772430dc294e3bf478c119ef8d43c0a3358 (diff)
downloadqtwebkit-2cf6c8816a73e0132bd8fa3b509d62d7c51b6e47.tar.gz
Imported WebKit commit 7e538425aa020340619e927792f3d895061fb54b (http://svn.webkit.org/repository/webkit/trunk@116286)
Diffstat (limited to 'Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp')
-rw-r--r--Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp41
1 files changed, 17 insertions, 24 deletions
diff --git a/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp b/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp
index 75789e602..e8017b904 100644
--- a/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp
+++ b/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp
@@ -1,7 +1,7 @@
/*
* Copyright (C) 1999-2002 Harri Porten (porten@kde.org)
* Copyright (C) 2001 Peter Kelly (pmk@post.com)
- * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2012 Apple Inc. All rights reserved.
* Copyright (C) 2007 Cameron Zwarich (cwzwarich@uwaterloo.ca)
* Copyright (C) 2007 Maks Orlovich
*
@@ -295,17 +295,20 @@ static double parseInt(const UString& s, const CharType* data, int radix)
number += digit;
++p;
}
- if (number >= mantissaOverflowLowerBound) {
- if (radix == 10)
- number = WTF::strtod<WTF::AllowTrailingJunk>(s.substringSharingImpl(firstDigitPosition, p - firstDigitPosition).utf8().data(), 0);
- else if (radix == 2 || radix == 4 || radix == 8 || radix == 16 || radix == 32)
- number = parseIntOverflow(s.substringSharingImpl(firstDigitPosition, p - firstDigitPosition).utf8().data(), p - firstDigitPosition, radix);
- }
// 12. If Z is empty, return NaN.
if (!sawDigit)
return std::numeric_limits<double>::quiet_NaN();
+ // Alternate code path for certain large numbers.
+ if (number >= mantissaOverflowLowerBound) {
+ if (radix == 10) {
+ size_t parsedLength;
+ number = parseDouble(s.characters() + firstDigitPosition, p - firstDigitPosition, parsedLength);
+ } else if (radix == 2 || radix == 4 || radix == 8 || radix == 16 || radix == 32)
+ number = parseIntOverflow(s.substringSharingImpl(firstDigitPosition, p - firstDigitPosition).utf8().data(), p - firstDigitPosition, radix);
+ }
+
// 15. Return sign x number.
return sign * number;
}
@@ -361,20 +364,10 @@ static double jsStrDecimalLiteral(const CharType*& data, const CharType* end)
{
ASSERT(data < end);
- // Copy the sting into a null-terminated byte buffer, and call strtod.
- Vector<char, 32> byteBuffer;
- for (const CharType* characters = data; characters < end; ++characters) {
- CharType character = *characters;
- byteBuffer.append(isASCII(character) ? static_cast<char>(character) : 0);
- }
- byteBuffer.append(0);
- char* endOfNumber;
- double number = WTF::strtod<WTF::AllowTrailingJunk>(byteBuffer.data(), &endOfNumber);
-
- // Check if strtod found a number; if so return it.
- ptrdiff_t consumed = endOfNumber - byteBuffer.data();
- if (consumed) {
- data += consumed;
+ size_t parsedLength;
+ double number = parseDouble(data, end - data, parsedLength);
+ if (parsedLength) {
+ data += parsedLength;
return number;
}
@@ -505,7 +498,7 @@ EncodedJSValue JSC_HOST_CALL globalFuncEval(ExecState* exec)
{
JSObject* thisObject = exec->hostThisValue().toThisObject(exec);
JSObject* unwrappedObject = thisObject->unwrappedObject();
- if (!unwrappedObject->isGlobalObject() || static_cast<JSGlobalObject*>(unwrappedObject)->evalFunction() != exec->callee())
+ if (!unwrappedObject->isGlobalObject() || jsCast<JSGlobalObject*>(unwrappedObject)->evalFunction() != exec->callee())
return throwVMError(exec, createEvalError(exec, "The \"this\" value passed to eval must be the global object from which eval originated"));
JSValue x = exec->argument(0);
@@ -525,11 +518,11 @@ EncodedJSValue JSC_HOST_CALL globalFuncEval(ExecState* exec)
}
EvalExecutable* eval = EvalExecutable::create(exec, makeSource(s), false);
- JSObject* error = eval->compile(exec, static_cast<JSGlobalObject*>(unwrappedObject)->globalScopeChain());
+ JSObject* error = eval->compile(exec, jsCast<JSGlobalObject*>(unwrappedObject)->globalScopeChain());
if (error)
return throwVMError(exec, error);
- return JSValue::encode(exec->interpreter()->execute(eval, exec, thisObject, static_cast<JSGlobalObject*>(unwrappedObject)->globalScopeChain()));
+ return JSValue::encode(exec->interpreter()->execute(eval, exec, thisObject, jsCast<JSGlobalObject*>(unwrappedObject)->globalScopeChain()));
}
EncodedJSValue JSC_HOST_CALL globalFuncParseInt(ExecState* exec)