Changeset 65305 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
Aug 13, 2010, 12:35:45 AM (15 years ago)
Author:
[email protected]
Message:

Unify UString::UTF8String() & String::utf8() methods,
remove UString::cost() & make atArrayIndex a free function.

Reviewed by Sam Weinig

JavaScriptCore:

(JSC::constantName):
(JSC::idName):
(JSC::CodeBlock::registerName):
(JSC::regexpName):
(JSC::printGlobalResolveInfo):
(JSC::printStructureStubInfo):
(JSC::CodeBlock::printStructure):
(JSC::CodeBlock::printStructures):

  • jsc.cpp:

(functionPrint):
(functionDebug):
(runInteractive):
(fillBufferWithContentsOfFile):

  • pcre/pcre_exec.cpp:

(Histogram::~Histogram):

  • profiler/CallIdentifier.h:

(JSC::CallIdentifier::c_str):

  • profiler/Profile.cpp:

(JSC::Profile::debugPrintDataSampleStyle):

  • profiler/ProfileGenerator.cpp:

(JSC::ProfileGenerator::willExecute):
(JSC::ProfileGenerator::didExecute):

  • profiler/ProfileNode.cpp:

(JSC::ProfileNode::debugPrintData):
(JSC::ProfileNode::debugPrintDataSampleStyle):

  • runtime/Arguments.cpp:

(JSC::Arguments::getOwnPropertySlot):
(JSC::Arguments::getOwnPropertyDescriptor):
(JSC::Arguments::put):
(JSC::Arguments::deleteProperty):

  • runtime/DateConversion.cpp:

(JSC::parseDate):

  • runtime/Identifier.h:

(JSC::Identifier::toStrictUInt32):

  • runtime/JSArray.cpp:

(JSC::JSArray::getOwnPropertySlot):
(JSC::JSArray::getOwnPropertyDescriptor):
(JSC::JSArray::put):
(JSC::JSArray::deleteProperty):

  • runtime/JSArray.h:

(JSC::toArrayIndex):

  • runtime/JSGlobalObjectFunctions.cpp:

(JSC::encode):
(JSC::parseInt):
(JSC::globalFuncJSCPrint):

  • runtime/JSString.h:

(JSC::RopeBuilder::JSString):

  • runtime/UString.cpp:

(JSC::UString::toDouble):
(JSC::putUTF8Triple):
(JSC::UString::utf8):

  • runtime/UString.h:

(JSC::UString::~UString):
(JSC::UString::isNull):
(JSC::UString::isEmpty):
(JSC::UString::impl):

  • wtf/text/WTFString.cpp:

(WTF::String::utf8):

  • wtf/text/WTFString.h:

(WTF::String::~String):
(WTF::String::swap):
(WTF::String::isNull):
(WTF::String::isEmpty):
(WTF::String::impl):
(WTF::String::length):
(WTF::String::String):
(WTF::String::isHashTableDeletedValue):

WebCore:

  • WebCore.xcodeproj/project.pbxproj:
  • bindings/js/JSDOMWindowCustom.cpp:

(WebCore::JSDOMWindow::getOwnPropertySlot):
(WebCore::JSDOMWindow::getOwnPropertyDescriptor):

  • bridge/NP_jsobject.cpp:

(_NPN_Enumerate):

  • bridge/c/c_utility.cpp:

(JSC::Bindings::convertValueToNPVariant):

  • bridge/jni/JNIBridge.cpp:

(JavaParameter::JavaParameter):
(JavaMethod::JavaMethod):
(JavaMethod::signature):
(JavaMethod::methodID):

  • bridge/jni/JNIBridge.h:

(JSC::Bindings::JavaString::utf8):
(JSC::Bindings::JavaParameter::type):
(JSC::Bindings::JavaMethod::returnType):

  • bridge/jni/jni_jsobject.mm:

(JavaJSObject::call):
(JavaJSObject::eval):
(JavaJSObject::getMember):
(JavaJSObject::setMember):
(JavaJSObject::removeMember):
(JavaJSObject::convertJObjectToValue):

  • bridge/jni/jsc/JNIBridgeJSC.cpp:

(JavaField::JavaField):
(JavaField::valueFromInstance):
(JavaField::setValueToInstance):

  • bridge/jni/jsc/JNIBridgeJSC.h:

