Skip to content

Commit 4965391

Browse files
Benjamin PoulainBenjaminPoulain
authored andcommitted
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: Canonical link: https://commits.webkit.org/113362@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@127191 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 1f61b7d commit 4965391

303 files changed

Lines changed: 1348 additions & 2132 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Source/JavaScriptCore/API/JSCallbackFunction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ JSCallbackFunction::JSCallbackFunction(JSGlobalObject* globalObject, JSObjectCal
4949
{
5050
}
5151

52-
void JSCallbackFunction::finishCreation(JSGlobalData& globalData, const UString& name)
52+
void JSCallbackFunction::finishCreation(JSGlobalData& globalData, const String& name)
5353
{
5454
Base::finishCreation(globalData, name);
5555
ASSERT(inherits(&s_info));

Source/JavaScriptCore/API/JSCallbackFunction.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ namespace JSC {
3434
class JSCallbackFunction : public InternalFunction {
3535
protected:
3636
JSCallbackFunction(JSGlobalObject*, JSObjectCallAsFunctionCallback);
37-
void finishCreation(JSGlobalData&, const UString& name);
37+
void finishCreation(JSGlobalData&, const String& name);
3838

3939
public:
4040
typedef InternalFunction Base;
4141

42-
static JSCallbackFunction* create(ExecState* exec, JSGlobalObject* globalObject, JSObjectCallAsFunctionCallback callback, const UString& name)
42+
static JSCallbackFunction* create(ExecState* exec, JSGlobalObject* globalObject, JSObjectCallAsFunctionCallback callback, const String& name)
4343
{
4444
JSCallbackFunction* function = new (NotNull, allocateCell<JSCallbackFunction>(*exec->heap())) JSCallbackFunction(globalObject, callback);
4545
function->finishCreation(exec->globalData(), name);

Source/JavaScriptCore/API/JSCallbackObject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ class JSCallbackObject : public Parent {
171171
static const unsigned StructureFlags = ProhibitsPropertyCaching | OverridesGetOwnPropertySlot | ImplementsHasInstance | OverridesHasInstance | OverridesVisitChildren | OverridesGetPropertyNames | Parent::StructureFlags;
172172

173173
private:
174-
static UString className(const JSObject*);
174+
static String className(const JSObject*);
175175

176176
static void destroy(JSCell*);
177177

Source/JavaScriptCore/API/JSCallbackObjectFunctions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,10 @@ void JSCallbackObject<Parent>::init(ExecState* exec)
111111
}
112112

113113
template <class Parent>
114-
UString JSCallbackObject<Parent>::className(const JSObject* object)
114+
String JSCallbackObject<Parent>::className(const JSObject* object)
115115
{
116116
const JSCallbackObject* thisObject = jsCast<const JSCallbackObject*>(object);
117-
UString thisClassName = thisObject->classRef()->className();
117+
String thisClassName = thisObject->classRef()->className();
118118
if (!thisClassName.isEmpty())
119119
return thisClassName;
120120

Source/JavaScriptCore/API/JSClassRef.cpp

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,6 @@ using namespace WTF::Unicode;
4242

4343
const JSClassDefinition kJSClassDefinitionEmpty = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
4444

45-
static inline UString tryCreateStringFromUTF8(const char* string)
46-
{
47-
if (!string)
48-
return UString();
49-
50-
size_t length = strlen(string);
51-
Vector<UChar, 1024> buffer(length);
52-
UChar* p = buffer.data();
53-
if (conversionOK != convertUTF8ToUTF16(&string, string + length, &p, p + length))
54-
return UString();
55-
56-
return UString(buffer.data(), p - buffer.data());
57-
}
58-
5945
OpaqueJSClass::OpaqueJSClass(const JSClassDefinition* definition, OpaqueJSClass* protoClass)
6046
: parentClass(definition->parentClass)
6147
, prototypeClass(0)
@@ -70,14 +56,14 @@ OpaqueJSClass::OpaqueJSClass(const JSClassDefinition* definition, OpaqueJSClass*
7056
, callAsConstructor(definition->callAsConstructor)
7157
, hasInstance(definition->hasInstance)
7258
, convertToType(definition->convertToType)
73-
, m_className(tryCreateStringFromUTF8(definition->className))
59+
, m_className(String::fromUTF8(definition->className))
7460
{
7561
initializeThreading();
7662

7763
if (const JSStaticValue* staticValue = definition->staticValues) {
7864
m_staticValues = adoptPtr(new OpaqueJSClassStaticValuesTable);
7965
while (staticValue->name) {
80-
UString valueName = tryCreateStringFromUTF8(staticValue->name);
66+
String valueName = String::fromUTF8(staticValue->name);
8167
if (!valueName.isNull())
8268
m_staticValues->set(valueName.impl(), adoptPtr(new StaticValueEntry(staticValue->getProperty, staticValue->setProperty, staticValue->attributes)));
8369
++staticValue;
@@ -87,7 +73,7 @@ OpaqueJSClass::OpaqueJSClass(const JSClassDefinition* definition, OpaqueJSClass*
8773
if (const JSStaticFunction* staticFunction = definition->staticFunctions) {
8874
m_staticFunctions = adoptPtr(new OpaqueJSClassStaticFunctionsTable);
8975
while (staticFunction->name) {
90-
UString functionName = tryCreateStringFromUTF8(staticFunction->name);
76+
String functionName = String::fromUTF8(staticFunction->name);
9177
if (!functionName.isNull())
9278
m_staticFunctions->set(functionName.impl(), adoptPtr(new StaticFunctionEntry(staticFunction->callAsFunction, staticFunction->attributes)));
9379
++staticFunction;
@@ -170,10 +156,10 @@ OpaqueJSClassContextData& OpaqueJSClass::contextData(ExecState* exec)
170156
return *contextData;
171157
}
172158

173-
UString OpaqueJSClass::className()
159+
String OpaqueJSClass::className()
174160
{
175161
// Make a deep copy, so that the caller has no chance to put the original into IdentifierTable.
176-
return UString(m_className.characters(), m_className.length());
162+
return m_className.isolatedCopy();
177163
}
178164

179165
OpaqueJSClassStaticValuesTable* OpaqueJSClass::staticValues(JSC::ExecState* exec)

Source/JavaScriptCore/API/JSClassRef.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
#include "Weak.h"
3232
#include "JSObject.h"
3333
#include "Protect.h"
34-
#include "UString.h"
3534
#include <wtf/HashMap.h>
35+
#include <wtf/text/WTFString.h>
3636

3737
struct StaticValueEntry {
3838
WTF_MAKE_FAST_ALLOCATED;
@@ -89,7 +89,7 @@ struct OpaqueJSClass : public ThreadSafeRefCounted<OpaqueJSClass> {
8989
static PassRefPtr<OpaqueJSClass> createNoAutomaticPrototype(const JSClassDefinition*);
9090
~OpaqueJSClass();
9191

92-
JSC::UString className();
92+
String className();
9393
OpaqueJSClassStaticValuesTable* staticValues(JSC::ExecState*);
9494
OpaqueJSClassStaticFunctionsTable* staticFunctions(JSC::ExecState*);
9595
JSC::JSObject* prototype(JSC::ExecState*);
@@ -118,8 +118,8 @@ struct OpaqueJSClass : public ThreadSafeRefCounted<OpaqueJSClass> {
118118

119119
OpaqueJSClassContextData& contextData(JSC::ExecState*);
120120

121-
// UStrings in these data members should not be put into any IdentifierTable.
122-
JSC::UString m_className;
121+
// Strings in these data members should not be put into any IdentifierTable.
122+
String m_className;
123123
OwnPtr<OpaqueJSClassStaticValuesTable> m_staticValues;
124124
OwnPtr<OpaqueJSClassStaticFunctionsTable> m_staticFunctions;
125125
};

Source/JavaScriptCore/API/JSContextRef.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#include "JSClassRef.h"
3636
#include "JSGlobalObject.h"
3737
#include "JSObject.h"
38-
#include "UStringBuilder.h"
38+
#include <wtf/text/StringBuilder.h>
3939
#include <wtf/text/StringHash.h>
4040

4141
#if OS(DARWIN)
@@ -167,9 +167,9 @@ JSStringRef JSContextCreateBacktrace(JSContextRef ctx, unsigned maxStackSize)
167167
JSLockHolder lock(exec);
168168

169169
unsigned count = 0;
170-
UStringBuilder builder;
170+
StringBuilder builder;
171171
CallFrame* callFrame = exec;
172-
UString functionName;
172+
String functionName;
173173
if (exec->callee()) {
174174
if (asObject(exec->callee())->inherits(&InternalFunction::s_info)) {
175175
functionName = asInternalFunction(exec->callee())->name(exec);
@@ -183,10 +183,10 @@ JSStringRef JSContextCreateBacktrace(JSContextRef ctx, unsigned maxStackSize)
183183
ASSERT(callFrame);
184184
int signedLineNumber;
185185
intptr_t sourceID;
186-
UString urlString;
186+
String urlString;
187187
JSValue function;
188188

189-
UString levelStr = UString::number(count);
189+
String levelStr = String::number(count);
190190

191191
exec->interpreter()->retrieveLastCaller(callFrame, signedLineNumber, sourceID, urlString, function);
192192

@@ -208,12 +208,12 @@ JSStringRef JSContextCreateBacktrace(JSContextRef ctx, unsigned maxStackSize)
208208
builder.append("() at ");
209209
builder.append(urlString);
210210
builder.append(":");
211-
builder.append(UString::number(lineNumber));
211+
builder.append(String::number(lineNumber));
212212
if (!function || ++count == maxStackSize)
213213
break;
214214
callFrame = callFrame->callerFrame();
215215
}
216-
return OpaqueJSString::create(builder.toUString()).leakRef();
216+
return OpaqueJSString::create(builder.toString()).leakRef();
217217
}
218218

219219

Source/JavaScriptCore/API/JSStringRefCF.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include "InitializeThreading.h"
3131
#include "JSStringRef.h"
3232
#include "OpaqueJSString.h"
33-
#include <runtime/UString.h>
3433
#include <runtime/JSValue.h>
3534
#include <wtf/OwnArrayPtr.h>
3635

Source/JavaScriptCore/API/JSValueRef.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@
3636
#include <runtime/LiteralParser.h>
3737
#include <runtime/Operations.h>
3838
#include <runtime/Protect.h>
39-
#include <runtime/UString.h>
4039
#include <runtime/JSValue.h>
4140

4241
#include <wtf/Assertions.h>
4342
#include <wtf/text/StringHash.h>
43+
#include <wtf/text/WTFString.h>
4444

4545
#include <algorithm> // for std::min
4646

@@ -234,7 +234,7 @@ JSValueRef JSValueMakeFromJSONString(JSContextRef ctx, JSStringRef string)
234234
{
235235
ExecState* exec = toJS(ctx);
236236
APIEntryShim entryShim(exec);
237-
UString str = string->ustring();
237+
String str = string->ustring();
238238
if (str.is8Bit()) {
239239
LiteralParser<LChar> parser(exec, str.characters8(), str.length(), StrictJSON);
240240
return toRef(exec, parser.tryLiteralParse());
@@ -248,7 +248,7 @@ JSStringRef JSValueCreateJSONString(JSContextRef ctx, JSValueRef apiValue, unsig
248248
ExecState* exec = toJS(ctx);
249249
APIEntryShim entryShim(exec);
250250
JSValue value = toJS(exec, apiValue);
251-
UString result = JSONStringify(exec, value, indent);
251+
String result = JSONStringify(exec, value, indent);
252252
if (exception)
253253
*exception = 0;
254254
if (exec->hadException()) {

Source/JavaScriptCore/API/OpaqueJSString.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@
3232

3333
using namespace JSC;
3434

35-
PassRefPtr<OpaqueJSString> OpaqueJSString::create(const UString& ustring)
35+
PassRefPtr<OpaqueJSString> OpaqueJSString::create(const String& string)
3636
{
37-
if (!ustring.isNull())
38-
return adoptRef(new OpaqueJSString(ustring.characters(), ustring.length()));
37+
if (!string.isNull())
38+
return adoptRef(new OpaqueJSString(string.characters(), string.length()));
3939
return 0;
4040
}
4141

42-
UString OpaqueJSString::ustring() const
42+
String OpaqueJSString::ustring() const
4343
{
4444
if (this && m_characters)
45-
return UString(m_characters, m_length);
46-
return UString();
45+
return String(m_characters, m_length);
46+
return String();
4747
}
4848

4949
Identifier OpaqueJSString::identifier(JSGlobalData* globalData) const

0 commit comments

Comments
 (0)