Permalink
Browse files

Replace JSC::UString by WTF::String

https://bugs.webkit.org/show_bug.cgi?id=95271

Patch by Benjamin Poulain <bpoulain@apple.com> 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:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@127191 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information...
1 parent 5238041 commit 13a0f920575e0337c89012738444f1372f6eae52 @BenjaminPoulain BenjaminPoulain committed Aug 30, 2012
Showing 303 changed files with 1,348 additions and 2,132 deletions.
@@ -49,7 +49,7 @@ JSCallbackFunction::JSCallbackFunction(JSGlobalObject* globalObject, JSObjectCal
{
}
-void JSCallbackFunction::finishCreation(JSGlobalData& globalData, const UString& name)
+void JSCallbackFunction::finishCreation(JSGlobalData& globalData, const String& name)
{
Base::finishCreation(globalData, name);
ASSERT(inherits(&s_info));
@@ -34,12 +34,12 @@ namespace JSC {
class JSCallbackFunction : public InternalFunction {
protected:
JSCallbackFunction(JSGlobalObject*, JSObjectCallAsFunctionCallback);
- void finishCreation(JSGlobalData&, const UString& name);
+ void finishCreation(JSGlobalData&, const String& name);
public:
typedef InternalFunction Base;
- static JSCallbackFunction* create(ExecState* exec, JSGlobalObject* globalObject, JSObjectCallAsFunctionCallback callback, const UString& name)
+ static JSCallbackFunction* create(ExecState* exec, JSGlobalObject* globalObject, JSObjectCallAsFunctionCallback callback, const String& name)
{
JSCallbackFunction* function = new (NotNull, allocateCell<JSCallbackFunction>(*exec->heap())) JSCallbackFunction(globalObject, callback);
function->finishCreation(exec->globalData(), name);
@@ -171,7 +171,7 @@ class JSCallbackObject : public Parent {
static const unsigned StructureFlags = ProhibitsPropertyCaching | OverridesGetOwnPropertySlot | ImplementsHasInstance | OverridesHasInstance | OverridesVisitChildren | OverridesGetPropertyNames | Parent::StructureFlags;
private:
- static UString className(const JSObject*);
+ static String className(const JSObject*);
static void destroy(JSCell*);
@@ -111,10 +111,10 @@ void JSCallbackObject<Parent>::init(ExecState* exec)
}
template <class Parent>
-UString JSCallbackObject<Parent>::className(const JSObject* object)
+String JSCallbackObject<Parent>::className(const JSObject* object)
{
const JSCallbackObject* thisObject = jsCast<const JSCallbackObject*>(object);
- UString thisClassName = thisObject->classRef()->className();
+ String thisClassName = thisObject->classRef()->className();
if (!thisClassName.isEmpty())
return thisClassName;
@@ -42,20 +42,6 @@ using namespace WTF::Unicode;
const JSClassDefinition kJSClassDefinitionEmpty = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
-static inline UString tryCreateStringFromUTF8(const char* string)
-{
- if (!string)
- return UString();
-
- size_t length = strlen(string);
- Vector<UChar, 1024> buffer(length);
- UChar* p = buffer.data();
- if (conversionOK != convertUTF8ToUTF16(&string, string + length, &p, p + length))
- return UString();
-
- return UString(buffer.data(), p - buffer.data());
-}
-
OpaqueJSClass::OpaqueJSClass(const JSClassDefinition* definition, OpaqueJSClass* protoClass)
: parentClass(definition->parentClass)
, prototypeClass(0)
@@ -70,14 +56,14 @@ OpaqueJSClass::OpaqueJSClass(const JSClassDefinition* definition, OpaqueJSClass*
, callAsConstructor(definition->callAsConstructor)
, hasInstance(definition->hasInstance)
, convertToType(definition->convertToType)
- , m_className(tryCreateStringFromUTF8(definition->className))
+ , m_className(String::fromUTF8(definition->className))
{
initializeThreading();
if (const JSStaticValue* staticValue = definition->staticValues) {
m_staticValues = adoptPtr(new OpaqueJSClassStaticValuesTable);
while (staticValue->name) {
- UString valueName = tryCreateStringFromUTF8(staticValue->name);
+ String valueName = String::fromUTF8(staticValue->name);
if (!valueName.isNull())
m_staticValues->set(valueName.impl(), adoptPtr(new StaticValueEntry(staticValue->getProperty, staticValue->setProperty, staticValue->attributes)));
++staticValue;
@@ -87,7 +73,7 @@ OpaqueJSClass::OpaqueJSClass(const JSClassDefinition* definition, OpaqueJSClass*
if (const JSStaticFunction* staticFunction = definition->staticFunctions) {
m_staticFunctions = adoptPtr(new OpaqueJSClassStaticFunctionsTable);
while (staticFunction->name) {
- UString functionName = tryCreateStringFromUTF8(staticFunction->name);
+ String functionName = String::fromUTF8(staticFunction->name);
if (!functionName.isNull())
m_staticFunctions->set(functionName.impl(), adoptPtr(new StaticFunctionEntry(staticFunction->callAsFunction, staticFunction->attributes)));
++staticFunction;
@@ -170,10 +156,10 @@ OpaqueJSClassContextData& OpaqueJSClass::contextData(ExecState* exec)
return *contextData;
}
-UString OpaqueJSClass::className()
+String OpaqueJSClass::className()
{
// Make a deep copy, so that the caller has no chance to put the original into IdentifierTable.
- return UString(m_className.characters(), m_className.length());
+ return m_className.isolatedCopy();
}
OpaqueJSClassStaticValuesTable* OpaqueJSClass::staticValues(JSC::ExecState* exec)
@@ -31,8 +31,8 @@
#include "Weak.h"
#include "JSObject.h"
#include "Protect.h"
-#include "UString.h"
#include <wtf/HashMap.h>
+#include <wtf/text/WTFString.h>
struct StaticValueEntry {
WTF_MAKE_FAST_ALLOCATED;
@@ -89,7 +89,7 @@ struct OpaqueJSClass : public ThreadSafeRefCounted<OpaqueJSClass> {
static PassRefPtr<OpaqueJSClass> createNoAutomaticPrototype(const JSClassDefinition*);
~OpaqueJSClass();
- JSC::UString className();
+ String className();
OpaqueJSClassStaticValuesTable* staticValues(JSC::ExecState*);
OpaqueJSClassStaticFunctionsTable* staticFunctions(JSC::ExecState*);
JSC::JSObject* prototype(JSC::ExecState*);
@@ -118,8 +118,8 @@ struct OpaqueJSClass : public ThreadSafeRefCounted<OpaqueJSClass> {
OpaqueJSClassContextData& contextData(JSC::ExecState*);
- // UStrings in these data members should not be put into any IdentifierTable.
- JSC::UString m_className;
+ // Strings in these data members should not be put into any IdentifierTable.
+ String m_className;
OwnPtr<OpaqueJSClassStaticValuesTable> m_staticValues;
OwnPtr<OpaqueJSClassStaticFunctionsTable> m_staticFunctions;
};
@@ -35,7 +35,7 @@
#include "JSClassRef.h"
#include "JSGlobalObject.h"
#include "JSObject.h"
-#include "UStringBuilder.h"
+#include <wtf/text/StringBuilder.h>
#include <wtf/text/StringHash.h>
#if OS(DARWIN)
@@ -167,9 +167,9 @@ JSStringRef JSContextCreateBacktrace(JSContextRef ctx, unsigned maxStackSize)
JSLockHolder lock(exec);
unsigned count = 0;
- UStringBuilder builder;
+ StringBuilder builder;
CallFrame* callFrame = exec;
- UString functionName;
+ String functionName;
if (exec->callee()) {
if (asObject(exec->callee())->inherits(&InternalFunction::s_info)) {
functionName = asInternalFunction(exec->callee())->name(exec);
@@ -183,10 +183,10 @@ JSStringRef JSContextCreateBacktrace(JSContextRef ctx, unsigned maxStackSize)
ASSERT(callFrame);
int signedLineNumber;
intptr_t sourceID;
- UString urlString;
+ String urlString;
JSValue function;
- UString levelStr = UString::number(count);
+ String levelStr = String::number(count);
exec->interpreter()->retrieveLastCaller(callFrame, signedLineNumber, sourceID, urlString, function);
@@ -208,12 +208,12 @@ JSStringRef JSContextCreateBacktrace(JSContextRef ctx, unsigned maxStackSize)
builder.append("() at ");
builder.append(urlString);
builder.append(":");
- builder.append(UString::number(lineNumber));
+ builder.append(String::number(lineNumber));
if (!function || ++count == maxStackSize)
break;
callFrame = callFrame->callerFrame();
}
- return OpaqueJSString::create(builder.toUString()).leakRef();
+ return OpaqueJSString::create(builder.toString()).leakRef();
}
@@ -30,7 +30,6 @@
#include "InitializeThreading.h"
#include "JSStringRef.h"
#include "OpaqueJSString.h"
-#include <runtime/UString.h>
#include <runtime/JSValue.h>
#include <wtf/OwnArrayPtr.h>
@@ -36,11 +36,11 @@
#include <runtime/LiteralParser.h>
#include <runtime/Operations.h>
#include <runtime/Protect.h>
-#include <runtime/UString.h>
#include <runtime/JSValue.h>
#include <wtf/Assertions.h>
#include <wtf/text/StringHash.h>
+#include <wtf/text/WTFString.h>
#include <algorithm> // for std::min
@@ -234,7 +234,7 @@ JSValueRef JSValueMakeFromJSONString(JSContextRef ctx, JSStringRef string)
{
ExecState* exec = toJS(ctx);
APIEntryShim entryShim(exec);
- UString str = string->ustring();
+ String str = string->ustring();
if (str.is8Bit()) {
LiteralParser<LChar> parser(exec, str.characters8(), str.length(), StrictJSON);
return toRef(exec, parser.tryLiteralParse());
@@ -248,7 +248,7 @@ JSStringRef JSValueCreateJSONString(JSContextRef ctx, JSValueRef apiValue, unsig
ExecState* exec = toJS(ctx);
APIEntryShim entryShim(exec);
JSValue value = toJS(exec, apiValue);
- UString result = JSONStringify(exec, value, indent);
+ String result = JSONStringify(exec, value, indent);
if (exception)
*exception = 0;
if (exec->hadException()) {
@@ -32,18 +32,18 @@
using namespace JSC;
-PassRefPtr<OpaqueJSString> OpaqueJSString::create(const UString& ustring)
+PassRefPtr<OpaqueJSString> OpaqueJSString::create(const String& string)
{
- if (!ustring.isNull())
- return adoptRef(new OpaqueJSString(ustring.characters(), ustring.length()));
+ if (!string.isNull())
+ return adoptRef(new OpaqueJSString(string.characters(), string.length()));
return 0;
}
-UString OpaqueJSString::ustring() const
+String OpaqueJSString::ustring() const
{
if (this && m_characters)
- return UString(m_characters, m_length);
- return UString();
+ return String(m_characters, m_length);
+ return String();
}
Identifier OpaqueJSString::identifier(JSGlobalData* globalData) const
@@ -27,7 +27,7 @@
#define OpaqueJSString_h
#include <wtf/ThreadSafeRefCounted.h>
-#include <runtime/UString.h>
+#include <wtf/text/WTFString.h>
namespace JSC {
class Identifier;
@@ -46,12 +46,13 @@ struct OpaqueJSString : public ThreadSafeRefCounted<OpaqueJSString> {
return adoptRef(new OpaqueJSString(characters, length));
}
- JS_EXPORT_PRIVATE static PassRefPtr<OpaqueJSString> create(const JSC::UString&);
+ JS_EXPORT_PRIVATE static PassRefPtr<OpaqueJSString> create(const String&);
UChar* characters() { return this ? m_characters : 0; }
unsigned length() { return this ? m_length : 0; }
- JSC::UString ustring() const;
+ // FIXME: rename to string().
+ String ustring() const;
JSC::Identifier identifier(JSC::JSGlobalData*) const;
private:
@@ -255,7 +255,6 @@ SET(JavaScriptCore_SOURCES
runtime/StructureChain.cpp
runtime/SymbolTable.cpp
runtime/TimeoutChecker.cpp
- runtime/UString.cpp
tools/CodeProfile.cpp
tools/CodeProfiling.cpp
@@ -1,3 +1,37 @@
+2012-08-30 Benjamin Poulain <bpoulain@apple.com>
+
+ Replace JSC::UString by WTF::String
+ https://bugs.webkit.org/show_bug.cgi?id=95271
+
+ Reviewed by Geoffrey Garen.
+
+ 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<>().
+
2012-08-24 Mark Hahnenberg <mhahnenberg@apple.com>
Remove uses of ClassInfo in StrictEq and CompareEq in the DFG
@@ -658,10 +658,6 @@ javascriptcore_sources += \
Source/JavaScriptCore/runtime/TimeoutChecker.h \
Source/JavaScriptCore/runtime/Tracing.h \
Source/JavaScriptCore/runtime/Uint16WithFraction.h \
- Source/JavaScriptCore/runtime/UString.cpp \
- Source/JavaScriptCore/runtime/UString.h \
- Source/JavaScriptCore/runtime/UStringBuilder.h \
- Source/JavaScriptCore/runtime/UStringConcatenate.h \
Source/JavaScriptCore/runtime/WeakGCMap.h \
Source/JavaScriptCore/runtime/WeakRandom.h \
Source/JavaScriptCore/runtime/WriteBarrier.h \
Oops, something went wrong.

0 comments on commit 13a0f92

Please sign in to comment.