⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 183977 in webkit


Ignore:
Timestamp:
May 7, 2015, 8:27:11 PM (11 years ago)
Author:
commit-queue@webkit.org
Message:

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

Location:
trunk/Source
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r183974 r183977  
     12015-05-07  Commit Queue  <commit-queue@webkit.org>
     2
     3        Unreviewed, rolling out r183961.
     4        https://bugs.webkit.org/show_bug.cgi?id=144784
     5
     6        Broke js/dom/JSON-stringify.html (Requested by kling on
     7        #webkit).
     8
     9        Reverted changeset:
     10
     11        "Optimize serialization of quoted JSON strings."
     12        https://bugs.webkit.org/show_bug.cgi?id=144754
     13        http://trac.webkit.org/changeset/183961
     14
    1152015-05-07  Filip Pizlo  <fpizlo@apple.com>
    216
  • trunk/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp

    r183961 r183977  
    30883088    for (size_t i = 0; i < m_targetPatterns.size(); i++) {
    30893089        if (m_targetPatterns[i].wasString)
    3090             builder.appendQuotedJSONString(m_targetPatterns[i].propertyName.string());
     3090            appendQuotedJSONStringToBuilder(builder, m_targetPatterns[i].propertyName.string());
    30913091        else
    30923092            builder.append(m_targetPatterns[i].propertyName.string());
  • trunk/Source/JavaScriptCore/runtime/JSONObject.cpp

    r183961 r183977  
    108108    friend class Holder;
    109109
     110    static void appendQuotedString(StringBuilder&, const String&);
     111
    110112    JSValue toJSON(JSValue, const PropertyNameForFunctionCall&);
    111113
     
    254256}
    255257
     258template <typename CharType>
     259static void appendStringToStringBuilder(StringBuilder& builder, const CharType* data, int length)
     260{
     261    for (int i = 0; i < length; ++i) {
     262        int start = i;
     263        while (i < length && (data[i] > 0x1F && data[i] != '"' && data[i] != '\\'))
     264            ++i;
     265        builder.append(data + start, i - start);
     266        if (i >= length)
     267            break;
     268        switch (data[i]) {
     269        case '\t':
     270            builder.append('\\');
     271            builder.append('t');
     272            break;
     273        case '\r':
     274            builder.append('\\');
     275            builder.append('r');
     276            break;
     277        case '\n':
     278            builder.append('\\');
     279            builder.append('n');
     280            break;
     281        case '\f':
     282            builder.append('\\');
     283            builder.append('f');
     284            break;
     285        case '\b':
     286            builder.append('\\');
     287            builder.append('b');
     288            break;
     289        case '"':
     290            builder.append('\\');
     291            builder.append('"');
     292            break;
     293        case '\\':
     294            builder.append('\\');
     295            builder.append('\\');
     296            break;
     297        default:
     298            static const char hexDigits[] = "0123456789abcdef";
     299            UChar ch = data[i];
     300            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]) };
     301            builder.append(hex, WTF_ARRAY_LENGTH(hex));
     302            break;
     303        }
     304    }
     305}
     306
     307void appendQuotedJSONStringToBuilder(StringBuilder& builder, const String& message)
     308{
     309    builder.append('"');
     310
     311    if (message.is8Bit())
     312        appendStringToStringBuilder(builder, message.characters8(), message.length());
     313    else
     314        appendStringToStringBuilder(builder, message.characters16(), message.length());
     315
     316    builder.append('"');
     317}
     318
     319void Stringifier::appendQuotedString(StringBuilder& builder, const String& value)
     320{
     321    appendQuotedJSONStringToBuilder(builder, value);
     322}
     323
    256324inline JSValue Stringifier::toJSON(JSValue value, const PropertyNameForFunctionCall& propertyName)
    257325{
     
    318386    String stringValue;
    319387    if (value.getString(m_exec, stringValue)) {
    320         builder.appendQuotedJSONString(stringValue);
     388        appendQuotedString(builder, stringValue);
    321389        return StringifySucceeded;
    322390    }
     
    489557
    490558        // Append the property name.
    491         builder.appendQuotedJSONString(propertyName.string());
     559        appendQuotedString(builder, propertyName.string());
    492560        builder.append(':');
    493561        if (stringifier.willIndent())
  • trunk/Source/JavaScriptCore/runtime/JSONObject.h

    r183961 r183977  
    6363JS_EXPORT_PRIVATE String JSONStringify(ExecState*, JSValue, unsigned indent);
    6464
     65JS_EXPORT_PRIVATE void appendQuotedJSONStringToBuilder(StringBuilder&, const String&);
     66
    6567   
    6668} // namespace JSC
  • trunk/Source/WTF/ChangeLog

    r183961 r183977  
     12015-05-07  Commit Queue  <commit-queue@webkit.org>
     2
     3        Unreviewed, rolling out r183961.
     4        https://bugs.webkit.org/show_bug.cgi?id=144784
     5
     6        Broke js/dom/JSON-stringify.html (Requested by kling on
     7        #webkit).
     8
     9        Reverted changeset:
     10
     11        "Optimize serialization of quoted JSON strings."
     12        https://bugs.webkit.org/show_bug.cgi?id=144754
     13        http://trac.webkit.org/changeset/183961
     14
    1152015-05-07  Andreas Kling  <akling@apple.com>
    216
  • trunk/Source/WTF/wtf/text/StringBuilder.cpp

    r183961 r183977  
    2828#include "StringBuilder.h"
    2929
    30 #include "ASCIICType.h"
    3130#include "IntegerToStringConversion.h"
    32 #include "MathExtras.h"
    3331#include "WTFString.h"
    3432#include <wtf/dtoa.h>
     
    363361}
    364362
    365 template <typename OutputCharacterType, typename InputCharacterType>
    366 static void appendQuotedJSONStringInternal(OutputCharacterType*& output, const InputCharacterType* input, unsigned length)
    367 {
    368     for (const InputCharacterType* end = input + length; input != end; ++input) {
    369         if (*input > 0x1F && *input != '"' && *input != '\\') {
    370             *output++ = *input;
    371             continue;
    372         }
    373         switch (*input) {
    374         case '\t':
    375             *output++ = '\\';
    376             *output++ = 't';
    377             break;
    378         case '\r':
    379             *output++ = '\\';
    380             *output++ = 'r';
    381             break;
    382         case '\n':
    383             *output++ = '\\';
    384             *output++ = 'n';
    385             break;
    386         case '\f':
    387             *output++ = '\\';
    388             *output++ = 'f';
    389             break;
    390         case '\b':
    391             *output++ = '\\';
    392             *output++ = 'b';
    393             break;
    394         case '"':
    395             *output++ = '\\';
    396             *output++ = '"';
    397             break;
    398         case '\\':
    399             *output++ = '\\';
    400             *output++ = '\\';
    401             break;
    402         default:
    403             ASSERT((*input & 0xFF00) == 0);
    404             *output++ = '\\';
    405             *output++ = 'u';
    406             *output++ = '0';
    407             *output++ = '0';
    408             *output++ = upperNibbleToASCIIHexDigit(*input);
    409             *output++ = lowerNibbleToASCIIHexDigit(*input);
    410             break;
    411         }
    412     }
    413 }
    414 
    415 void StringBuilder::appendQuotedJSONString(const String& string)
    416 {
    417     // Make sure we have enough buffer space to append this string without having
    418     // to worry about reallocating in the middle.
    419     // The 2 is for the '"' quotes on each end.
    420     // The 'maximumOutputCharactersPerInputCharacter' is 6 for 16-bit characters
    421     // since they may need \uNNNN-style representation. 2 for 8-bit strings.
    422     unsigned maximumOutputCharactersPerInputCharacter = string.is8Bit() ? 2 : 6;
    423     size_t maximumCapacityRequired = length() + 2 + (string.length() * maximumOutputCharactersPerInputCharacter);
    424     RELEASE_ASSERT(maximumCapacityRequired < std::numeric_limits<unsigned>::max());
    425 
    426     if (is8Bit() && !string.is8Bit())
    427         allocateBufferUpConvert(m_bufferCharacters8, roundUpToPowerOfTwo(maximumCapacityRequired));
    428     else
    429         reserveCapacity(roundUpToPowerOfTwo(maximumCapacityRequired));
    430 
    431     if (is8Bit()) {
    432         ASSERT(string.is8Bit());
    433         LChar* output = m_bufferCharacters8 + m_length;
    434         *output++ = '"';
    435         appendQuotedJSONStringInternal(output, string.characters8(), string.length());
    436         *output++ = '"';
    437         m_length = output - m_bufferCharacters8;
    438     } else {
    439         UChar* output = m_bufferCharacters16 + m_length;
    440         *output++ = '"';
    441         if (string.is8Bit())
    442             appendQuotedJSONStringInternal(output, string.characters8(), string.length());
    443         else
    444             appendQuotedJSONStringInternal(output, string.characters16(), string.length());
    445         *output++ = '"';
    446         m_length = output - m_bufferCharacters16;
    447     }
    448 }
    449 
    450363} // namespace WTF
  • trunk/Source/WTF/wtf/text/StringBuilder.h

    r183961 r183977  
    160160    }
    161161
    162     WTF_EXPORT_PRIVATE void appendQuotedJSONString(const String&);
    163 
    164162    template<unsigned charactersCount>
    165163    ALWAYS_INLINE void appendLiteral(const char (&characters)[charactersCount]) { append(characters, charactersCount - 1); }
  • trunk/Source/WebKit2/ChangeLog

    r183976 r183977  
     12015-05-07  Commit Queue  <commit-queue@webkit.org>
     2
     3        Unreviewed, rolling out r183961.
     4        https://bugs.webkit.org/show_bug.cgi?id=144784
     5
     6        Broke js/dom/JSON-stringify.html (Requested by kling on
     7        #webkit).
     8
     9        Reverted changeset:
     10
     11        "Optimize serialization of quoted JSON strings."
     12        https://bugs.webkit.org/show_bug.cgi?id=144754
     13        http://trac.webkit.org/changeset/183961
     14
    1152015-05-07  Anders Carlsson  <andersca@apple.com>
    216
  • trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEntry.cpp

    r183961 r183977  
    3131#include "NetworkCacheDecoder.h"
    3232#include "NetworkCacheEncoder.h"
     33#include <JavaScriptCore/JSONObject.h>
    3334#include <WebCore/ResourceRequest.h>
    3435#include <WebCore/SharedBuffer.h>
     
    159160    json.appendLiteral("{\n");
    160161    json.appendLiteral("\"hash\": ");
    161     json.appendQuotedJSONString(m_key.hashAsString());
     162    JSC::appendQuotedJSONStringToBuilder(json, m_key.hashAsString());
    162163    json.appendLiteral(",\n");
    163164    json.appendLiteral("\"bodySize\": ");
     
    168169    json.appendLiteral(",\n");
    169170    json.appendLiteral("\"partition\": ");
    170     json.appendQuotedJSONString(m_key.partition());
     171    JSC::appendQuotedJSONStringToBuilder(json, m_key.partition());
    171172    json.appendLiteral(",\n");
    172173    json.appendLiteral("\"timestamp\": ");
     
    174175    json.appendLiteral(",\n");
    175176    json.appendLiteral("\"URL\": ");
    176     json.appendQuotedJSONString(m_response.url().string());
     177    JSC::appendQuotedJSONStringToBuilder(json, m_response.url().string());
    177178    json.appendLiteral(",\n");
    178179    json.appendLiteral("\"bodyHash\": ");
    179     json.appendQuotedJSONString(info.bodyHash);
     180    JSC::appendQuotedJSONStringToBuilder(json, info.bodyHash);
    180181    json.appendLiteral(",\n");
    181182    json.appendLiteral("\"bodyShareCount\": ");
     
    189190        firstHeader = false;
    190191        json.appendLiteral("    ");
    191         json.appendQuotedJSONString(header.key);
     192        JSC::appendQuotedJSONStringToBuilder(json, header.key);
    192193        json.appendLiteral(": ");
    193         json.appendQuotedJSONString(header.value);
     194        JSC::appendQuotedJSONStringToBuilder(json, header.value);
    194195    }
    195196    json.appendLiteral("\n}\n");
Note: See TracChangeset for help on using the changeset viewer.