<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: https://svn.webkit.org/repository/webkit/trunk@33374
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
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)
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;
}
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;
}
{
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.
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.
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; }