X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/f9bf01c6616d5ddcf65b13b33cedf9e387ff7a63..4e4e5a6f2694187498445a6ac6f1634ce8141119:/API/JSClassRef.cpp?ds=sidebyside diff --git a/API/JSClassRef.cpp b/API/JSClassRef.cpp index d75d5cd..3e65b75 100644 --- a/API/JSClassRef.cpp +++ b/API/JSClassRef.cpp @@ -33,12 +33,29 @@ #include #include #include +#include +#include using namespace std; using namespace JSC; +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::null(); + + size_t length = strlen(string); + Vector buffer(length); + UChar* p = buffer.data(); + if (conversionOK != convertUTF8ToUTF16(&string, string + length, &p, p + length)) + return UString::null(); + + return UString(buffer.data(), p - buffer.data()); +} + OpaqueJSClass::OpaqueJSClass(const JSClassDefinition* definition, OpaqueJSClass* protoClass) : parentClass(definition->parentClass) , prototypeClass(0) @@ -53,7 +70,7 @@ OpaqueJSClass::OpaqueJSClass(const JSClassDefinition* definition, OpaqueJSClass* , callAsConstructor(definition->callAsConstructor) , hasInstance(definition->hasInstance) , convertToType(definition->convertToType) - , m_className(UString::createFromUTF8(definition->className).rep()->ref()) + , m_className(tryCreateStringFromUTF8(definition->className)) , m_staticValues(0) , m_staticFunctions(0) { @@ -62,9 +79,14 @@ OpaqueJSClass::OpaqueJSClass(const JSClassDefinition* definition, OpaqueJSClass* if (const JSStaticValue* staticValue = definition->staticValues) { m_staticValues = new OpaqueJSClassStaticValuesTable(); while (staticValue->name) { - // Use a local variable here to sidestep an RVCT compiler bug. - StaticValueEntry* entry = new StaticValueEntry(staticValue->getProperty, staticValue->setProperty, staticValue->attributes); - m_staticValues->add(UString::createFromUTF8(staticValue->name).rep()->ref(), entry); + UString valueName = tryCreateStringFromUTF8(staticValue->name); + if (!valueName.isNull()) { + // Use a local variable here to sidestep an RVCT compiler bug. + StaticValueEntry* entry = new StaticValueEntry(staticValue->getProperty, staticValue->setProperty, staticValue->attributes); + UStringImpl* impl = valueName.rep(); + impl->ref(); + m_staticValues->add(impl, entry); + } ++staticValue; } } @@ -72,9 +94,14 @@ OpaqueJSClass::OpaqueJSClass(const JSClassDefinition* definition, OpaqueJSClass* if (const JSStaticFunction* staticFunction = definition->staticFunctions) { m_staticFunctions = new OpaqueJSClassStaticFunctionsTable(); while (staticFunction->name) { - // Use a local variable here to sidestep an RVCT compiler bug. - StaticFunctionEntry* entry = new StaticFunctionEntry(staticFunction->callAsFunction, staticFunction->attributes); - m_staticFunctions->add(UString::createFromUTF8(staticFunction->name).rep()->ref(), entry); + UString functionName = tryCreateStringFromUTF8(staticFunction->name); + if (!functionName.isNull()) { + // Use a local variable here to sidestep an RVCT compiler bug. + StaticFunctionEntry* entry = new StaticFunctionEntry(staticFunction->callAsFunction, staticFunction->attributes); + UStringImpl* impl = functionName.rep(); + impl->ref(); + m_staticFunctions->add(impl, entry); + } ++staticFunction; } } @@ -85,7 +112,8 @@ OpaqueJSClass::OpaqueJSClass(const JSClassDefinition* definition, OpaqueJSClass* OpaqueJSClass::~OpaqueJSClass() { - ASSERT(!m_className.rep()->isIdentifier()); + // The empty string is shared across threads & is an identifier, in all other cases we should have done a deep copy in className(), below. + ASSERT(!m_className.size() || !m_className.rep()->isIdentifier()); if (m_staticValues) { OpaqueJSClassStaticValuesTable::const_iterator end = m_staticValues->end(); @@ -145,13 +173,10 @@ OpaqueJSClassContextData::OpaqueJSClassContextData(OpaqueJSClass* jsClass) ASSERT(!it->first->isIdentifier()); // Use a local variable here to sidestep an RVCT compiler bug. StaticValueEntry* entry = new StaticValueEntry(it->second->getProperty, it->second->setProperty, it->second->attributes); - staticValues->add(UString::Rep::create(it->first->data(), it->first->size()), entry); - + staticValues->add(UString::Rep::create(it->first->characters(), it->first->length()), entry); } - } else staticValues = 0; - if (jsClass->m_staticFunctions) { staticFunctions = new OpaqueJSClassStaticFunctionsTable; @@ -160,7 +185,7 @@ OpaqueJSClassContextData::OpaqueJSClassContextData(OpaqueJSClass* jsClass) ASSERT(!it->first->isIdentifier()); // Use a local variable here to sidestep an RVCT compiler bug. StaticFunctionEntry* entry = new StaticFunctionEntry(it->second->callAsFunction, it->second->attributes); - staticFunctions->add(UString::Rep::create(it->first->data(), it->first->size()), entry); + staticFunctions->add(UString::Rep::create(it->first->characters(), it->first->length()), entry); } } else