Commit a1251b33 authored by ap@webkit.org's avatar ap@webkit.org

Reviewed by Geoffrey Garen.

        <rdar://problem/4949018> JavaScriptCore API claims to work with UTF8 strings, but only works
        with ASCII strings
        
        * kjs/ustring.h:
        * kjs/ustring.cpp:
        (KJS::UString::Rep::createFromUTF8):
        Added. Implementation adapted from JSStringCreateWithUTF8CString().

        * API/JSStringRef.cpp:
        (JSStringCreateWithUTF8CString):
        * API/JSClassRef.cpp:
        (OpaqueJSClass::OpaqueJSClass):
        Use UString::Rep::createFromUTF8().



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@33374 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 9b892647
......@@ -39,8 +39,7 @@ using namespace KJS;
const JSClassDefinition kJSClassDefinitionEmpty = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
OpaqueJSClass::OpaqueJSClass(const JSClassDefinition* definition, OpaqueJSClass* protoClass)
// FIXME: <rdar://problem/4949018>
: className(definition->className)
: className(UString::Rep::createFromUTF8(definition->className))
, parentClass(definition->parentClass)
, prototypeClass(0)
, staticValues(0)
......@@ -61,8 +60,7 @@ OpaqueJSClass::OpaqueJSClass(const JSClassDefinition* definition, OpaqueJSClass*
if (const JSStaticValue* staticValue = definition->staticValues) {
staticValues = new StaticValuesTable();
while (staticValue->name) {
// FIXME: <rdar://problem/4949018>
staticValues->add(Identifier(staticValue->name).ustring().rep(),
staticValues->add(Identifier(UString::Rep::createFromUTF8(staticValue->name).get()).ustring().rep(),
new StaticValueEntry(staticValue->getProperty, staticValue->setProperty, staticValue->attributes));
++staticValue;
}
......@@ -71,8 +69,7 @@ OpaqueJSClass::OpaqueJSClass(const JSClassDefinition* definition, OpaqueJSClass*
if (const JSStaticFunction* staticFunction = definition->staticFunctions) {
staticFunctions = new StaticFunctionsTable();
while (staticFunction->name) {
// FIXME: <rdar://problem/4949018>
staticFunctions->add(Identifier(staticFunction->name).ustring().rep(),
staticFunctions->add(Identifier(UString::Rep::createFromUTF8(staticFunction->name).get()).ustring().rep(),
new StaticFunctionEntry(staticFunction->callAsFunction, staticFunction->attributes));
++staticFunction;
}
......
......@@ -51,13 +51,11 @@ JSStringRef JSStringCreateWithUTF8CString(const char* string)
{
JSLock lock;
size_t length = strlen(string);
Vector<UChar, 1024> buffer(length);
UChar* p = buffer.data();
if (conversionOK != convertUTF8ToUTF16(&string, string + length, &p, p + length))
RefPtr<UString::Rep> result = UString::Rep::createFromUTF8(string);
if (result.get() == &UString::Rep::null)
return 0;
return toRef(UString(buffer.data(), p - buffer.data()).rep()->ref());
return toRef(result.release().releaseRef());
}
JSStringRef JSStringRetain(JSStringRef string)
......
2008-05-13 Alexey Proskuryakov <ap@webkit.org>
Reviewed by Geoffrey Garen.
<rdar://problem/4949018> JavaScriptCore API claims to work with UTF8 strings, but only works
with ASCII strings
* kjs/ustring.h:
* kjs/ustring.cpp:
(KJS::UString::Rep::createFromUTF8):
Added. Implementation adapted from JSStringCreateWithUTF8CString().
* API/JSStringRef.cpp:
(JSStringCreateWithUTF8CString):
* API/JSClassRef.cpp:
(OpaqueJSClass::OpaqueJSClass):
Use UString::Rep::createFromUTF8().
2008-05-12 Mark Rowe <mrowe@apple.com>
Reviewed by Tim Hatcher.
......
......@@ -238,6 +238,20 @@ PassRefPtr<UString::Rep> UString::Rep::create(PassRefPtr<Rep> base, int offset,
return adoptRef(r);
}
PassRefPtr<UString::Rep> UString::Rep::createFromUTF8(const char* string)
{
if (!string)
return &UString::Rep::null;
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::Rep::null;
return UString::Rep::createCopying(buffer.data(), p - buffer.data());
}
void UString::Rep::destroy()
{
// Static null and empty strings can never be destroyed, but we cannot rely on reference counting, because ref/deref are not thread-safe.
......
......@@ -94,6 +94,10 @@ namespace KJS {
static PassRefPtr<Rep> createCopying(const UChar *d, int l);
static PassRefPtr<Rep> create(PassRefPtr<Rep> base, int offset, int length);
// Constructs a string from a UTF-8 string, using strict conversion (see comments in UTF8.h).
// Returns UString::Rep::null for null input or conversion failure.
static PassRefPtr<Rep> createFromUTF8(const char*);
void destroy();
bool baseIsSelf() const { return baseString == this; }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment