Changeset 54545 in webkit
- Timestamp:
- Feb 9, 2010 3:55:39 AM (14 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/API/JSClassRef.cpp
r54428 r54545 34 34 #include <runtime/ObjectPrototype.h> 35 35 #include <runtime/Identifier.h> 36 #include <wtf/unicode/UTF8.h> 36 37 37 38 using namespace std; 38 39 using namespace JSC; 40 using namespace WTF::Unicode; 39 41 40 42 const JSClassDefinition kJSClassDefinitionEmpty = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 43 44 UString tryCreateStringFromUTF8(const char* string) 45 { 46 if (!string) 47 return UString::null(); 48 49 size_t length = strlen(string); 50 Vector<UChar, 1024> buffer(length); 51 UChar* p = buffer.data(); 52 if (conversionOK != convertUTF8ToUTF16(&string, string + length, &p, p + length)) 53 return UString::null(); 54 55 return UString(buffer.data(), p - buffer.data()); 56 } 41 57 42 58 OpaqueJSClass::OpaqueJSClass(const JSClassDefinition* definition, OpaqueJSClass* protoClass) … … 54 70 , hasInstance(definition->hasInstance) 55 71 , convertToType(definition->convertToType) 56 , m_className( UString::createFromUTF8(definition->className).rep()->ref())72 , m_className(tryCreateStringFromUTF8(definition->className)) 57 73 , m_staticValues(0) 58 74 , m_staticFunctions(0) … … 63 79 m_staticValues = new OpaqueJSClassStaticValuesTable(); 64 80 while (staticValue->name) { 65 // Use a local variable here to sidestep an RVCT compiler bug. 66 StaticValueEntry* entry = new StaticValueEntry(staticValue->getProperty, staticValue->setProperty, staticValue->attributes); 67 m_staticValues->add(UString::createFromUTF8(staticValue->name).rep()->ref(), entry); 81 UString valueName = tryCreateStringFromUTF8(staticValue->name); 82 if (!valueName.isNull()) { 83 // Use a local variable here to sidestep an RVCT compiler bug. 84 StaticValueEntry* entry = new StaticValueEntry(staticValue->getProperty, staticValue->setProperty, staticValue->attributes); 85 m_staticValues->add(valueName.rep()->ref(), entry); 86 } 68 87 ++staticValue; 69 88 } … … 73 92 m_staticFunctions = new OpaqueJSClassStaticFunctionsTable(); 74 93 while (staticFunction->name) { 75 // Use a local variable here to sidestep an RVCT compiler bug. 76 StaticFunctionEntry* entry = new StaticFunctionEntry(staticFunction->callAsFunction, staticFunction->attributes); 77 m_staticFunctions->add(UString::createFromUTF8(staticFunction->name).rep()->ref(), entry); 94 UString functionName = tryCreateStringFromUTF8(staticFunction->name); 95 if (!functionName.isNull()) { 96 // Use a local variable here to sidestep an RVCT compiler bug. 97 StaticFunctionEntry* entry = new StaticFunctionEntry(staticFunction->callAsFunction, staticFunction->attributes); 98 m_staticFunctions->add(functionName.rep()->ref(), entry); 99 } 78 100 ++staticFunction; 79 101 } … … 147 169 StaticValueEntry* entry = new StaticValueEntry(it->second->getProperty, it->second->setProperty, it->second->attributes); 148 170 staticValues->add(UString::Rep::create(it->first->data(), it->first->size()), entry); 149 150 } 151 171 } 152 172 } else 153 173 staticValues = 0; 154 155 174 156 175 if (jsClass->m_staticFunctions) { -
trunk/JavaScriptCore/ChangeLog
r54539 r54545 1 2010-02-09 Gavin Barraclough <barraclough@apple.com> 2 3 Reviewed by Oliver Hunt. 4 5 Three small string fixes: 6 (1) StringBuilder::release should CRASH if the buffer allocation failed. 7 (2) Remove weird, dead code from JSString::tryGetValue, replace with an ASSERT. 8 (3) Move UString::createFromUTF8 out to the API, as tryCreateStringFromUTF8. 9 This is only used from the API, and (now) unlike other UString::create 10 methods may return UString::null() to indicate failure cases. Better 11 handle these in the API. 12 13 * API/JSClassRef.cpp: 14 (tryCreateStringFromUTF8): 15 (OpaqueJSClass::OpaqueJSClass): 16 (OpaqueJSClassContextData::OpaqueJSClassContextData): 17 * runtime/JSString.h: 18 (JSC::Fiber::tryGetValue): 19 * runtime/StringBuilder.h: 20 (JSC::StringBuilder::release): 21 * runtime/UString.cpp: 22 (JSC::UString::UString): 23 (JSC::UString::from): 24 (JSC::UString::find): 25 * runtime/UString.h: 26 1 27 2010-02-09 Janne Koskinen <janne.p.koskinen@digia.com> 2 28 -
trunk/JavaScriptCore/runtime/JSString.h
r54022 r54545 284 284 const UString tryGetValue() const 285 285 { 286 if (isRope()) 287 UString(); 286 // If this is a rope, m_value should be null - 287 // if this is not a rope, m_value should be non-null. 288 ASSERT(isRope() == m_value.isNull()); 288 289 return m_value; 289 290 } -
trunk/JavaScriptCore/runtime/StringBuilder.h
r54394 r54545 70 70 { 71 71 buffer.shrinkToFit(); 72 if (!buffer.data()) 73 CRASH(); 72 74 return UString::adopt(buffer); 73 75 } -
trunk/JavaScriptCore/runtime/UString.cpp
r54531 r54545 54 54 55 55 namespace JSC { 56 56 57 57 extern const double NaN; 58 58 extern const double Inf; … … 147 147 } 148 148 149 // These static strings are immutable, except for rc, whose initial value is chosen to 149 // These static strings are immutable, except for rc, whose initial value is chosen to 150 150 // reduce the possibility of it becoming zero due to ref/deref not being thread-safe. 151 151 static UChar sharedEmptyChar; … … 175 175 UString::UString(const UChar* c, int length) 176 176 { 177 if (length == 0) 177 if (length == 0) 178 178 m_rep = &Rep::empty(); 179 179 else … … 181 181 } 182 182 183 UString UString::createFromUTF8(const char* string)184 {185 if (!string)186 return null();187 188 size_t length = strlen(string);189 Vector<UChar, 1024> buffer(length);190 UChar* p = buffer.data();191 if (conversionOK != convertUTF8ToUTF16(&string, string + length, &p, p + length))192 return null();193 194 return UString(buffer.data(), p - buffer.data());195 }196 197 183 UString UString::from(int i) 198 184 { … … 200 186 UChar* end = buf + sizeof(buf) / sizeof(UChar); 201 187 UChar* p = end; 202 188 203 189 if (i == 0) 204 190 *--p = '0'; … … 262 248 UChar* end = buf + sizeof(buf) / sizeof(UChar); 263 249 UChar* p = end; 264 250 265 251 if (u == 0) 266 252 *--p = '0'; … … 271 257 } 272 258 } 273 259 274 260 return UString(p, static_cast<int>(end - p)); 275 261 } … … 598 584 return static_cast<int>(c - data()); 599 585 } 600 586 601 587 return -1; 602 588 } -
trunk/JavaScriptCore/runtime/UString.h
r54531 r54545 82 82 83 83 public: 84 // UString constructors passed char*s assume ISO Latin-1 encoding; for UTF8 use 'createFromUTF8', below.85 84 UString(); 86 85 UString(const char*); // Constructor for null-terminated string. … … 109 108 return Rep::adopt(vector); 110 109 } 111 112 static UString createFromUTF8(const char*);113 110 114 111 static UString from(int); -
trunk/JavaScriptCore/runtime/UStringImpl.h
r54464 r54545 88 88 static PassRefPtr<UStringImpl> adopt(Vector<UChar, inlineCapacity>& vector) 89 89 { 90 ASSERT(vector.data()); 90 91 if (unsigned length = vector.size()) 91 92 return adoptRef(new UStringImpl(vector.releaseBuffer(), length, BufferOwned));
Note: See TracChangeset
for help on using the changeset viewer.