Ignore:
Timestamp:
Aug 30, 2012, 2:23:51 PM (13 years ago)
Author:
[email protected]
Message:

Replace JSC::UString by WTF::String
https://bugs.webkit.org/show_bug.cgi?id=95271

Patch by Benjamin Poulain <[email protected]> on 2012-08-30
Reviewed by Geoffrey Garen.

Source/JavaScriptCore:

Having JSC::UString and WTF::String increase the complexity of working on WebKit, and
add useless conversions in the bindings. It also cause some code bloat.

The performance advantages of UString have been ported over in previous patches. This patch
is the last step: getting rid of UString.

In addition to the simplified code, this also reduce the binary size by 15kb on x86_64.

  • API/OpaqueJSString.cpp:

(OpaqueJSString::ustring):

  • runtime/Identifier.h:

(JSC::Identifier::ustring):
To avoid changing everything at once, the function named ustring() were kept as is. They
will be renamed in a follow up patch.

  • runtime/JSString.h:

(JSC::JSString::string):
(JSC::JSValue::toWTFString):
(JSC::inlineJSValueNotStringtoString):
(JSC::JSValue::toWTFStringInline):
Since JSValue::toString() already exist (and return the JSString), the direct accessor is renamed
to ::toWTFString(). We may change ::string() to ::jsString() and ::toWTFString() to ::toString()
in the future.

  • runtime/StringPrototype.cpp:

(JSC::substituteBackreferencesSlow): Replace the use of UString::getCharacters<>() by String::getCharactersWithUpconvert<>().

Source/WebCore:

Update the code to use String instead of UString.

On x86_64, this reduces the binary size by 22kb.

Since it is no longer possible to differenciate JSC::jsString() and WebCore::jsString() by the input
types, WebCore::jsString() is renated to WebCore::jsStringWithCache().

Since the cache is using a PtrHash, JSC::jsString() is used in place of the old WebCore::jsString() when
the string is generated locally. This is because the cache can never match in those cases.

Source/WebKit/blackberry:

Replace UString by String.

  • WebCoreSupport/ClientExtension.cpp:
  • WebCoreSupport/PagePopupBlackBerry.cpp:

(WebCore::PagePopupBlackBerry::installDomFunction):

Source/WebKit/efl:

Replace UString by String.

  • WebCoreSupport/DumpRenderTreeSupportEfl.cpp:

(DumpRenderTreeSupportEfl::sendWebIntentResponse):

  • ewk/ewk_frame.cpp:

(ewk_frame_script_execute):

Source/WebKit/gtk:

Replace UString by String.

  • gdom/ConvertToGCharPrivate.h:

(copyAsGchar):

Source/WebKit/mac:

Get rid of UString, replace it by String, and simplify the code when possible.

On x86_64, this reduces the binary size by 7kb.

  • Plugins/Hosted/NetscapePluginHostProxy.mm:

(identifierFromIdentifierRep):

  • Plugins/Hosted/NetscapePluginInstanceProxy.mm:

(WebKit::NetscapePluginInstanceProxy::addValueToArray):
(WebKit::NetscapePluginInstanceProxy::moveGlobalExceptionToExecState):

  • Plugins/Hosted/ProxyInstance.mm:

(WebKit::ProxyRuntimeMethod::create):
(WebKit::ProxyRuntimeMethod::finishCreation):
(WebKit::ProxyInstance::getPropertyNames):
(WebKit::ProxyInstance::methodsNamed):
(WebKit::ProxyInstance::fieldNamed):

  • WebView/WebFrame.mm:

(-[WebFrame _stringByEvaluatingJavaScriptFromString:forceUserGesture:]):
(-[WebFrame _stringByEvaluatingJavaScriptFromString:withGlobalObject:inScriptWorld:]):

  • WebView/WebScriptDebugDelegate.mm:

(-[WebScriptCallFrame functionName]):
(-[WebScriptCallFrame evaluateWebScript:]):

  • WebView/WebScriptDebugger.h:

(WTF):
(JSC):
(WebScriptDebugger):

  • WebView/WebScriptDebugger.mm:

(toNSURL):
(WebScriptDebugger::sourceParsed):

  • WebView/WebView.mm:

(aeDescFromJSValue):

Source/WebKit/qt:

Replace UString by String.

  • Api/qwebelement.cpp:

(QWebElement::evaluateJavaScript):

Source/WebKit/win:

Replace UString by String.

  • WebFrame.cpp:

(WebFrame::stringByEvaluatingJavaScriptInScriptWorld):

  • WebView.cpp:

(WebView::stringByEvaluatingJavaScriptFromString):

Source/WebKit/wx:

Update the #includes to use the correct types.

  • WebFrame.cpp:
  • WebView.cpp:

