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):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.