(JSC::Bindings::JavaField::type):

  • bridge/jni/jsc/JavaInstanceJSC.cpp:

(JavaInstance::invokeMethod):

  • bridge/jni/jsc/JavaStringJSC.h:

(JSC::Bindings::JavaStringImpl::utf8):

  • bridge/runtime_array.cpp:

(JSC::RuntimeArray::getOwnPropertySlot):
(JSC::RuntimeArray::getOwnPropertyDescriptor):
(JSC::RuntimeArray::put):

WebKit/mac:

  • Plugins/Hosted/NetscapePluginInstanceProxy.mm:

(WebKit::NetscapePluginInstanceProxy::enumerate):

WebKit/wx:

  • WebFrame.cpp:

(wxWebFrame::RunScript):

WebKit2:

  • WebProcess/Plugins/JSNPObject.cpp:

(WebKit::npIdentifierFromIdentifier):

  • WebProcess/Plugins/NPJSObject.cpp:

(WebKit::NPJSObject::enumerate):

  • WebProcess/Plugins/NPRuntimeObjectMap.cpp:

(WebKit::NPRuntimeObjectMap::convertJSValueToNPVariant):

Location:
trunk/JavaScriptCore
Files:
21 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r65303 r65305  
     12010-08-13  Gavin Barraclough  <[email protected]>
     2
     3        Reviewed by Sam Weinig
     4
     5        Unify UString::UTF8String() & String::utf8() methods,
     6        remove UString::cost() & make atArrayIndex a free function.
     7
     8        * JavaScriptCore.exp:
     9        * bytecode/CodeBlock.cpp:
     10        (JSC::constantName):
     11        (JSC::idName):
     12        (JSC::CodeBlock::registerName):
     13        (JSC::regexpName):
     14        (JSC::printGlobalResolveInfo):
     15        (JSC::printStructureStubInfo):
     16        (JSC::CodeBlock::printStructure):
     17        (JSC::CodeBlock::printStructures):
     18        * jsc.cpp:
     19        (functionPrint):
     20        (functionDebug):
     21        (runInteractive):
     22        (fillBufferWithContentsOfFile):
     23        * pcre/pcre_exec.cpp:
     24        (Histogram::~Histogram):
     25        * profiler/CallIdentifier.h:
     26        (JSC::CallIdentifier::c_str):
     27        * profiler/Profile.cpp:
     28        (JSC::Profile::debugPrintDataSampleStyle):
     29        * profiler/ProfileGenerator.cpp:
     30        (JSC::ProfileGenerator::willExecute):
     31        (JSC::ProfileGenerator::didExecute):
     32        * profiler/ProfileNode.cpp:
     33        (JSC::ProfileNode::debugPrintData):
     34        (JSC::ProfileNode::debugPrintDataSampleStyle):
     35        * runtime/Arguments.cpp:
     36        (JSC::Arguments::getOwnPropertySlot):
     37        (JSC::Arguments::getOwnPropertyDescriptor):
     38        (JSC::Arguments::put):
     39        (JSC::Arguments::deleteProperty):
     40        * runtime/DateConversion.cpp:
     41        (JSC::parseDate):
     42        * runtime/Identifier.h:
     43        (JSC::Identifier::toStrictUInt32):
     44        * runtime/JSArray.cpp:
     45        (JSC::JSArray::getOwnPropertySlot):
     46        (JSC::JSArray::getOwnPropertyDescriptor):
     47        (JSC::JSArray::put):
     48        (JSC::JSArray::deleteProperty):
     49        * runtime/JSArray.h:
     50        (JSC::toArrayIndex):
     51        * runtime/JSGlobalObjectFunctions.cpp:
     52        (JSC::encode):
     53        (JSC::parseInt):
     54        (JSC::globalFuncJSCPrint):
     55        * runtime/JSString.h:
     56        (JSC::RopeBuilder::JSString):
     57        * runtime/UString.cpp:
     58        (JSC::UString::toDouble):
     59        (JSC::putUTF8Triple):
     60        (JSC::UString::utf8):
     61        * runtime/UString.h:
     62        (JSC::UString::~UString):
     63        (JSC::UString::isNull):
     64        (JSC::UString::isEmpty):
     65        (JSC::UString::impl):
     66        * wtf/text/WTFString.cpp:
     67        (WTF::String::utf8):
     68        * wtf/text/WTFString.h:
     69        (WTF::String::~String):
     70        (WTF::String::swap):
     71        (WTF::String::isNull):
     72        (WTF::String::isEmpty):
     73        (WTF::String::impl):
     74        (WTF::String::length):
     75        (WTF::String::String):
     76        (WTF::String::isHashTableDeletedValue):
     77
    1782010-08-12  Zoltan Herczeg  <[email protected]>
    279
  • trunk/JavaScriptCore/JavaScriptCore.exp

    r65302 r65305  
    514514__ZNK3JSC7JSValue20toThisObjectSlowCaseEPNS_9ExecStateE
    515515__ZNK3JSC7JSValue9toIntegerEPNS_9ExecStateE
    516 __ZNK3JSC7UString10UTF8StringEb
    517516__ZNK3JSC7UString14toStrictUInt32EPb
     517__ZNK3JSC7UString4utf8Eb
    518518__ZNK3JSC7UString5asciiEv
    519519__ZNK3JSC7UString6substrEjj
     
    541541__ZNK3WTF6String18simplifyWhiteSpaceEv
    542542__ZNK3WTF6String19characterStartingAtEj
    543 __ZNK3WTF6String4utf8Ev
     543__ZNK3WTF6String4utf8Eb
    544544__ZNK3WTF6String5asciiEv
    545545__ZNK3WTF6String5lowerEv
  • trunk/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj

    r65207 r65305  
    23272327                        buildConfigurationList = 149C277108902AFE008A9EFC /* Build configuration list for PBXProject "JavaScriptCore" */;
    23282328                        compatibilityVersion = "Xcode 2.4";
    2329                         developmentRegion = English;
    23302329                        hasScannedForEncodings = 1;
    23312330                        knownRegions = (
  • trunk/JavaScriptCore/bytecode/CodeBlock.cpp

    r65302 r65305  
    7272static CString constantName(ExecState* exec, int k, JSValue value)
    7373{
    74     return makeString(valueToSourceString(exec, value), "(@k", UString::number(k - FirstConstantRegisterIndex), ")").UTF8String();
     74    return makeString(valueToSourceString(exec, value), "(@k", UString::number(k - FirstConstantRegisterIndex), ")").utf8();
    7575}
    7676
    7777static CString idName(int id0, const Identifier& ident)
    7878{
    79     return makeString(ident.ustring(), "(@id", UString::number(id0), ")").UTF8String();
     79    return makeString(ident.ustring(), "(@id", UString::number(id0), ")").utf8();
    8080}
    8181
     
    8888        return constantName(exec, r, getConstant(r));
    8989
    90     return makeString("r", UString::number(r)).UTF8String();
     90    return makeString("r", UString::number(r)).utf8();
    9191}
    9292
     
    107107static CString regexpName(int re, RegExp* regexp)
    108108{
    109     return makeString(regexpToSourceString(regexp), "(@re", UString::number(re), ")").UTF8String();
     109    return makeString(regexpToSourceString(regexp), "(@re", UString::number(re), ")").utf8();
    110110}
    111111
     
    225225static void printGlobalResolveInfo(const GlobalResolveInfo& resolveInfo, unsigned instructionOffset)
    226226{
    227     printf("  [%4d] %s: %s\n", instructionOffset, "resolve_global", pointerToSourceString(resolveInfo.structure).UTF8String().data());
     227    printf("  [%4d] %s: %s\n", instructionOffset, "resolve_global", pointerToSourceString(resolveInfo.structure).utf8().data());
    228228}
    229229
     
    232232    switch (stubInfo.accessType) {
    233233    case access_get_by_id_self:
    234         printf("  [%4d] %s: %s\n", instructionOffset, "get_by_id_self", pointerToSourceString(stubInfo.u.getByIdSelf.baseObjectStructure).UTF8String().data());
     234        printf("  [%4d] %s: %s\n", instructionOffset, "get_by_id_self", pointerToSourceString(stubInfo.u.getByIdSelf.baseObjectStructure).utf8().data());
    235235        return;
    236236    case access_get_by_id_proto:
    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());
     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());
    238238        return;
    239239    case access_get_by_id_chain:
    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());
     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());
    241241        return;
    242242    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).UTF8String().data(), stubInfo.u.getByIdSelfList.listSize);
     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);
    244244        return;
    245245    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).UTF8String().data(), stubInfo.u.getByIdProtoList.listSize);
     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);
    247247        return;
    248248    case access_put_by_id_transition:
    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());
     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());
    250250        return;
    251251    case access_put_by_id_replace:
    252         printf("  [%4d] %s: %s\n", instructionOffset, "put_by_id_replace", pointerToSourceString(stubInfo.u.putByIdReplace.baseObjectStructure).UTF8String().data());
     252        printf("  [%4d] %s: %s\n", instructionOffset, "put_by_id_replace", pointerToSourceString(stubInfo.u.putByIdReplace.baseObjectStructure).utf8().data());
    253253        return;
    254254    case access_get_by_id:
     
    279279{
    280280    unsigned instructionOffset = vPC - m_instructions.begin();
    281     printf("  [%4d] %s: %s\n", instructionOffset, name, pointerToSourceString(vPC[operand].u.structure).UTF8String().data());
     281    printf("  [%4d] %s: %s\n", instructionOffset, name, pointerToSourceString(vPC[operand].u.structure).utf8().data());
    282282}
    283283
     
    296296    }
    297297    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).UTF8String().data(), pointerToSourceString(vPC[5].u.structure).UTF8String().data());
     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());
    299299        return;
    300300    }
    301301    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).UTF8String().data(), pointerToSourceString(vPC[5].u.structure).UTF8String().data(), pointerToSourceString(vPC[6].u.structureChain).UTF8String().data());
     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());
    303303        return;
    304304    }
    305305    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).UTF8String().data(), pointerToSourceString(vPC[5].u.structureChain).UTF8String().data());
     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());
    307307        return;
    308308    }
  • trunk/JavaScriptCore/jsc.cpp

    r65302 r65305  
    179179            putchar(' ');
    180180
    181         printf("%s", exec->argument(i).toString(exec).UTF8String().data());
     181        printf("%s", exec->argument(i).toString(exec).utf8().data());
    182182    }
    183183
     
    189189EncodedJSValue JSC_HOST_CALL functionDebug(ExecState* exec)
    190190{
    191     fprintf(stderr, "--> %s\n", exec->argument(0).toString(exec).UTF8String().data());
     191    fprintf(stderr, "--> %s\n", exec->argument(0).toString(exec).utf8().data());
    192192    return JSValue::encode(jsUndefined());
    193193}
     
    443443            printf("Exception: %s\n", completion.value().toString(globalObject->globalExec()).ascii());
    444444        else
    445             printf("%s\n", completion.value().toString(globalObject->globalExec()).UTF8String().data());
     445            printf("%s\n", completion.value().toString(globalObject->globalExec()).utf8().data());
    446446
    447447        globalObject->globalExec()->clearException();
     
    533533static bool fillBufferWithContentsOfFile(const UString& fileName, Vector<char>& buffer)
    534534{
    535     FILE* f = fopen(fileName.UTF8String().data(), "r");
     535    FILE* f = fopen(fileName.utf8().data(), "r");
    536536    if (!f) {
    537         fprintf(stderr, "Could not open file: %s\n", fileName.UTF8String().data());
     537        fprintf(stderr, "Could not open file: %s\n", fileName.utf8().data());
    538538        return false;
    539539    }
  • trunk/JavaScriptCore/pcre/pcre_exec.cpp

    r65302 r65305  
    21442144    printf("Regular Expressions, sorted by time spent evaluating them:\n");
    21452145    for (size_t i = 0; i < size; ++i)
    2146         printf("    %f - %s\n", values[size - i - 1].second, values[size - i - 1].first.UTF8String().c_str());
     2146        printf("    %f - %s\n", values[size - i - 1].second, values[size - i - 1].first.utf8().c_str());
    21472147}
    21482148
  • trunk/JavaScriptCore/profiler/CallIdentifier.h

    r65302 r65305  
    7272#ifndef NDEBUG
    7373        operator const char*() const { return c_str(); }
    74         const char* c_str() const { return m_name.UTF8String().data(); }
     74        const char* c_str() const { return m_name.utf8().data(); }
    7575#endif
    7676    };
  • trunk/JavaScriptCore/profiler/Profile.cpp

    r65302 r65305  
    128128    std::sort(sortedFunctions.begin(), sortedFunctions.end(), functionNameCountPairComparator);
    129129    for (NameCountPairVector::iterator it = sortedFunctions.begin(); it != sortedFunctions.end(); ++it)
    130         printf("        %-12d%s\n", (*it).second, UString((*it).first).UTF8String().data());
     130        printf("        %-12d%s\n", (*it).second, UString((*it).first).utf8().data());
    131131
    132132    printf("\nSort by top of stack, same collapsed (when >= 5):\n");
  • trunk/JavaScriptCore/profiler/ProfileGenerator.cpp

    r65302 r65305  
    7676{
    7777    if (JAVASCRIPTCORE_PROFILE_WILL_EXECUTE_ENABLED()) {
    78         CString name = callIdentifier.m_name.UTF8String();
    79         CString url = callIdentifier.m_url.UTF8String();
     78        CString name = callIdentifier.m_name.utf8();
     79        CString url = callIdentifier.m_url.utf8();
    8080        JAVASCRIPTCORE_PROFILE_WILL_EXECUTE(m_profileGroup, const_cast<char*>(name.data()), const_cast<char*>(url.data()), callIdentifier.m_lineNumber);
    8181    }
     
    9191{
    9292    if (JAVASCRIPTCORE_PROFILE_DID_EXECUTE_ENABLED()) {
    93         CString name = callIdentifier.m_name.UTF8String();
    94         CString url = callIdentifier.m_url.UTF8String();
     93        CString name = callIdentifier.m_name.utf8();
     94        CString url = callIdentifier.m_url.utf8();
    9595        JAVASCRIPTCORE_PROFILE_DID_EXECUTE(m_profileGroup, const_cast<char*>(name.data()), const_cast<char*>(url.data()), callIdentifier.m_lineNumber);
    9696    }
  • trunk/JavaScriptCore/profiler/ProfileNode.cpp

    r65302 r65305  
    295295
    296296    printf("Function Name %s %d SelfTime %.3fms/%.3f%% TotalTime %.3fms/%.3f%% VSelf %.3fms VTotal %.3fms Visible %s Next Sibling %s\n",
    297         functionName().UTF8String().data(),
     297        functionName().utf8().data(),
    298298        m_numberOfCalls, m_actualSelfTime, selfPercent(), m_actualTotalTime, totalPercent(),
    299299        m_visibleSelfTime, m_visibleTotalTime,
    300300        (m_visible ? "True" : "False"),
    301         m_nextSibling ? m_nextSibling->functionName().UTF8String().data() : "");
     301        m_nextSibling ? m_nextSibling->functionName().utf8().data() : "");
    302302
    303303    ++indentLevel;
     
    314314
    315315    // Print function names
    316     const char* name = functionName().UTF8String().data();
     316    const char* name = functionName().utf8().data();
    317317    double sampleCount = m_actualTotalTime * 1000;
    318318    if (indentLevel) {
     
    340340            printf("  ");
    341341
    342         printf("%.0f %s\n", sampleCount - sumOfChildrensCount, functionName().UTF8String().data());
     342        printf("%.0f %s\n", sampleCount - sumOfChildrensCount, functionName().utf8().data());
    343343    }
    344344
  • trunk/JavaScriptCore/runtime/Arguments.cpp

    r65302 r65305  
    158158{
    159159    bool isArrayIndex;
    160     unsigned i = propertyName.toArrayIndex(&isArrayIndex);
     160    unsigned i = toArrayIndex(propertyName.ustring(), &isArrayIndex);
    161161    if (isArrayIndex && i < d->numArguments && (!d->deletedArguments || !d->deletedArguments[i])) {
    162162        if (i < d->numParameters) {
     
    183183{
    184184    bool isArrayIndex;
    185     unsigned i = propertyName.toArrayIndex(&isArrayIndex);
     185    unsigned i = toArrayIndex(propertyName.ustring(), &isArrayIndex);
    186186    if (isArrayIndex && i < d->numArguments && (!d->deletedArguments || !d->deletedArguments[i])) {
    187187        if (i < d->numParameters) {
     
    234234{
    235235    bool isArrayIndex;
    236     unsigned i = propertyName.toArrayIndex(&isArrayIndex);
     236    unsigned i = toArrayIndex(propertyName.ustring(), &isArrayIndex);
    237237    if (isArrayIndex && i < d->numArguments && (!d->deletedArguments || !d->deletedArguments[i])) {
    238238        if (i < d->numParameters)
     
    277277{
    278278    bool isArrayIndex;
    279     unsigned i = propertyName.toArrayIndex(&isArrayIndex);
     279    unsigned i = toArrayIndex(propertyName.ustring(), &isArrayIndex);
    280280    if (isArrayIndex && i < d->numArguments) {
    281281        if (!d->deletedArguments) {
  • trunk/JavaScriptCore/runtime/DateConversion.cpp

    r65302 r65305  
    5757    if (date == exec->globalData().cachedDateString)
    5858        return exec->globalData().cachedDateStringValue;
    59     double value = parseDateFromNullTerminatedCharacters(exec, date.UTF8String().data());
     59    double value = parseDateFromNullTerminatedCharacters(exec, date.utf8().data());
    6060    exec->globalData().cachedDateString = date;
    6161    exec->globalData().cachedDateStringValue = value;
  • trunk/JavaScriptCore/runtime/Identifier.h

    r65302 r65305  
    4545        Identifier(JSGlobalData* globalData, const UString& s) : m_string(add(globalData, s.impl())) { }
    4646
    47         // Special constructor for cases where we overwrite an object in place.
    48         Identifier(PlacementNewAdoptType) : m_string(PlacementNewAdopt) { }
    49        
    5047        const UString& ustring() const { return m_string; }
    5148        StringImpl* impl() const { return m_string.impl(); }
     
    6966        uint32_t toUInt32(bool* ok, bool tolerateEmptyString) const { return m_string.toUInt32(ok, tolerateEmptyString); };
    7067        uint32_t toStrictUInt32(bool* ok) const { return m_string.toStrictUInt32(ok); }
    71         unsigned toArrayIndex(bool* ok) const { return m_string.toArrayIndex(ok); }
    7268        double toDouble() const { return m_string.toDouble(); }
    7369       
  • trunk/JavaScriptCore/runtime/JSArray.cpp

    r65302 r65305  
    274274
    275275    bool isArrayIndex;
    276     unsigned i = propertyName.toArrayIndex(&isArrayIndex);
     276    unsigned i = toArrayIndex(propertyName.ustring(), &isArrayIndex);
    277277    if (isArrayIndex)
    278278        return JSArray::getOwnPropertySlot(exec, i, slot);
     
    291291   
    292292    bool isArrayIndex;
    293     unsigned i = propertyName.toArrayIndex(&isArrayIndex);
     293    unsigned i = toArrayIndex(propertyName.ustring(), &isArrayIndex);
    294294    if (isArrayIndex) {
    295295        if (i >= storage->m_length)
     
    318318{
    319319    bool isArrayIndex;
    320     unsigned i = propertyName.toArrayIndex(&isArrayIndex);
     320    unsigned i = toArrayIndex(propertyName.ustring(), &isArrayIndex);
    321321    if (isArrayIndex) {
    322322        put(exec, i, value);
     
    476476{
    477477    bool isArrayIndex;
    478     unsigned i = propertyName.toArrayIndex(&isArrayIndex);
     478    unsigned i = toArrayIndex(propertyName.ustring(), &isArrayIndex);
    479479    if (isArrayIndex)
    480480        return deleteProperty(exec, i);
  • trunk/JavaScriptCore/runtime/JSArray.h

    r65302 r65305  
    262262        }
    263263    }
    264    
     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
    265275} // namespace JSC
    266276
  • trunk/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp

    r65302 r65305  
    5454{
    5555    UString str = exec->argument(0).toString(exec);
    56     CString cstr = str.UTF8String(true);
     56    CString cstr = str.utf8(true);
    5757    if (!cstr.data())
    5858        return throwError(exec, createURIError(exec, "String contained an illegal UTF-16 sequence."));
     
    266266    if (number >= mantissaOverflowLowerBound) {
    267267        if (radix == 10)
    268             number = WTF::strtod(s.substr(firstDigitPosition, p - firstDigitPosition).UTF8String().data(), 0);
     268            number = WTF::strtod(s.substr(firstDigitPosition, p - firstDigitPosition).utf8().data(), 0);
    269269        else if (radix == 2 || radix == 4 || radix == 8 || radix == 16 || radix == 32)
    270             number = parseIntOverflow(s.substr(firstDigitPosition, p - firstDigitPosition).UTF8String().data(), p - firstDigitPosition, radix);
     270            number = parseIntOverflow(s.substr(firstDigitPosition, p - firstDigitPosition).utf8().data(), p - firstDigitPosition, radix);
    271271    }
    272272
     
    454454EncodedJSValue JSC_HOST_CALL globalFuncJSCPrint(ExecState* exec)
    455455{
    456     CString string = exec->argument(0).toString(exec).UTF8String();
     456    CString string = exec->argument(0).toString(exec).utf8();
    457457    puts(string.data());
    458458    return JSValue::encode(jsUndefined());
  • trunk/JavaScriptCore/runtime/JSString.h

    r65302 r65305  
    192192        {
    193193            ASSERT(!m_value.isNull());
    194             Heap::heap(this)->reportExtraMemoryCost(value.cost());
     194            Heap::heap(this)->reportExtraMemoryCost(value.impl()->cost());
    195195        }
    196196
     
    309309            m_other.m_finalizerCallback = finalizer;
    310310            m_other.m_finalizerContext = context;
    311             Heap::heap(this)->reportExtraMemoryCost(value.cost());
     311            Heap::heap(this)->reportExtraMemoryCost(value.impl()->cost());
    312312        }
    313313
  • trunk/JavaScriptCore/runtime/UString.cpp

    r65302 r65305  
    258258    }
    259259
    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 
    271260    const UChar* data = this->characters();
    272261    const UChar* end = data + size;
     
    595584}
    596585
    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)
     586// Helper to write a three-byte UTF-8 code point to the buffer, caller must check room is available.
     587static 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
     595CString 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    // Only produced from strict conversion.
     617    if (result == sourceIllegal)
    608618        return CString();
    609619
    610     return CString(buffer.data(), p - buffer.data());
     620    // Check for an unconverted high surrogate.
     621    if (result == sourceExhausted) {
     622        if (strict)
     623            return CString();
     624        // This should be one unpaired high surrogate. Treat it the same
     625        // was as an unpaired high surrogate would have been handled in
     626        // the middle of a string with non-strict conversion - which is
     627        // to say, simply encode it to UTF-8.
     628        ASSERT((characters + 1) == (this->characters() + length));
     629        ASSERT((*characters >= 0xD800) && (*characters <= 0xDBFF));
     630        // There should be room left, since one UChar hasn't been converted.
     631        ASSERT((buffer + 3) <= (buffer + bufferVector.size()));
     632        putUTF8Triple(buffer, *characters);
     633    }
     634
     635    return CString(bufferVector.data(), buffer - bufferVector.data());
    611636}
    612637
  • trunk/JavaScriptCore/runtime/UString.h

    r65302 r65305  
    3939namespace JSC {
    4040
    41 using WTF::PlacementNewAdoptType;
    42 using WTF::PlacementNewAdopt;
    43 
    4441class UString {
    4542public:
     
    6461    UString(RefPtr<StringImpl> impl) : m_impl(impl) { }
    6562
     63    // Inline the destructor.
     64    ALWAYS_INLINE ~UString() { }
     65
    6666    void swap(UString& o) { m_impl.swap(o.m_impl); }
    6767
     
    6969    static UString adopt(Vector<UChar, inlineCapacity>& vector) { return StringImpl::adopt(vector); }
    7070
    71     static UString number(int);
    72     static UString number(long long);
    73     static UString number(unsigned);
    74     static UString number(long);
    75     static UString number(double);
    76 
    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;
     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(); }
    9075
    9176    unsigned length() const
     
    10388    }
    10489
     90    CString utf8(bool strict = false) const;
     91
    10592    UChar operator[](unsigned index) const
    10693    {
     
    11097    }
    11198
     99    static UString number(int);
     100    static UString number(unsigned);
     101    static UString number(long);
     102    static UString number(long long);
     103    static UString number(double);
     104
     105
     106
    112107    double toDouble(bool tolerateTrailingJunk, bool tolerateEmptyString) const;
    113108    double toDouble(bool tolerateTrailingJunk) const;
     
    117112    uint32_t toUInt32(bool* ok, bool tolerateEmptyString) const;
    118113    uint32_t toStrictUInt32(bool* ok = 0) const;
    119 
    120     unsigned toArrayIndex(bool* ok = 0) const;
    121114
    122115    static const unsigned NotFound = 0xFFFFFFFFu;
     
    128121    UString substr(unsigned pos = 0, unsigned len = 0xFFFFFFFF) const;
    129122
    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() { }
     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
    143127private:
    144128    RefPtr<StringImpl> m_impl;
     
    218202}
    219203
    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 
    230204// We'd rather not do shared substring append for small strings, since
    231205// this runs too much risk of a tiny initial string holding down a
  • trunk/JavaScriptCore/wtf/text/WTFString.cpp

    r65302 r65305  
    655655}
    656656
    657 CString String::utf8() const
     657CString String::utf8(bool strict) const
    658658{
    659659    unsigned length = this->length();
     
    673673
    674674    char* buffer = bufferVector.data();
    675     ConversionResult result = convertUTF16ToUTF8(&characters, characters + length, &buffer, buffer + bufferVector.size(), false);
    676     ASSERT(result != sourceIllegal); // Only produced from strict conversion.
     675    ConversionResult result = convertUTF16ToUTF8(&characters, characters + length, &buffer, buffer + bufferVector.size(), strict);
    677676    ASSERT(result != targetExhausted); // (length * 3) should be sufficient for any conversion
    678677
    679     // If a high surrogate is left unconverted, treat it the same was as an unpaired high surrogate
    680     // would have been handled in the middle of a string with non-strict conversion - which is to say,
    681     // simply encode it to UTF-8.
     678    // Only produced from strict conversion.
     679    if (result == sourceIllegal)
     680        return CString();
     681
     682    // Check for an unconverted high surrogate.
    682683    if (result == sourceExhausted) {
    683         // This should be one unpaired high surrogate.
     684        if (strict)
     685            return CString();
     686        // This should be one unpaired high surrogate. Treat it the same
     687        // was as an unpaired high surrogate would have been handled in
     688        // the middle of a string with non-strict conversion - which is
     689        // to say, simply encode it to UTF-8.
    684690        ASSERT((characters + 1) == (this->characters() + length));
    685691        ASSERT((*characters >= 0xD800) && (*characters <= 0xDBFF));
  • trunk/JavaScriptCore/wtf/text/WTFString.h

    r65302 r65305  
    9898    String(RefPtr<StringImpl> impl) : m_impl(impl) { }
    9999
     100    // Inline the destructor.
     101    ALWAYS_INLINE ~String() { }
     102
    100103    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(); }
    105104
    106105    static String adopt(StringBuffer& buffer) { return StringImpl::adopt(buffer); }
     
    108107    static String adopt(Vector<UChar, inlineCapacity>& vector) { return StringImpl::adopt(vector); }
    109108
    110 
    111     ALWAYS_INLINE unsigned length() const
     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
    112115    {
    113116        if (!m_impl)
     
    123126    }
    124127
    125     const UChar* charactersWithNullTermination();
    126    
     128    CString latin1() const;
     129    CString utf8(bool strict = false) const;
     130
    127131    UChar operator[](unsigned index) const
    128132    {
     
    131135        return m_impl->characters()[index];
    132136    }
     137
     138    static String number(short);
     139    static String number(unsigned short);
     140    static String number(int);
     141    static String number(unsigned);
     142    static String number(long);
     143    static String number(unsigned long);
     144    static String number(long long);
     145    static String number(unsigned long long);
     146    static String number(double);
     147
     148
     149
     150    const UChar* charactersWithNullTermination();
     151   
    133152    UChar32 characterStartingAt(unsigned) const; // Ditto.
    134153   
     
    191210    String foldCase() const;
    192211
    193     static String number(short);
    194     static String number(unsigned short);
    195     static String number(int);
    196     static String number(unsigned);
    197     static String number(long);
    198     static String number(unsigned long);
    199     static String number(long long);
    200     static String number(unsigned long long);
    201     static String number(double);
    202 
    203212#if !PLATFORM(QT)
    204213    static String format(const char *, ...) WTF_ATTRIBUTE_PRINTF(1, 2);
     
    241250    String threadsafeCopy() const;
    242251
    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 
    248252#if PLATFORM(CF)
    249253    String(CFStringRef);
     
    277281    Vector<char> ascii() const;
    278282
    279     CString latin1() const;
    280     CString utf8() const;
    281 
    282283    static String fromUTF8(const char*, size_t);
    283284    static String fromUTF8(const char*);
     
    290291
    291292    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(); }
    292297
    293298private:
Note: See TracChangeset for help on using the changeset viewer.