[SCM] WebKit Debian packaging branch, webkit-1.2, updated. upstream/1.1.90-6072-g9a69373
tkent at chromium.org
tkent at chromium.org
Wed Apr 7 23:48:36 UTC 2010
The following commit has been merged in the webkit-1.2 branch:
commit e2a781159b12fe0d5b29704171dea99720e3bd3f
Author: tkent at chromium.org <tkent at chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Thu Nov 19 03:12:50 2009 +0000
2009-11-18 Kent Tamura <tkent at chromium.org>
Reviewed by Darin Adler.
Move UString::from(double) implementation to new
WTF::doubleToStringInJavaScriptFormat(), and expose it because WebCore
code will use it.
https://bugs.webkit.org/show_bug.cgi?id=31330
- Introduce new function createRep(const char*, unsigned) and
UString::UString(const char*, unsigned) to reduce 2 calls to strlen().
- Fix a bug that dtoa() doesn't update *rve if the input value is NaN
or Infinity.
No new tests because this doesn't change the behavior.
* JavaScriptCore.exp:
* JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def:
* runtime/UString.cpp:
(JSC::createRep):
(JSC::UString::UString):
(JSC::UString::from): Move the code to doubleToStringInJavaScriptFormat().
* runtime/UString.h:
* wtf/dtoa.cpp:
(WTF::dtoa): Fix a bug about rve.
(WTF::append): A helper for doubleToStringInJavaScriptFormat().
(WTF::doubleToStringInJavaScriptFormat): Move the code from UString::from(double).
* wtf/dtoa.h:
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@51168 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog
index aff606e..8261127 100644
--- a/JavaScriptCore/ChangeLog
+++ b/JavaScriptCore/ChangeLog
@@ -1,3 +1,32 @@
+2009-11-18 Kent Tamura <tkent at chromium.org>
+
+ Reviewed by Darin Adler.
+
+ Move UString::from(double) implementation to new
+ WTF::doubleToStringInJavaScriptFormat(), and expose it because WebCore
+ code will use it.
+ https://bugs.webkit.org/show_bug.cgi?id=31330
+
+ - Introduce new function createRep(const char*, unsigned) and
+ UString::UString(const char*, unsigned) to reduce 2 calls to strlen().
+ - Fix a bug that dtoa() doesn't update *rve if the input value is NaN
+ or Infinity.
+
+ No new tests because this doesn't change the behavior.
+
+ * JavaScriptCore.exp:
+ * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def:
+ * runtime/UString.cpp:
+ (JSC::createRep):
+ (JSC::UString::UString):
+ (JSC::UString::from): Move the code to doubleToStringInJavaScriptFormat().
+ * runtime/UString.h:
+ * wtf/dtoa.cpp:
+ (WTF::dtoa): Fix a bug about rve.
+ (WTF::append): A helper for doubleToStringInJavaScriptFormat().
+ (WTF::doubleToStringInJavaScriptFormat): Move the code from UString::from(double).
+ * wtf/dtoa.h:
+
2009-11-18 Laszlo Gombos <laszlo.1.gombos at nokia.com>
Reviewed by Kenneth Rohde Christiansen.
diff --git a/JavaScriptCore/JavaScriptCore.exp b/JavaScriptCore/JavaScriptCore.exp
index 30f1bbc..231fddd 100644
--- a/JavaScriptCore/JavaScriptCore.exp
+++ b/JavaScriptCore/JavaScriptCore.exp
@@ -331,6 +331,7 @@ __ZN3WTF21RefCountedLeakCounterD1Ev
__ZN3WTF23waitForThreadCompletionEjPPv
__ZN3WTF27releaseFastMallocFreeMemoryEv
__ZN3WTF28setMainThreadCallbacksPausedEb
+__ZN3WTF32doubleToStringInJavaScriptFormatEdPcPj
__ZN3WTF36lockAtomicallyInitializedStaticMutexEv
__ZN3WTF37parseDateFromNullTerminatedCharactersEPKc
__ZN3WTF38unlockAtomicallyInitializedStaticMutexEv
diff --git a/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def b/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def
index a2781ca..6b18236 100644
--- a/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def
+++ b/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def
@@ -114,6 +114,7 @@ EXPORTS
?detachThread at WTF@@YAXI at Z
?didTimeOut at TimeoutChecker@JSC@@QAE_NPAVExecState at 2@@Z
?dumpSampleData at JSGlobalData@JSC@@QAEXPAVExecState at 2@@Z
+ ?doubleToStringInJavaScriptFormat at WTF@@YAXNQADPAI at Z
?enumerable at PropertyDescriptor@JSC@@QBE_NXZ
?equal at Identifier@JSC@@SA_NPBURep at UString@2 at PBD@Z
?equal at JSC@@YA_NPBURep at UString@1 at 0@Z
diff --git a/JavaScriptCore/runtime/UString.cpp b/JavaScriptCore/runtime/UString.cpp
index e66ca93..477d244 100644
--- a/JavaScriptCore/runtime/UString.cpp
+++ b/JavaScriptCore/runtime/UString.cpp
@@ -578,11 +578,33 @@ static PassRefPtr<UString::Rep> createRep(const char* c)
}
+static inline PassRefPtr<UString::Rep> createRep(const char* c, int length)
+{
+ if (!c)
+ return &UString::Rep::null();
+
+ if (!length)
+ return &UString::Rep::empty();
+
+ UChar* d;
+ if (!allocChars(length).getValue(d))
+ return &UString::Rep::null();
+
+ for (int i = 0; i < length; i++)
+ d[i] = static_cast<unsigned char>(c[i]); // use unsigned char to zero-extend instead of sign-extend
+ return UString::Rep::create(d, length);
+}
+
UString::UString(const char* c)
: m_rep(createRep(c))
{
}
+UString::UString(const char* c, int length)
+ : m_rep(createRep(c, length))
+{
+}
+
UString::UString(const UChar* c, int length)
{
if (length == 0)
@@ -1025,69 +1047,10 @@ UString UString::from(long l)
UString UString::from(double d)
{
- // avoid ever printing -NaN, in JS conceptually there is only one NaN value
- if (isnan(d))
- return "NaN";
- if (!d)
- return "0"; // -0 -> "0"
-
- char buf[80];
- int decimalPoint;
- int sign;
-
- char result[80];
- WTF::dtoa(result, d, 0, &decimalPoint, &sign, NULL);
- int length = static_cast<int>(strlen(result));
-
- int i = 0;
- if (sign)
- buf[i++] = '-';
-
- if (decimalPoint <= 0 && decimalPoint > -6) {
- buf[i++] = '0';
- buf[i++] = '.';
- for (int j = decimalPoint; j < 0; j++)
- buf[i++] = '0';
- strcpy(buf + i, result);
- } else if (decimalPoint <= 21 && decimalPoint > 0) {
- if (length <= decimalPoint) {
- strcpy(buf + i, result);
- i += length;
- for (int j = 0; j < decimalPoint - length; j++)
- buf[i++] = '0';
- buf[i] = '\0';
- } else {
- strncpy(buf + i, result, decimalPoint);
- i += decimalPoint;
- buf[i++] = '.';
- strcpy(buf + i, result + decimalPoint);
- }
- } else if (result[0] < '0' || result[0] > '9')
- strcpy(buf + i, result);
- else {
- buf[i++] = result[0];
- if (length > 1) {
- buf[i++] = '.';
- strcpy(buf + i, result + 1);
- i += length - 1;
- }
-
- buf[i++] = 'e';
- buf[i++] = (decimalPoint >= 0) ? '+' : '-';
- // decimalPoint can't be more than 3 digits decimal given the
- // nature of float representation
- int exponential = decimalPoint - 1;
- if (exponential < 0)
- exponential = -exponential;
- if (exponential >= 100)
- buf[i++] = static_cast<char>('0' + exponential / 100);
- if (exponential >= 10)
- buf[i++] = static_cast<char>('0' + (exponential % 100) / 10);
- buf[i++] = static_cast<char>('0' + exponential % 10);
- buf[i++] = '\0';
- }
-
- return UString(buf);
+ DtoaBuffer buffer;
+ unsigned length;
+ doubleToStringInJavaScriptFormat(d, buffer, &length);
+ return UString(buffer, length);
}
UString UString::spliceSubstringsWithSeparators(const Range* substringRanges, int rangeCount, const UString* separators, int separatorCount) const
diff --git a/JavaScriptCore/runtime/UString.h b/JavaScriptCore/runtime/UString.h
index c4dad2a..9b046f2 100644
--- a/JavaScriptCore/runtime/UString.h
+++ b/JavaScriptCore/runtime/UString.h
@@ -235,7 +235,10 @@ namespace JSC {
public:
UString();
+ // Constructor for null-terminated ASCII string.
UString(const char*);
+ // Constructor for non-null-terminated ASCII string.
+ UString(const char*, int length);
UString(const UChar*, int length);
UString(UChar*, int length, bool copy);
diff --git a/JavaScriptCore/wtf/dtoa.cpp b/JavaScriptCore/wtf/dtoa.cpp
index d75c17a..6f58cb7 100644
--- a/JavaScriptCore/wtf/dtoa.cpp
+++ b/JavaScriptCore/wtf/dtoa.cpp
@@ -148,6 +148,7 @@
#include <wtf/AlwaysInline.h>
#include <wtf/Assertions.h>
#include <wtf/FastMalloc.h>
+#include <wtf/MathExtras.h>
#include <wtf/Vector.h>
#include <wtf/Threading.h>
@@ -1869,7 +1870,7 @@ static ALWAYS_INLINE int quorem(BigInt& b, BigInt& S)
* calculation.
*/
-void dtoa(char* result, double dd, int ndigits, int* decpt, int* sign, char** rve)
+void dtoa(DtoaBuffer result, double dd, int ndigits, int* decpt, int* sign, char** rve)
{
/*
Arguments ndigits, decpt, sign are similar to those
@@ -1908,16 +1909,23 @@ void dtoa(char* result, double dd, int ndigits, int* decpt, int* sign, char** rv
{
/* Infinity or NaN */
*decpt = 9999;
- if (!word1(&u) && !(word0(&u) & 0xfffff))
+ if (!word1(&u) && !(word0(&u) & 0xfffff)) {
strcpy(result, "Infinity");
- else
+ if (rve)
+ *rve = result + 8;
+ } else {
strcpy(result, "NaN");
+ if (rve)
+ *rve = result + 3;
+ }
return;
}
if (!dval(&u)) {
*decpt = 1;
result[0] = '0';
result[1] = '\0';
+ if (rve)
+ *rve = result + 1;
return;
}
@@ -2376,4 +2384,83 @@ ret:
*rve = s;
}
+static ALWAYS_INLINE void append(char*& next, const char* src, unsigned size)
+{
+ for (unsigned i = 0; i < size; ++i)
+ *next++ = *src++;
+}
+
+void doubleToStringInJavaScriptFormat(double d, DtoaBuffer buffer, unsigned* resultLength)
+{
+ ASSERT(buffer);
+
+ // avoid ever printing -NaN, in JS conceptually there is only one NaN value
+ if (isnan(d)) {
+ append(buffer, "NaN", 3);
+ if (resultLength)
+ *resultLength = 3;
+ return;
+ }
+ // -0 -> "0"
+ if (!d) {
+ buffer[0] = '0';
+ if (resultLength)
+ *resultLength = 1;
+ return;
+ }
+
+ int decimalPoint;
+ int sign;
+
+ DtoaBuffer result;
+ char* resultEnd = 0;
+ WTF::dtoa(result, d, 0, &decimalPoint, &sign, &resultEnd);
+ int length = resultEnd - result;
+
+ char* next = buffer;
+ if (sign)
+ *next++ = '-';
+
+ if (decimalPoint <= 0 && decimalPoint > -6) {
+ *next++ = '0';
+ *next++ = '.';
+ for (int j = decimalPoint; j < 0; j++)
+ *next++ = '0';
+ append(next, result, length);
+ } else if (decimalPoint <= 21 && decimalPoint > 0) {
+ if (length <= decimalPoint) {
+ append(next, result, length);
+ for (int j = 0; j < decimalPoint - length; j++)
+ *next++ = '0';
+ } else {
+ append(next, result, decimalPoint);
+ *next++ = '.';
+ append(next, result + decimalPoint, length - decimalPoint);
+ }
+ } else if (result[0] < '0' || result[0] > '9')
+ append(next, result, length);
+ else {
+ *next++ = result[0];
+ if (length > 1) {
+ *next++ = '.';
+ append(next, result + 1, length - 1);
+ }
+
+ *next++ = 'e';
+ *next++ = (decimalPoint >= 0) ? '+' : '-';
+ // decimalPoint can't be more than 3 digits decimal given the
+ // nature of float representation
+ int exponential = decimalPoint - 1;
+ if (exponential < 0)
+ exponential = -exponential;
+ if (exponential >= 100)
+ *next++ = static_cast<char>('0' + exponential / 100);
+ if (exponential >= 10)
+ *next++ = static_cast<char>('0' + (exponential % 100) / 10);
+ *next++ = static_cast<char>('0' + exponential % 10);
+ }
+ if (resultLength)
+ *resultLength = next - buffer;
+}
+
} // namespace WTF
diff --git a/JavaScriptCore/wtf/dtoa.h b/JavaScriptCore/wtf/dtoa.h
index cbec7c7..6127f53 100644
--- a/JavaScriptCore/wtf/dtoa.h
+++ b/JavaScriptCore/wtf/dtoa.h
@@ -30,8 +30,18 @@ namespace WTF {
extern WTF::Mutex* s_dtoaP5Mutex;
double strtod(const char* s00, char** se);
- void dtoa(char* result, double d, int ndigits, int* decpt, int* sign, char** rve);
+
+ typedef char DtoaBuffer[80];
+ void dtoa(DtoaBuffer result, double d, int ndigits, int* decpt, int* sign, char** rve);
+
+ // dtoa() for ECMA-262 'ToString Applied to the Number Type.'
+ // The *resultLength will have the length of the resultant string in bufer.
+ // The resultant string isn't terminated by 0.
+ void doubleToStringInJavaScriptFormat(double, DtoaBuffer, unsigned* resultLength);
} // namespace WTF
+using WTF::DtoaBuffer;
+using WTF::doubleToStringInJavaScriptFormat;
+
#endif // WTF_dtoa_h
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list