Source/WebKit2:

Update to code to switch from UString to String.

  • WebProcess/Plugins/Netscape/JSNPMethod.cpp:

(WebKit::JSNPMethod::finishCreation):

  • WebProcess/Plugins/Netscape/JSNPMethod.h:

(WebKit::JSNPMethod::create):
(JSNPMethod):

  • WebProcess/Plugins/Netscape/JSNPObject.cpp:

(WebKit::npIdentifierFromIdentifier):

  • WebProcess/Plugins/Netscape/NPRuntimeObjectMap.cpp:

(WebKit::NPRuntimeObjectMap::evaluate):
(WebKit::NPRuntimeObjectMap::moveGlobalExceptionToExecState):

Source/WTF:

  • wtf/Platform.h: Useless edit to force a full build. This is needed for some bots for some reason.
  • wtf/text/WTFString.h: Export a symbol that was exported on UString and needed in WebCore.

Add String::getCharactersWithUpconvert<>(), which is similar to String::getCharacters<>() but with the same
behaviors as UString::getCharacters<>().

String::getCharactersWithUpconvert<>() is useful when manipulating multiple strings, it allow writting code
using 16bits characters if any of the input String is not 8bit.

Tools:

Get rid of UString.

  • DumpRenderTree/efl/WorkQueueItemEfl.cpp:
  • gdb/webkit.py:

(WTFStringPrinter.to_string):
(JSCIdentifierPrinter.to_string):
(JSCJSStringPrinter.to_string):
(add_pretty_printers):

Websites/webkit.org:

