Unreviewed, rolling out r183961.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 May 2015 03:27:11 +0000 (03:27 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 May 2015 03:27:11 +0000 (03:27 +0000)
https://bugs.webkit.org/show_bug.cgi?id=144784

Broke js/dom/JSON-stringify.html (Requested by kling on
#webkit).

Reverted changeset:

"Optimize serialization of quoted JSON strings."
https://bugs.webkit.org/show_bug.cgi?id=144754
http://trac.webkit.org/changeset/183961

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@183977 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp
Source/JavaScriptCore/runtime/JSONObject.cpp
Source/JavaScriptCore/runtime/JSONObject.h
Source/WTF/ChangeLog
Source/WTF/wtf/text/StringBuilder.cpp
Source/WTF/wtf/text/StringBuilder.h
Source/WebKit2/ChangeLog
Source/WebKit2/NetworkProcess/cache/NetworkCacheEntry.cpp

index ffaaada..03461b1 100644 (file)
@@ -1,3 +1,17 @@
+2015-05-07  Commit Queue  <commit-queue@webkit.org>
+
+        Unreviewed, rolling out r183961.
+        https://bugs.webkit.org/show_bug.cgi?id=144784
+
+        Broke js/dom/JSON-stringify.html (Requested by kling on
+        #webkit).
+
+        Reverted changeset:
+
+        "Optimize serialization of quoted JSON strings."
+        https://bugs.webkit.org/show_bug.cgi?id=144754
+        http://trac.webkit.org/changeset/183961
+
 2015-05-07  Filip Pizlo  <fpizlo@apple.com>
 
         GC has trouble with pathologically large array allocations
index 39b03cd..8fe5b29 100644 (file)
@@ -3087,7 +3087,7 @@ void ObjectPatternNode::toString(StringBuilder& builder) const
     builder.append('{');
     for (size_t i = 0; i < m_targetPatterns.size(); i++) {
         if (m_targetPatterns[i].wasString)
-            builder.appendQuotedJSONString(m_targetPatterns[i].propertyName.string());
+            appendQuotedJSONStringToBuilder(builder, m_targetPatterns[i].propertyName.string());
         else
             builder.append(m_targetPatterns[i].propertyName.string());
         builder.append(':');
index 9940658..581bd45 100644 (file)
@@ -107,6 +107,8 @@ private:
 
     friend class Holder;
 
+    static void appendQuotedString(StringBuilder&, const String&);
+
     JSValue toJSON(JSValue, const PropertyNameForFunctionCall&);
 
     enum StringifyResult { StringifyFailed, StringifySucceeded, StringifyFailedDueToUndefinedValue };
@@ -253,6 +255,72 @@ Local<Unknown> Stringifier::stringify(Handle<Unknown> value)
     return Local<Unknown>(m_exec->vm(), jsString(m_exec, result.toString()));
 }
 
+template <typename CharType>
+static void appendStringToStringBuilder(StringBuilder& builder, const CharType* data, int length)
+{
+    for (int i = 0; i < length; ++i) {
+        int start = i;
+        while (i < length && (data[i] > 0x1F && data[i] != '"' && data[i] != '\\'))
+            ++i;
+        builder.append(data + start, i - start);
+        if (i >= length)
+            break;
+        switch (data[i]) {
+        case '\t':
+            builder.append('\\');
+            builder.append('t');
+            break;
+        case '\r':
+            builder.append('\\');
+            builder.append('r');
+            break;
+        case '\n':
+            builder.append('\\');
+            builder.append('n');
+            break;
+        case '\f':
+            builder.append('\\');
+            builder.append('f');
+            break;
+        case '\b':
+            builder.append('\\');
+            builder.append('b');
+            break;
+        case '"':
+            builder.append('\\');
+            builder.append('"');
+            break;
+        case '\\':
+            builder.append('\\');
+            builder.append('\\');
+            break;
+        default:
+            static const char hexDigits[] = "0123456789abcdef";
+            UChar ch = data[i];
+            LChar hex[] = { '\\', 'u', static_cast<LChar>(hexDigits[(ch >> 12) & 0xF]), static_cast<LChar>(hexDigits[(ch >> 8) & 0xF]), static_cast<LChar>(hexDigits[(ch >> 4) & 0xF]), static_cast<LChar>(hexDigits[ch & 0xF]) };
+            builder.append(hex, WTF_ARRAY_LENGTH(hex));
+            break;
+        }
+    }
+}
+
+void appendQuotedJSONStringToBuilder(StringBuilder& builder, const String& message)
+{
+    builder.append('"');
+
+    if (message.is8Bit())
+        appendStringToStringBuilder(builder, message.characters8(), message.length());
+    else
+        appendStringToStringBuilder(builder, message.characters16(), message.length());
+
+    builder.append('"');
+}
+
+void Stringifier::appendQuotedString(StringBuilder& builder, const String& value)
+{
+    appendQuotedJSONStringToBuilder(builder, value);
+}
+
 inline JSValue Stringifier::toJSON(JSValue value, const PropertyNameForFunctionCall& propertyName)
 {
     ASSERT(!m_exec->hadException());
@@ -317,7 +385,7 @@ Stringifier::StringifyResult Stringifier::appendStringifiedValue(StringBuilder&
 
     String stringValue;
     if (value.getString(m_exec, stringValue)) {
-        builder.appendQuotedJSONString(stringValue);
+        appendQuotedString(builder, stringValue);
         return StringifySucceeded;
     }
 
@@ -488,7 +556,7 @@ bool Stringifier::Holder::appendNextProperty(Stringifier& stringifier, StringBui
         stringifier.startNewLine(builder);
 
         // Append the property name.
-        builder.appendQuotedJSONString(propertyName.string());
+        appendQuotedString(builder, propertyName.string());
         builder.append(':');
         if (stringifier.willIndent())
             builder.append(' ');
index d550525..eb6daad 100644 (file)
@@ -62,6 +62,8 @@ private:
 JS_EXPORT_PRIVATE JSValue JSONParse(ExecState*, const String&);
 JS_EXPORT_PRIVATE String JSONStringify(ExecState*, JSValue, unsigned indent);
 
+JS_EXPORT_PRIVATE void appendQuotedJSONStringToBuilder(StringBuilder&, const String&);
+
     
 } // namespace JSC
 
index 1bb27f5..70494cd 100644 (file)
@@ -1,3 +1,17 @@
+2015-05-07  Commit Queue  <commit-queue@webkit.org>
+
+        Unreviewed, rolling out r183961.
+        https://bugs.webkit.org/show_bug.cgi?id=144784
+
+        Broke js/dom/JSON-stringify.html (Requested by kling on
+        #webkit).
+
+        Reverted changeset:
+
+        "Optimize serialization of quoted JSON strings."
+        https://bugs.webkit.org/show_bug.cgi?id=144754
+        http://trac.webkit.org/changeset/183961
+
 2015-05-07  Andreas Kling  <akling@apple.com>
 
         Optimize serialization of quoted JSON strings.
index b0b3fec..164b8c3 100644 (file)
@@ -27,9 +27,7 @@
 #include "config.h"
 #include "StringBuilder.h"
 
-#include "ASCIICType.h"
 #include "IntegerToStringConversion.h"
-#include "MathExtras.h"
 #include "WTFString.h"
 #include <wtf/dtoa.h>
 
@@ -362,89 +360,4 @@ void StringBuilder::shrinkToFit()
     }
 }
 
-template <typename OutputCharacterType, typename InputCharacterType>
-static void appendQuotedJSONStringInternal(OutputCharacterType*& output, const InputCharacterType* input, unsigned length)
-{
-    for (const InputCharacterType* end = input + length; input != end; ++input) {
-        if (*input > 0x1F && *input != '"' && *input != '\\') {
-            *output++ = *input;
-            continue;
-        }
-        switch (*input) {
-        case '\t':
-            *output++ = '\\';
-            *output++ = 't';
-            break;
-        case '\r':
-            *output++ = '\\';
-            *output++ = 'r';
-            break;
-        case '\n':
-            *output++ = '\\';
-            *output++ = 'n';
-            break;
-        case '\f':
-            *output++ = '\\';
-            *output++ = 'f';
-            break;
-        case '\b':
-            *output++ = '\\';
-            *output++ = 'b';
-            break;
-        case '"':
-            *output++ = '\\';
-            *output++ = '"';
-            break;
-        case '\\':
-            *output++ = '\\';
-            *output++ = '\\';
-            break;
-        default:
-            ASSERT((*input & 0xFF00) == 0);
-            *output++ = '\\';
-            *output++ = 'u';
-            *output++ = '0';
-            *output++ = '0';
-            *output++ = upperNibbleToASCIIHexDigit(*input);
-            *output++ = lowerNibbleToASCIIHexDigit(*input);
-            break;
-        }
-    }
-}
-
-void StringBuilder::appendQuotedJSONString(const String& string)
-{
-    // Make sure we have enough buffer space to append this string without having
-    // to worry about reallocating in the middle.
-    // The 2 is for the '"' quotes on each end.
-    // The 'maximumOutputCharactersPerInputCharacter' is 6 for 16-bit characters
-    // since they may need \uNNNN-style representation. 2 for 8-bit strings.
-    unsigned maximumOutputCharactersPerInputCharacter = string.is8Bit() ? 2 : 6;
-    size_t maximumCapacityRequired = length() + 2 + (string.length() * maximumOutputCharactersPerInputCharacter);
-    RELEASE_ASSERT(maximumCapacityRequired < std::numeric_limits<unsigned>::max());
-
-    if (is8Bit() && !string.is8Bit())
-        allocateBufferUpConvert(m_bufferCharacters8, roundUpToPowerOfTwo(maximumCapacityRequired));
-    else
-        reserveCapacity(roundUpToPowerOfTwo(maximumCapacityRequired));
-
-    if (is8Bit()) {
-        ASSERT(string.is8Bit());
-        LChar* output = m_bufferCharacters8 + m_length;
-        *output++ = '"';
-        appendQuotedJSONStringInternal(output, string.characters8(), string.length());
-        *output++ = '"';
-        m_length = output - m_bufferCharacters8;
-    } else {
-        UChar* output = m_bufferCharacters16 + m_length;
-        *output++ = '"';
-        if (string.is8Bit())
-            appendQuotedJSONStringInternal(output, string.characters8(), string.length());
-        else
-            appendQuotedJSONStringInternal(output, string.characters16(), string.length());
-        *output++ = '"';
-        m_length = output - m_bufferCharacters16;
-    }
-}
-
 } // namespace WTF
index be5c117..93422a2 100644 (file)
@@ -159,8 +159,6 @@ public:
         append(U16_TRAIL(c));
     }
 
-    WTF_EXPORT_PRIVATE void appendQuotedJSONString(const String&);
-
     template<unsigned charactersCount>
     ALWAYS_INLINE void appendLiteral(const char (&characters)[charactersCount]) { append(characters, charactersCount - 1); }
 
index 57563b3..23286f7 100644 (file)
@@ -1,3 +1,17 @@
+2015-05-07  Commit Queue  <commit-queue@webkit.org>
+
+        Unreviewed, rolling out r183961.
+        https://bugs.webkit.org/show_bug.cgi?id=144784
+
+        Broke js/dom/JSON-stringify.html (Requested by kling on
+        #webkit).
+
+        Reverted changeset:
+
+        "Optimize serialization of quoted JSON strings."
+        https://bugs.webkit.org/show_bug.cgi?id=144754
+        http://trac.webkit.org/changeset/183961
+
 2015-05-07  Anders Carlsson  <andersca@apple.com>
 
         Build fixes.
index 7350a5b..c34fc52 100644 (file)
@@ -30,6 +30,7 @@
 #include "NetworkCacheCoders.h"
 #include "NetworkCacheDecoder.h"
 #include "NetworkCacheEncoder.h"
+#include <JavaScriptCore/JSONObject.h>
 #include <WebCore/ResourceRequest.h>
 #include <WebCore/SharedBuffer.h>
 #include <wtf/text/StringBuilder.h>
@@ -158,7 +159,7 @@ void Entry::asJSON(StringBuilder& json, const Storage::RecordInfo& info) const
 {
     json.appendLiteral("{\n");
     json.appendLiteral("\"hash\": ");
-    json.appendQuotedJSONString(m_key.hashAsString());
+    JSC::appendQuotedJSONStringToBuilder(json, m_key.hashAsString());
     json.appendLiteral(",\n");
     json.appendLiteral("\"bodySize\": ");
     json.appendNumber(info.bodySize);
@@ -167,16 +168,16 @@ void Entry::asJSON(StringBuilder& json, const Storage::RecordInfo& info) const
     json.appendNumber(info.worth);
     json.appendLiteral(",\n");
     json.appendLiteral("\"partition\": ");
-    json.appendQuotedJSONString(m_key.partition());
+    JSC::appendQuotedJSONStringToBuilder(json, m_key.partition());
     json.appendLiteral(",\n");
     json.appendLiteral("\"timestamp\": ");
     json.appendNumber(std::chrono::duration_cast<std::chrono::milliseconds>(m_timeStamp.time_since_epoch()).count());
     json.appendLiteral(",\n");
     json.appendLiteral("\"URL\": ");
-    json.appendQuotedJSONString(m_response.url().string());
+    JSC::appendQuotedJSONStringToBuilder(json, m_response.url().string());
     json.appendLiteral(",\n");
     json.appendLiteral("\"bodyHash\": ");
-    json.appendQuotedJSONString(info.bodyHash);
+    JSC::appendQuotedJSONStringToBuilder(json, info.bodyHash);
     json.appendLiteral(",\n");
     json.appendLiteral("\"bodyShareCount\": ");
     json.appendNumber(info.bodyShareCount);
@@ -188,9 +189,9 @@ void Entry::asJSON(StringBuilder& json, const Storage::RecordInfo& info) const
             json.appendLiteral(",\n");
         firstHeader = false;
         json.appendLiteral("    ");
-        json.appendQuotedJSONString(header.key);
+        JSC::appendQuotedJSONStringToBuilder(json, header.key);
         json.appendLiteral(": ");
-        json.appendQuotedJSONString(header.value);
+        JSC::appendQuotedJSONStringToBuilder(json, header.value);
     }
     json.appendLiteral("\n}\n");
     json.appendLiteral("}");