Changeset 65302 in webkit for trunk/JavaScriptCore
- Timestamp:
- Aug 12, 2010, 11:42:16 PM (15 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r65296 r65302 1 2010-08-12 Sheriff Bot <[email protected]> 2 3 Unreviewed, rolling out r65295. 4 http://trac.webkit.org/changeset/65295 5 https://bugs.webkit.org/show_bug.cgi?id=43950 6 7 It broke 4 sputnik tests (Requested by Ossy on #webkit). 8 9 * JavaScriptCore.exp: 10 * bytecode/CodeBlock.cpp: 11 (JSC::constantName): 12 (JSC::idName): 13 (JSC::CodeBlock::registerName): 14 (JSC::regexpName): 15 (JSC::printGlobalResolveInfo): 16 (JSC::printStructureStubInfo): 17 (JSC::CodeBlock::printStructure): 18 (JSC::CodeBlock::printStructures): 19 * jsc.cpp: 20 (functionPrint): 21 (functionDebug): 22 (runInteractive): 23 (fillBufferWithContentsOfFile): 24 * pcre/pcre_exec.cpp: 25 (Histogram::~Histogram): 26 * profiler/CallIdentifier.h: 27 (JSC::CallIdentifier::c_str): 28 * profiler/Profile.cpp: 29 (JSC::Profile::debugPrintDataSampleStyle): 30 * profiler/ProfileGenerator.cpp: 31 (JSC::ProfileGenerator::willExecute): 32 (JSC::ProfileGenerator::didExecute): 33 * profiler/ProfileNode.cpp: 34 (JSC::ProfileNode::debugPrintData): 35 (JSC::ProfileNode::debugPrintDataSampleStyle): 36 * runtime/Arguments.cpp: 37 (JSC::Arguments::getOwnPropertySlot): 38 (JSC::Arguments::getOwnPropertyDescriptor): 39 (JSC::Arguments::put): 40 (JSC::Arguments::deleteProperty): 41 * runtime/DateConversion.cpp: 42 (JSC::parseDate): 43 * runtime/Identifier.h: 44 (JSC::Identifier::Identifier): 45 (JSC::Identifier::toArrayIndex): 46 * runtime/JSArray.cpp: 47 (JSC::JSArray::getOwnPropertySlot): 48 (JSC::JSArray::getOwnPropertyDescriptor): 49 (JSC::JSArray::put): 50 (JSC::JSArray::deleteProperty): 51 * runtime/JSArray.h: 52 * runtime/JSGlobalObjectFunctions.cpp: 53 (JSC::encode): 54 (JSC::parseInt): 55 (JSC::globalFuncJSCPrint): 56 * runtime/JSString.h: 57 (JSC::RopeBuilder::JSString): 58 * runtime/UString.cpp: 59 (JSC::UString::toDouble): 60 (JSC::UString::UTF8String): 61 * runtime/UString.h: 62 (JSC::UString::isNull): 63 (JSC::UString::isEmpty): 64 (JSC::UString::impl): 65 (JSC::UString::cost): 66 (JSC::UString::~UString): 67 (JSC::UString::toArrayIndex): 68 * wtf/text/WTFString.cpp: 69 (WTF::String::utf8): 70 * wtf/text/WTFString.h: 71 (WTF::String::String): 72 (WTF::String::isHashTableDeletedValue): 73 (WTF::String::length): 74 (WTF::String::operator[]): 75 (WTF::String::isNull): 76 (WTF::String::isEmpty): 77 (WTF::String::impl): 78 1 79 2010-08-12 Gavin Barraclough <[email protected]> 2 80 -
trunk/JavaScriptCore/JavaScriptCore.exp
r65295 r65302 514 514 __ZNK3JSC7JSValue20toThisObjectSlowCaseEPNS_9ExecStateE 515 515 __ZNK3JSC7JSValue9toIntegerEPNS_9ExecStateE 516 __ZNK3JSC7UString10UTF8StringEb 516 517 __ZNK3JSC7UString14toStrictUInt32EPb 517 __ZNK3JSC7UString4utf8Eb518 518 __ZNK3JSC7UString5asciiEv 519 519 __ZNK3JSC7UString6substrEjj … … 541 541 __ZNK3WTF6String18simplifyWhiteSpaceEv 542 542 __ZNK3WTF6String19characterStartingAtEj 543 __ZNK3WTF6String4utf8E b543 __ZNK3WTF6String4utf8Ev 544 544 __ZNK3WTF6String5asciiEv 545 545 __ZNK3WTF6String5lowerEv -
trunk/JavaScriptCore/bytecode/CodeBlock.cpp
r65295 r65302 72 72 static CString constantName(ExecState* exec, int k, JSValue value) 73 73 { 74 return makeString(valueToSourceString(exec, value), "(@k", UString::number(k - FirstConstantRegisterIndex), ")"). utf8();74 return makeString(valueToSourceString(exec, value), "(@k", UString::number(k - FirstConstantRegisterIndex), ")").UTF8String(); 75 75 } 76 76 77 77 static CString idName(int id0, const Identifier& ident) 78 78 { 79 return makeString(ident.ustring(), "(@id", UString::number(id0), ")"). utf8();79 return makeString(ident.ustring(), "(@id", UString::number(id0), ")").UTF8String(); 80 80 } 81 81 … … 88 88 return constantName(exec, r, getConstant(r)); 89 89 90 return makeString("r", UString::number(r)). utf8();90 return makeString("r", UString::number(r)).UTF8String(); 91 91 } 92 92 … … 107 107 static CString regexpName(int re, RegExp* regexp) 108 108 { 109 return makeString(regexpToSourceString(regexp), "(@re", UString::number(re), ")"). utf8();109 return makeString(regexpToSourceString(regexp), "(@re", UString::number(re), ")").UTF8String(); 110 110 } 111 111 … … 225 225 static void printGlobalResolveInfo(const GlobalResolveInfo& resolveInfo, unsigned instructionOffset) 226 226 { 227 printf(" [%4d] %s: %s\n", instructionOffset, "resolve_global", pointerToSourceString(resolveInfo.structure). utf8().data());227 printf(" [%4d] %s: %s\n", instructionOffset, "resolve_global", pointerToSourceString(resolveInfo.structure).UTF8String().data()); 228 228 } 229 229 … … 232 232 switch (stubInfo.accessType) { 233 233 case access_get_by_id_self: 234 printf(" [%4d] %s: %s\n", instructionOffset, "get_by_id_self", pointerToSourceString(stubInfo.u.getByIdSelf.baseObjectStructure). utf8().data());234 printf(" [%4d] %s: %s\n", instructionOffset, "get_by_id_self", pointerToSourceString(stubInfo.u.getByIdSelf.baseObjectStructure).UTF8String().data()); 235 235 return; 236 236 case access_get_by_id_proto: 237 printf(" [%4d] %s: %s, %s\n", instructionOffset, "get_by_id_proto", pointerToSourceString(stubInfo.u.getByIdProto.baseObjectStructure). utf8().data(), pointerToSourceString(stubInfo.u.getByIdProto.prototypeStructure).utf8().data());237 printf(" [%4d] %s: %s, %s\n", instructionOffset, "get_by_id_proto", pointerToSourceString(stubInfo.u.getByIdProto.baseObjectStructure).UTF8String().data(), pointerToSourceString(stubInfo.u.getByIdProto.prototypeStructure).UTF8String().data()); 238 238 return; 239 239 case access_get_by_id_chain: 240 printf(" [%4d] %s: %s, %s\n", instructionOffset, "get_by_id_chain", pointerToSourceString(stubInfo.u.getByIdChain.baseObjectStructure). utf8().data(), pointerToSourceString(stubInfo.u.getByIdChain.chain).utf8().data());240 printf(" [%4d] %s: %s, %s\n", instructionOffset, "get_by_id_chain", pointerToSourceString(stubInfo.u.getByIdChain.baseObjectStructure).UTF8String().data(), pointerToSourceString(stubInfo.u.getByIdChain.chain).UTF8String().data()); 241 241 return; 242 242 case access_get_by_id_self_list: 243 printf(" [%4d] %s: %s (%d)\n", instructionOffset, "op_get_by_id_self_list", pointerToSourceString(stubInfo.u.getByIdSelfList.structureList). utf8().data(), stubInfo.u.getByIdSelfList.listSize);243 printf(" [%4d] %s: %s (%d)\n", instructionOffset, "op_get_by_id_self_list", pointerToSourceString(stubInfo.u.getByIdSelfList.structureList).UTF8String().data(), stubInfo.u.getByIdSelfList.listSize); 244 244 return; 245 245 case access_get_by_id_proto_list: 246 printf(" [%4d] %s: %s (%d)\n", instructionOffset, "op_get_by_id_proto_list", pointerToSourceString(stubInfo.u.getByIdProtoList.structureList). utf8().data(), stubInfo.u.getByIdProtoList.listSize);246 printf(" [%4d] %s: %s (%d)\n", instructionOffset, "op_get_by_id_proto_list", pointerToSourceString(stubInfo.u.getByIdProtoList.structureList).UTF8String().data(), stubInfo.u.getByIdProtoList.listSize); 247 247 return; 248 248 case access_put_by_id_transition: 249 printf(" [%4d] %s: %s, %s, %s\n", instructionOffset, "put_by_id_transition", pointerToSourceString(stubInfo.u.putByIdTransition.previousStructure). utf8().data(), pointerToSourceString(stubInfo.u.putByIdTransition.structure).utf8().data(), pointerToSourceString(stubInfo.u.putByIdTransition.chain).utf8().data());249 printf(" [%4d] %s: %s, %s, %s\n", instructionOffset, "put_by_id_transition", pointerToSourceString(stubInfo.u.putByIdTransition.previousStructure).UTF8String().data(), pointerToSourceString(stubInfo.u.putByIdTransition.structure).UTF8String().data(), pointerToSourceString(stubInfo.u.putByIdTransition.chain).UTF8String().data()); 250 250 return; 251 251 case access_put_by_id_replace: 252 printf(" [%4d] %s: %s\n", instructionOffset, "put_by_id_replace", pointerToSourceString(stubInfo.u.putByIdReplace.baseObjectStructure). utf8().data());252 printf(" [%4d] %s: %s\n", instructionOffset, "put_by_id_replace", pointerToSourceString(stubInfo.u.putByIdReplace.baseObjectStructure).UTF8String().data()); 253 253 return; 254 254 case access_get_by_id: … … 279 279 { 280 280 unsigned instructionOffset = vPC - m_instructions.begin(); 281 printf(" [%4d] %s: %s\n", instructionOffset, name, pointerToSourceString(vPC[operand].u.structure). utf8().data());281 printf(" [%4d] %s: %s\n", instructionOffset, name, pointerToSourceString(vPC[operand].u.structure).UTF8String().data()); 282 282 } 283 283 … … 296 296 } 297 297 if (vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_proto)) { 298 printf(" [%4d] %s: %s, %s\n", instructionOffset, "get_by_id_proto", pointerToSourceString(vPC[4].u.structure). utf8().data(), pointerToSourceString(vPC[5].u.structure).utf8().data());298 printf(" [%4d] %s: %s, %s\n", instructionOffset, "get_by_id_proto", pointerToSourceString(vPC[4].u.structure).UTF8String().data(), pointerToSourceString(vPC[5].u.structure).UTF8String().data()); 299 299 return; 300 300 } 301 301 if (vPC[0].u.opcode == interpreter->getOpcode(op_put_by_id_transition)) { 302 printf(" [%4d] %s: %s, %s, %s\n", instructionOffset, "put_by_id_transition", pointerToSourceString(vPC[4].u.structure). utf8().data(), pointerToSourceString(vPC[5].u.structure).utf8().data(), pointerToSourceString(vPC[6].u.structureChain).utf8().data());302 printf(" [%4d] %s: %s, %s, %s\n", instructionOffset, "put_by_id_transition", pointerToSourceString(vPC[4].u.structure).UTF8String().data(), pointerToSourceString(vPC[5].u.structure).UTF8String().data(), pointerToSourceString(vPC[6].u.structureChain).UTF8String().data()); 303 303 return; 304 304 } 305 305 if (vPC[0].u.opcode == interpreter->getOpcode(op_get_by_id_chain)) { 306 printf(" [%4d] %s: %s, %s\n", instructionOffset, "get_by_id_chain", pointerToSourceString(vPC[4].u.structure). utf8().data(), pointerToSourceString(vPC[5].u.structureChain).utf8().data());306 printf(" [%4d] %s: %s, %s\n", instructionOffset, "get_by_id_chain", pointerToSourceString(vPC[4].u.structure).UTF8String().data(), pointerToSourceString(vPC[5].u.structureChain).UTF8String().data()); 307 307 return; 308 308 } -
trunk/JavaScriptCore/jsc.cpp
r65295 r65302 179 179 putchar(' '); 180 180 181 printf("%s", exec->argument(i).toString(exec). utf8().data());181 printf("%s", exec->argument(i).toString(exec).UTF8String().data()); 182 182 } 183 183 … … 189 189 EncodedJSValue JSC_HOST_CALL functionDebug(ExecState* exec) 190 190 { 191 fprintf(stderr, "--> %s\n", exec->argument(0).toString(exec). utf8().data());191 fprintf(stderr, "--> %s\n", exec->argument(0).toString(exec).UTF8String().data()); 192 192 return JSValue::encode(jsUndefined()); 193 193 } … … 443 443 printf("Exception: %s\n", completion.value().toString(globalObject->globalExec()).ascii()); 444 444 else 445 printf("%s\n", completion.value().toString(globalObject->globalExec()). utf8().data());445 printf("%s\n", completion.value().toString(globalObject->globalExec()).UTF8String().data()); 446 446 447 447 globalObject->globalExec()->clearException(); … … 533 533 static bool fillBufferWithContentsOfFile(const UString& fileName, Vector<char>& buffer) 534 534 { 535 FILE* f = fopen(fileName. utf8().data(), "r");535 FILE* f = fopen(fileName.UTF8String().data(), "r"); 536 536 if (!f) { 537 fprintf(stderr, "Could not open file: %s\n", fileName. utf8().data());537 fprintf(stderr, "Could not open file: %s\n", fileName.UTF8String().data()); 538 538 return false; 539 539 } -
trunk/JavaScriptCore/pcre/pcre_exec.cpp
r65295 r65302 2144 2144 printf("Regular Expressions, sorted by time spent evaluating them:\n"); 2145 2145 for (size_t i = 0; i < size; ++i) 2146 printf(" %f - %s\n", values[size - i - 1].second, values[size - i - 1].first. utf8().c_str());2146 printf(" %f - %s\n", values[size - i - 1].second, values[size - i - 1].first.UTF8String().c_str()); 2147 2147 } 2148 2148 -
trunk/JavaScriptCore/profiler/CallIdentifier.h
r65295 r65302 72 72 #ifndef NDEBUG 73 73 operator const char*() const { return c_str(); } 74 const char* c_str() const { return m_name. utf8().data(); }74 const char* c_str() const { return m_name.UTF8String().data(); } 75 75 #endif 76 76 }; -
trunk/JavaScriptCore/profiler/Profile.cpp
r65295 r65302 128 128 std::sort(sortedFunctions.begin(), sortedFunctions.end(), functionNameCountPairComparator); 129 129 for (NameCountPairVector::iterator it = sortedFunctions.begin(); it != sortedFunctions.end(); ++it) 130 printf(" %-12d%s\n", (*it).second, UString((*it).first). utf8().data());130 printf(" %-12d%s\n", (*it).second, UString((*it).first).UTF8String().data()); 131 131 132 132 printf("\nSort by top of stack, same collapsed (when >= 5):\n"); -
trunk/JavaScriptCore/profiler/ProfileGenerator.cpp
r65295 r65302 76 76 { 77 77 if (JAVASCRIPTCORE_PROFILE_WILL_EXECUTE_ENABLED()) { 78 CString name = callIdentifier.m_name. utf8();79 CString url = callIdentifier.m_url. utf8();78 CString name = callIdentifier.m_name.UTF8String(); 79 CString url = callIdentifier.m_url.UTF8String(); 80 80 JAVASCRIPTCORE_PROFILE_WILL_EXECUTE(m_profileGroup, const_cast<char*>(name.data()), const_cast<char*>(url.data()), callIdentifier.m_lineNumber); 81 81 } … … 91 91 { 92 92 if (JAVASCRIPTCORE_PROFILE_DID_EXECUTE_ENABLED()) { 93 CString name = callIdentifier.m_name. utf8();94 CString url = callIdentifier.m_url. utf8();93 CString name = callIdentifier.m_name.UTF8String(); 94 CString url = callIdentifier.m_url.UTF8String(); 95 95 JAVASCRIPTCORE_PROFILE_DID_EXECUTE(m_profileGroup, const_cast<char*>(name.data()), const_cast<char*>(url.data()), callIdentifier.m_lineNumber); 96 96 } -
trunk/JavaScriptCore/profiler/ProfileNode.cpp
r65295 r65302 295 295 296 296 printf("Function Name %s %d SelfTime %.3fms/%.3f%% TotalTime %.3fms/%.3f%% VSelf %.3fms VTotal %.3fms Visible %s Next Sibling %s\n", 297 functionName(). utf8().data(),297 functionName().UTF8String().data(), 298 298 m_numberOfCalls, m_actualSelfTime, selfPercent(), m_actualTotalTime, totalPercent(), 299 299 m_visibleSelfTime, m_visibleTotalTime, 300 300 (m_visible ? "True" : "False"), 301 m_nextSibling ? m_nextSibling->functionName(). utf8().data() : "");301 m_nextSibling ? m_nextSibling->functionName().UTF8String().data() : ""); 302 302 303 303 ++indentLevel; … … 314 314 315 315 // Print function names 316 const char* name = functionName(). utf8().data();316 const char* name = functionName().UTF8String().data(); 317 317 double sampleCount = m_actualTotalTime * 1000; 318 318 if (indentLevel) { … … 340 340 printf(" "); 341 341 342 printf("%.0f %s\n", sampleCount - sumOfChildrensCount, functionName(). utf8().data());342 printf("%.0f %s\n", sampleCount - sumOfChildrensCount, functionName().UTF8String().data()); 343 343 } 344 344 -
trunk/JavaScriptCore/runtime/Arguments.cpp
r65295 r65302 158 158 { 159 159 bool isArrayIndex; 160 unsigned i = toArrayIndex(propertyName.ustring(),&isArrayIndex);160 unsigned i = propertyName.toArrayIndex(&isArrayIndex); 161 161 if (isArrayIndex && i < d->numArguments && (!d->deletedArguments || !d->deletedArguments[i])) { 162 162 if (i < d->numParameters) { … … 183 183 { 184 184 bool isArrayIndex; 185 unsigned i = toArrayIndex(propertyName.ustring(),&isArrayIndex);185 unsigned i = propertyName.toArrayIndex(&isArrayIndex); 186 186 if (isArrayIndex && i < d->numArguments && (!d->deletedArguments || !d->deletedArguments[i])) { 187 187 if (i < d->numParameters) { … … 234 234 { 235 235 bool isArrayIndex; 236 unsigned i = toArrayIndex(propertyName.ustring(),&isArrayIndex);236 unsigned i = propertyName.toArrayIndex(&isArrayIndex); 237 237 if (isArrayIndex && i < d->numArguments && (!d->deletedArguments || !d->deletedArguments[i])) { 238 238 if (i < d->numParameters) … … 277 277 { 278 278 bool isArrayIndex; 279 unsigned i = toArrayIndex(propertyName.ustring(),&isArrayIndex);279 unsigned i = propertyName.toArrayIndex(&isArrayIndex); 280 280 if (isArrayIndex && i < d->numArguments) { 281 281 if (!d->deletedArguments) { -
trunk/JavaScriptCore/runtime/DateConversion.cpp
r65295 r65302 57 57 if (date == exec->globalData().cachedDateString) 58 58 return exec->globalData().cachedDateStringValue; 59 double value = parseDateFromNullTerminatedCharacters(exec, date. utf8().data());59 double value = parseDateFromNullTerminatedCharacters(exec, date.UTF8String().data()); 60 60 exec->globalData().cachedDateString = date; 61 61 exec->globalData().cachedDateStringValue = value; -
trunk/JavaScriptCore/runtime/Identifier.h
r65295 r65302 45 45 Identifier(JSGlobalData* globalData, const UString& s) : m_string(add(globalData, s.impl())) { } 46 46 47 // Special constructor for cases where we overwrite an object in place. 48 Identifier(PlacementNewAdoptType) : m_string(PlacementNewAdopt) { } 49 47 50 const UString& ustring() const { return m_string; } 48 51 StringImpl* impl() const { return m_string.impl(); } … … 66 69 uint32_t toUInt32(bool* ok, bool tolerateEmptyString) const { return m_string.toUInt32(ok, tolerateEmptyString); }; 67 70 uint32_t toStrictUInt32(bool* ok) const { return m_string.toStrictUInt32(ok); } 71 unsigned toArrayIndex(bool* ok) const { return m_string.toArrayIndex(ok); } 68 72 double toDouble() const { return m_string.toDouble(); } 69 73 -
trunk/JavaScriptCore/runtime/JSArray.cpp
r65295 r65302 274 274 275 275 bool isArrayIndex; 276 unsigned i = toArrayIndex(propertyName.ustring(),&isArrayIndex);276 unsigned i = propertyName.toArrayIndex(&isArrayIndex); 277 277 if (isArrayIndex) 278 278 return JSArray::getOwnPropertySlot(exec, i, slot); … … 291 291 292 292 bool isArrayIndex; 293 unsigned i = toArrayIndex(propertyName.ustring(),&isArrayIndex);293 unsigned i = propertyName.toArrayIndex(&isArrayIndex); 294 294 if (isArrayIndex) { 295 295 if (i >= storage->m_length) … … 318 318 { 319 319 bool isArrayIndex; 320 unsigned i = toArrayIndex(propertyName.ustring(),&isArrayIndex);320 unsigned i = propertyName.toArrayIndex(&isArrayIndex); 321 321 if (isArrayIndex) { 322 322 put(exec, i, value); … … 476 476 { 477 477 bool isArrayIndex; 478 unsigned i = toArrayIndex(propertyName.ustring(),&isArrayIndex);478 unsigned i = propertyName.toArrayIndex(&isArrayIndex); 479 479 if (isArrayIndex) 480 480 return deleteProperty(exec, i); -
trunk/JavaScriptCore/runtime/JSArray.h
r65295 r65302 262 262 } 263 263 } 264 265 // Rule from ECMA 15.2 about what an array index is. 266 // Must exactly match string form of an unsigned integer, and be less than 2^32 - 1. 267 inline unsigned toArrayIndex(const UString& string, bool* ok) 268 { 269 unsigned i = string.toStrictUInt32(ok); 270 if (ok && i >= 0xFFFFFFFFU) 271 *ok = false; 272 return i; 273 } 274 264 275 265 } // namespace JSC 276 266 -
trunk/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp
r65295 r65302 54 54 { 55 55 UString str = exec->argument(0).toString(exec); 56 CString cstr = str. utf8(true);56 CString cstr = str.UTF8String(true); 57 57 if (!cstr.data()) 58 58 return throwError(exec, createURIError(exec, "String contained an illegal UTF-16 sequence.")); … … 266 266 if (number >= mantissaOverflowLowerBound) { 267 267 if (radix == 10) 268 number = WTF::strtod(s.substr(firstDigitPosition, p - firstDigitPosition). utf8().data(), 0);268 number = WTF::strtod(s.substr(firstDigitPosition, p - firstDigitPosition).UTF8String().data(), 0); 269 269 else if (radix == 2 || radix == 4 || radix == 8 || radix == 16 || radix == 32) 270 number = parseIntOverflow(s.substr(firstDigitPosition, p - firstDigitPosition). utf8().data(), p - firstDigitPosition, radix);270 number = parseIntOverflow(s.substr(firstDigitPosition, p - firstDigitPosition).UTF8String().data(), p - firstDigitPosition, radix); 271 271 } 272 272 … … 454 454 EncodedJSValue JSC_HOST_CALL globalFuncJSCPrint(ExecState* exec) 455 455 { 456 CString string = exec->argument(0).toString(exec). utf8();456 CString string = exec->argument(0).toString(exec).UTF8String(); 457 457 puts(string.data()); 458 458 return JSValue::encode(jsUndefined()); -
trunk/JavaScriptCore/runtime/JSString.h
r65295 r65302 192 192 { 193 193 ASSERT(!m_value.isNull()); 194 Heap::heap(this)->reportExtraMemoryCost(value. impl()->cost());194 Heap::heap(this)->reportExtraMemoryCost(value.cost()); 195 195 } 196 196 … … 309 309 m_other.m_finalizerCallback = finalizer; 310 310 m_other.m_finalizerContext = context; 311 Heap::heap(this)->reportExtraMemoryCost(value. impl()->cost());311 Heap::heap(this)->reportExtraMemoryCost(value.cost()); 312 312 } 313 313 -
trunk/JavaScriptCore/runtime/UString.cpp
r65295 r65302 258 258 } 259 259 260 // FIXME: If tolerateTrailingJunk is true, then we want to tolerate junk 261 // after the number, even if it contains invalid UTF-16 sequences. So we 262 // shouldn't use the UTF8String function, which returns null when it 263 // encounters invalid UTF-16. Further, we have no need to convert the 264 // non-ASCII characters to UTF-8, so the UTF8String does quite a bit of 265 // unnecessary work. 266 267 // FIXME: The space skipping code below skips only ASCII spaces, but callers 268 // need to skip all StrWhiteSpace. The isStrWhiteSpace function does the 269 // right thing but requires UChar, not char, for its argument. 270 260 271 const UChar* data = this->characters(); 261 272 const UChar* end = data + size; … … 584 595 } 585 596 586 // Helper to write a three-byte UTF-8 code point to the buffer, caller must check room is available. 587 static inline void putUTF8Triple(char*& buffer, UChar ch) 588 { 589 ASSERT(ch >= 0x0800); 590 *buffer++ = static_cast<char>(((ch >> 12) & 0x0F) | 0xE0); 591 *buffer++ = static_cast<char>(((ch >> 6) & 0x3F) | 0x80); 592 *buffer++ = static_cast<char>((ch & 0x3F) | 0x80); 593 } 594 595 CString UString::utf8(bool strict) const 596 { 597 unsigned length = this->length(); 598 const UChar* characters = this->characters(); 599 600 // Allocate a buffer big enough to hold all the characters 601 // (an individual UTF-16 UChar can only expand to 3 UTF-8 bytes). 602 // Optimization ideas, if we find this function is hot: 603 // * We could speculatively create a CStringBuffer to contain 'length' 604 // characters, and resize if necessary (i.e. if the buffer contains 605 // non-ascii characters). (Alternatively, scan the buffer first for 606 // ascii characters, so we know this will be sufficient). 607 // * We could allocate a CStringBuffer with an appropriate size to 608 // have a good chance of being able to write the string into the 609 // buffer without reallocing (say, 1.5 x length). 610 Vector<char, 1024> bufferVector(length * 3); 611 612 char* buffer = bufferVector.data(); 613 ConversionResult result = convertUTF16ToUTF8(&characters, characters + length, &buffer, buffer + bufferVector.size(), strict); 614 ASSERT(result != targetExhausted); // (length * 3) should be sufficient for any conversion 615 616 if (result == sourceIllegal) // Only produced from strict conversion. 597 CString UString::UTF8String(bool strict) const 598 { 599 // Allocate a buffer big enough to hold all the characters. 600 const unsigned len = length(); 601 Vector<char, 1024> buffer(len * 3); 602 603 // Convert to runs of 8-bit characters. 604 char* p = buffer.data(); 605 const UChar* d = reinterpret_cast<const UChar*>(&characters()[0]); 606 ConversionResult result = convertUTF16ToUTF8(&d, d + len, &p, p + buffer.size(), strict); 607 if (result != conversionOK) 617 608 return CString(); 618 609 619 // If a high surrogate is left unconverted, treat it the same was as an unpaired high surrogate 620 // would have been handled in the middle of a string with non-strict conversion - which is to say, 621 // simply encode it to UTF-8. 622 if (result == sourceExhausted) { 623 // This should be one unpaired high surrogate. 624 ASSERT((characters + 1) == (this->characters() + length)); 625 ASSERT((*characters >= 0xD800) && (*characters <= 0xDBFF)); 626 // There should be room left, since one UChar hasn't been converted. 627 ASSERT((buffer + 3) <= (buffer + bufferVector.size())); 628 putUTF8Triple(buffer, *characters); 629 } 630 631 return CString(bufferVector.data(), buffer - bufferVector.data()); 610 return CString(buffer.data(), p - buffer.data()); 632 611 } 633 612 -
trunk/JavaScriptCore/runtime/UString.h
r65295 r65302 39 39 namespace JSC { 40 40 41 using WTF::PlacementNewAdoptType; 42 using WTF::PlacementNewAdopt; 43 41 44 class UString { 42 45 public: … … 61 64 UString(RefPtr<StringImpl> impl) : m_impl(impl) { } 62 65 63 // Inline the destructor.64 ALWAYS_INLINE ~UString() { }65 66 66 void swap(UString& o) { m_impl.swap(o.m_impl); } 67 67 … … 69 69 static UString adopt(Vector<UChar, inlineCapacity>& vector) { return StringImpl::adopt(vector); } 70 70 71 bool isNull() const { return !m_impl; }72 bool isEmpty() const { return !m_impl || !m_impl->length(); }73 74 StringImpl* impl() const { return m_impl.get(); }75 76 unsigned length() const77 {78 if (!m_impl)79 return 0;80 return m_impl->length();81 }82 83 const UChar* characters() const84 {85 if (!m_impl)86 return 0;87 return m_impl->characters();88 }89 90 CString utf8(bool strict = false) const;91 92 UChar operator[](unsigned index) const93 {94 if (!m_impl || index >= m_impl->length())95 return 0;96 return m_impl->characters()[index];97 }98 99 71 static UString number(int); 72 static UString number(long long); 100 73 static UString number(unsigned); 101 74 static UString number(long); 102 static UString number(long long);103 75 static UString number(double); 104 76 105 77 // NOTE: This method should only be used for *debugging* purposes as it 78 // is neither Unicode safe nor free from side effects nor thread-safe. 79 char* ascii() const; 80 81 /** 82 * Convert the string to UTF-8, assuming it is UTF-16 encoded. 83 * In non-strict mode, this function is tolerant of badly formed UTF-16, it 84 * can create UTF-8 strings that are invalid because they have characters in 85 * the range U+D800-U+DDFF, U+FFFE, or U+FFFF, but the UTF-8 string is 86 * guaranteed to be otherwise valid. 87 * In strict mode, error is returned as null CString. 88 */ 89 CString UTF8String(bool strict = false) const; 90 91 unsigned length() const 92 { 93 if (!m_impl) 94 return 0; 95 return m_impl->length(); 96 } 97 98 const UChar* characters() const 99 { 100 if (!m_impl) 101 return 0; 102 return m_impl->characters(); 103 } 104 105 UChar operator[](unsigned index) const 106 { 107 if (!m_impl || index >= m_impl->length()) 108 return 0; 109 return m_impl->characters()[index]; 110 } 106 111 107 112 double toDouble(bool tolerateTrailingJunk, bool tolerateEmptyString) const; … … 112 117 uint32_t toUInt32(bool* ok, bool tolerateEmptyString) const; 113 118 uint32_t toStrictUInt32(bool* ok = 0) const; 119 120 unsigned toArrayIndex(bool* ok = 0) const; 114 121 115 122 static const unsigned NotFound = 0xFFFFFFFFu; … … 121 128 UString substr(unsigned pos = 0, unsigned len = 0xFFFFFFFF) const; 122 129 123 // NOTE: This method should only be used for *debugging* purposes as it 124 // is neither Unicode safe nor free from side effects nor thread-safe. 125 char* ascii() const; 126 130 bool isNull() const { return !m_impl; } 131 bool isEmpty() const { return !m_impl || !m_impl->length(); } 132 133 StringImpl* impl() const { return m_impl.get(); } 134 135 size_t cost() const 136 { 137 if (!m_impl) 138 return 0; 139 return m_impl->cost(); 140 } 141 142 ALWAYS_INLINE ~UString() { } 127 143 private: 128 144 RefPtr<StringImpl> m_impl; … … 202 218 } 203 219 220 // Rule from ECMA 15.2 about what an array index is. 221 // Must exactly match string form of an unsigned integer, and be less than 2^32 - 1. 222 inline unsigned UString::toArrayIndex(bool* ok) const 223 { 224 unsigned i = toStrictUInt32(ok); 225 if (ok && i >= 0xFFFFFFFFU) 226 *ok = false; 227 return i; 228 } 229 204 230 // We'd rather not do shared substring append for small strings, since 205 231 // this runs too much risk of a tiny initial string holding down a -
trunk/JavaScriptCore/wtf/text/WTFString.cpp
r65295 r65302 655 655 } 656 656 657 CString String::utf8( bool strict) const657 CString String::utf8() const 658 658 { 659 659 unsigned length = this->length(); … … 673 673 674 674 char* buffer = bufferVector.data(); 675 ConversionResult result = convertUTF16ToUTF8(&characters, characters + length, &buffer, buffer + bufferVector.size(), strict); 675 ConversionResult result = convertUTF16ToUTF8(&characters, characters + length, &buffer, buffer + bufferVector.size(), false); 676 ASSERT(result != sourceIllegal); // Only produced from strict conversion. 676 677 ASSERT(result != targetExhausted); // (length * 3) should be sufficient for any conversion 677 678 if (result == sourceIllegal) // Only produced from strict conversion.679 return CString();680 678 681 679 // If a high surrogate is left unconverted, treat it the same was as an unpaired high surrogate -
trunk/JavaScriptCore/wtf/text/WTFString.h
r65295 r65302 98 98 String(RefPtr<StringImpl> impl) : m_impl(impl) { } 99 99 100 // Inline the destructor.101 ALWAYS_INLINE ~String() { }102 103 100 void swap(String& o) { m_impl.swap(o.m_impl); } 101 102 // Hash table deleted values, which are only constructed and never copied or destroyed. 103 String(WTF::HashTableDeletedValueType) : m_impl(WTF::HashTableDeletedValue) { } 104 bool isHashTableDeletedValue() const { return m_impl.isHashTableDeletedValue(); } 104 105 105 106 static String adopt(StringBuffer& buffer) { return StringImpl::adopt(buffer); } … … 107 108 static String adopt(Vector<UChar, inlineCapacity>& vector) { return StringImpl::adopt(vector); } 108 109 109 bool isNull() const { return !m_impl; } 110 bool isEmpty() const { return !m_impl || !m_impl->length(); } 111 112 StringImpl* impl() const { return m_impl.get(); } 113 114 unsigned length() const 110 111 ALWAYS_INLINE unsigned length() const 115 112 { 116 113 if (!m_impl) … … 126 123 } 127 124 128 CString latin1() const; 129 CString utf8(bool strict = false) const; 130 125 const UChar* charactersWithNullTermination(); 126 131 127 UChar operator[](unsigned index) const 132 128 { … … 135 131 return m_impl->characters()[index]; 136 132 } 133 UChar32 characterStartingAt(unsigned) const; // Ditto. 134 135 bool contains(UChar c) const { return find(c) != -1; } 136 bool contains(const char* str, bool caseSensitive = true) const { return find(str, 0, caseSensitive) != -1; } 137 bool contains(const String& str, bool caseSensitive = true) const { return find(str, 0, caseSensitive) != -1; } 138 139 int find(UChar c, int start = 0) const 140 { return m_impl ? m_impl->find(c, start) : -1; } 141 int find(CharacterMatchFunctionPtr matchFunction, int start = 0) const 142 { return m_impl ? m_impl->find(matchFunction, start) : -1; } 143 int find(const char* str, int start = 0, bool caseSensitive = true) const 144 { return m_impl ? m_impl->find(str, start, caseSensitive) : -1; } 145 int find(const String& str, int start = 0, bool caseSensitive = true) const 146 { return m_impl ? m_impl->find(str.impl(), start, caseSensitive) : -1; } 147 148 int reverseFind(UChar c, int start = -1) const 149 { return m_impl ? m_impl->reverseFind(c, start) : -1; } 150 int reverseFind(const String& str, int start = -1, bool caseSensitive = true) const 151 { return m_impl ? m_impl->reverseFind(str.impl(), start, caseSensitive) : -1; } 152 153 bool startsWith(const String& s, bool caseSensitive = true) const 154 { return m_impl ? m_impl->startsWith(s.impl(), caseSensitive) : s.isEmpty(); } 155 bool endsWith(const String& s, bool caseSensitive = true) const 156 { return m_impl ? m_impl->endsWith(s.impl(), caseSensitive) : s.isEmpty(); } 157 158 void append(const String&); 159 void append(char); 160 void append(UChar); 161 void append(const UChar*, unsigned length); 162 void insert(const String&, unsigned pos); 163 void insert(const UChar*, unsigned length, unsigned pos); 164 165 String& replace(UChar a, UChar b) { if (m_impl) m_impl = m_impl->replace(a, b); return *this; } 166 String& replace(UChar a, const String& b) { if (m_impl) m_impl = m_impl->replace(a, b.impl()); return *this; } 167 String& replace(const String& a, const String& b) { if (m_impl) m_impl = m_impl->replace(a.impl(), b.impl()); return *this; } 168 String& replace(unsigned index, unsigned len, const String& b) { if (m_impl) m_impl = m_impl->replace(index, len, b.impl()); return *this; } 169 170 void makeLower() { if (m_impl) m_impl = m_impl->lower(); } 171 void makeUpper() { if (m_impl) m_impl = m_impl->upper(); } 172 void makeSecure(UChar aChar) { if (m_impl) m_impl = m_impl->secure(aChar); } 173 174 void truncate(unsigned len); 175 void remove(unsigned pos, int len = 1); 176 177 String substring(unsigned pos, unsigned len = UINT_MAX) const; 178 String left(unsigned len) const { return substring(0, len); } 179 String right(unsigned len) const { return substring(length() - len, len); } 180 181 // Returns a lowercase/uppercase version of the string 182 String lower() const; 183 String upper() const; 184 185 String stripWhiteSpace() const; 186 String simplifyWhiteSpace() const; 187 188 String removeCharacters(CharacterMatchFunctionPtr) const; 189 190 // Return the string with case folded for case insensitive comparison. 191 String foldCase() const; 137 192 138 193 static String number(short); … … 146 201 static String number(double); 147 202 148 149 150 const UChar* charactersWithNullTermination();151 152 UChar32 characterStartingAt(unsigned) const; // Ditto.153 154 bool contains(UChar c) const { return find(c) != -1; }155 bool contains(const char* str, bool caseSensitive = true) const { return find(str, 0, caseSensitive) != -1; }156 bool contains(const String& str, bool caseSensitive = true) const { return find(str, 0, caseSensitive) != -1; }157 158 int find(UChar c, int start = 0) const159 { return m_impl ? m_impl->find(c, start) : -1; }160 int find(CharacterMatchFunctionPtr matchFunction, int start = 0) const161 { return m_impl ? m_impl->find(matchFunction, start) : -1; }162 int find(const char* str, int start = 0, bool caseSensitive = true) const163 { return m_impl ? m_impl->find(str, start, caseSensitive) : -1; }164 int find(const String& str, int start = 0, bool caseSensitive = true) const165 { return m_impl ? m_impl->find(str.impl(), start, caseSensitive) : -1; }166 167 int reverseFind(UChar c, int start = -1) const168 { return m_impl ? m_impl->reverseFind(c, start) : -1; }169 int reverseFind(const String& str, int start = -1, bool caseSensitive = true) const170 { return m_impl ? m_impl->reverseFind(str.impl(), start, caseSensitive) : -1; }171 172 bool startsWith(const String& s, bool caseSensitive = true) const173 { return m_impl ? m_impl->startsWith(s.impl(), caseSensitive) : s.isEmpty(); }174 bool endsWith(const String& s, bool caseSensitive = true) const175 { return m_impl ? m_impl->endsWith(s.impl(), caseSensitive) : s.isEmpty(); }176 177 void append(const String&);178 void append(char);179 void append(UChar);180 void append(const UChar*, unsigned length);181 void insert(const String&, unsigned pos);182 void insert(const UChar*, unsigned length, unsigned pos);183 184 String& replace(UChar a, UChar b) { if (m_impl) m_impl = m_impl->replace(a, b); return *this; }185 String& replace(UChar a, const String& b) { if (m_impl) m_impl = m_impl->replace(a, b.impl()); return *this; }186 String& replace(const String& a, const String& b) { if (m_impl) m_impl = m_impl->replace(a.impl(), b.impl()); return *this; }187 String& replace(unsigned index, unsigned len, const String& b) { if (m_impl) m_impl = m_impl->replace(index, len, b.impl()); return *this; }188 189 void makeLower() { if (m_impl) m_impl = m_impl->lower(); }190 void makeUpper() { if (m_impl) m_impl = m_impl->upper(); }191 void makeSecure(UChar aChar) { if (m_impl) m_impl = m_impl->secure(aChar); }192 193 void truncate(unsigned len);194 void remove(unsigned pos, int len = 1);195 196 String substring(unsigned pos, unsigned len = UINT_MAX) const;197 String left(unsigned len) const { return substring(0, len); }198 String right(unsigned len) const { return substring(length() - len, len); }199 200 // Returns a lowercase/uppercase version of the string201 String lower() const;202 String upper() const;203 204 String stripWhiteSpace() const;205 String simplifyWhiteSpace() const;206 207 String removeCharacters(CharacterMatchFunctionPtr) const;208 209 // Return the string with case folded for case insensitive comparison.210 String foldCase() const;211 212 203 #if !PLATFORM(QT) 213 204 static String format(const char *, ...) WTF_ATTRIBUTE_PRINTF(1, 2); … … 250 241 String threadsafeCopy() const; 251 242 243 bool isNull() const { return !m_impl; } 244 ALWAYS_INLINE bool isEmpty() const { return !m_impl || !m_impl->length(); } 245 246 StringImpl* impl() const { return m_impl.get(); } 247 252 248 #if PLATFORM(CF) 253 249 String(CFStringRef); … … 281 277 Vector<char> ascii() const; 282 278 279 CString latin1() const; 280 CString utf8() const; 281 283 282 static String fromUTF8(const char*, size_t); 284 283 static String fromUTF8(const char*); … … 291 290 292 291 bool containsOnlyASCII() const { return charactersAreAllASCII(characters(), length()); } 293 294 // Hash table deleted values, which are only constructed and never copied or destroyed.295 String(WTF::HashTableDeletedValueType) : m_impl(WTF::HashTableDeletedValue) { }296 bool isHashTableDeletedValue() const { return m_impl.isHashTableDeletedValue(); }297 292 298 293 private:
Note:
See TracChangeset
for help on using the changeset viewer.