Update the coding style to avoid mentioning a class that no longer exist.

  • coding/coding-style.html:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/runtime/JSONObject.cpp

    r126781 r127191  
    3737#include "Lookup.h"
    3838#include "PropertyNameArray.h"
    39 #include "UStringBuilder.h"
    40 #include "UStringConcatenate.h"
    4139#include <wtf/MathExtras.h>
     40#include <wtf/text/StringBuilder.h>
    4241
    4342namespace JSC {
     
    9594        JSObject* object() const { return m_object.get(); }
    9695
    97         bool appendNextProperty(Stringifier&, UStringBuilder&);
     96        bool appendNextProperty(Stringifier&, StringBuilder&);
    9897
    9998    private:
     
    108107    friend class Holder;
    109108
    110     static void appendQuotedString(UStringBuilder&, const UString&);
     109    static void appendQuotedString(StringBuilder&, const String&);
    111110
    112111    JSValue toJSON(JSValue, const PropertyNameForFunctionCall&);
    113112
    114113    enum StringifyResult { StringifyFailed, StringifySucceeded, StringifyFailedDueToUndefinedValue };
    115     StringifyResult appendStringifiedValue(UStringBuilder&, JSValue, JSObject* holder, const PropertyNameForFunctionCall&);
     114    StringifyResult appendStringifiedValue(StringBuilder&, JSValue, JSObject* holder, const PropertyNameForFunctionCall&);
    116115
    117116    bool willIndent() const;
    118117    void indent();
    119118    void unindent();
    120     void startNewLine(UStringBuilder&) const;
     119    void startNewLine(StringBuilder&) const;
    121120
    122121    ExecState* const m_exec;
     
    126125    CallType m_replacerCallType;
    127126    CallData m_replacerCallData;
    128     const UString m_gap;
     127    const String m_gap;
    129128
    130129    Vector<Holder, 16> m_holderStack;
    131     UString m_repeatedGap;
    132     UString m_indent;
     130    String m_repeatedGap;
     131    String m_indent;
    133132};
    134133
     
    149148}
    150149
    151 static inline UString gap(ExecState* exec, JSValue space)
     150static inline String gap(ExecState* exec, JSValue space)
    152151{
    153152    const unsigned maxGapLength = 10;
     
    167166        for (int i = 0; i < count; ++i)
    168167            spaces[i] = ' ';
    169         return UString(spaces, count);
     168        return String(spaces, count);
    170169    }
    171170
    172171    // If the space value is a string, use it as the gap string, otherwise use no gap string.
    173     UString spaces = space.getString(exec);
     172    String spaces = space.getString(exec);
    174173    if (spaces.length() > maxGapLength) {
    175174        spaces = spaces.substringSharingImpl(0, maxGapLength);
     
    246245    object->putDirect(m_exec->globalData(), m_exec->globalData().propertyNames->emptyIdentifier, value.get());
    247246
    248     UStringBuilder result;
     247    StringBuilder result;
    249248    if (appendStringifiedValue(result, value.get(), object, emptyPropertyName) != StringifySucceeded)
    250249        return Local<Unknown>(m_exec->globalData(), jsUndefined());
     
    252251        return Local<Unknown>(m_exec->globalData(), jsNull());
    253252
    254     return Local<Unknown>(m_exec->globalData(), jsString(m_exec, result.toUString()));
     253    return Local<Unknown>(m_exec->globalData(), jsString(m_exec, result.toString()));
    255254}
    256255
    257256template <typename CharType>
    258 static void appendStringToUStringBuilder(UStringBuilder& builder, const CharType* data, int length)
     257static void appendStringToStringBuilder(StringBuilder& builder, const CharType* data, int length)
    259258{
    260259    for (int i = 0; i < length; ++i) {
     
    304303}
    305304   
    306 void Stringifier::appendQuotedString(UStringBuilder& builder, const UString& value)
     305void Stringifier::appendQuotedString(StringBuilder& builder, const String& value)
    307306{
    308307    int length = value.length();
     
    311310
    312311    if (value.is8Bit())
    313         appendStringToUStringBuilder<LChar>(builder, value.characters8(), length);
     312        appendStringToStringBuilder<LChar>(builder, value.characters8(), length);
    314313    else
    315         appendStringToUStringBuilder<UChar>(builder, value.characters16(), length);
     314        appendStringToStringBuilder<UChar>(builder, value.characters16(), length);
    316315
    317316    builder.append('"');
     
    342341}
    343342
    344 Stringifier::StringifyResult Stringifier::appendStringifiedValue(UStringBuilder& builder, JSValue value, JSObject* holder, const PropertyNameForFunctionCall& propertyName)
     343Stringifier::StringifyResult Stringifier::appendStringifiedValue(StringBuilder& builder, JSValue value, JSObject* holder, const PropertyNameForFunctionCall& propertyName)
    345344{
    346345    // Call the toJSON function.
     
    377376    }
    378377
    379     UString stringValue;
     378    String stringValue;
    380379    if (value.getString(m_exec, stringValue)) {
    381380        appendQuotedString(builder, stringValue);
     
    388387            builder.append("null");
    389388        else
    390             builder.append(UString::numberToStringECMAScript(number));
     389            builder.append(String::numberToStringECMAScript(number));
    391390        return StringifySucceeded;
    392391    }
     
    449448    unsigned newSize = m_indent.length() + m_gap.length();
    450449    if (newSize > m_repeatedGap.length())
    451         m_repeatedGap = makeUString(m_repeatedGap, m_gap);
     450        m_repeatedGap = makeString(m_repeatedGap, m_gap);
    452451    ASSERT(newSize <= m_repeatedGap.length());
    453452    m_indent = m_repeatedGap.substringSharingImpl(0, newSize);
     
    460459}
    461460
    462 inline void Stringifier::startNewLine(UStringBuilder& builder) const
     461inline void Stringifier::startNewLine(StringBuilder& builder) const
    463462{
    464463    if (m_gap.isEmpty())
     
    478477}
    479478
    480 bool Stringifier::Holder::appendNextProperty(Stringifier& stringifier, UStringBuilder& builder)
     479bool Stringifier::Holder::appendNextProperty(Stringifier& stringifier, StringBuilder& builder)
    481480{
    482481    ASSERT(m_index <= m_size);
     
    705704            case ArrayEndVisitMember: {
    706705                JSArray* array = arrayStack.peek();
    707                 JSValue filteredValue = callReviver(array, jsString(m_exec, UString::number(indexStack.last())), outValue);
     706                JSValue filteredValue = callReviver(array, jsString(m_exec, String::number(indexStack.last())), outValue);
    708707                if (filteredValue.isUndefined())
    709708                    array->methodTable()->deletePropertyByIndex(array, m_exec, indexStack.last());
     
    812811    if (!exec->argumentCount())
    813812        return throwVMError(exec, createError(exec, "JSON.parse requires at least one parameter"));
    814     UString source = exec->argument(0).toString(exec)->value(exec);
     813    String source = exec->argument(0).toString(exec)->value(exec);
    815814    if (exec->hadException())
    816815        return JSValue::encode(jsNull());
     
    853852}
    854853
    855 UString JSONStringify(ExecState* exec, JSValue value, unsigned indent)
     854String JSONStringify(ExecState* exec, JSValue value, unsigned indent)
    856855{
    857856    LocalScope scope(exec->globalData());
    858857    Local<Unknown> result = Stringifier(exec, Local<Unknown>(exec->globalData(), jsNull()), Local<Unknown>(exec->globalData(), jsNumber(indent))).stringify(Local<Unknown>(exec->globalData(), value));
    859858    if (result.isUndefinedOrNull())
    860         return UString();
     859        return String();
    861860    return result.getString(exec);
    862861}
Note: See TracChangeset for help on using the changeset viewer.