Ignore:
Timestamp:
Aug 7, 2007, 5:45:39 PM (18 years ago)
Author:
darin
Message:

Reviewed by Adele.

  • fix <rdar://problem/5383104> REGRESSION: XHR.responseText is null instead of empty string in http/tests/xmlhttprequest/zero-length-response.html

The new code to handle out of memory conditions was turning a "" into a null string.

  • kjs/ustring.h: Removed UCharReference, which has long been obsolete and unused. Removed copyForWriting, which was only used for the upper/lowercasing code and for UCharReference.
  • kjs/ustring.cpp: (KJS::allocChars): Removed special case that made this fail (return 0) when passed 0. Instead assert that we're not passed 0. Also added an overflow check for two reasons: 1) for sizes that aren't checked this prevents us from allocating a buffer that's too small, and 2) for sizes where we overflowed in the expandedSize function and returned overflowIndicator, it guarantees we fail. (KJS::reallocChars): Ditto. (KJS::UString::expandedSize): Return a large number, overflowIndicator, rather than 0 for cases where we overflow. (KJS::UString::spliceSubstringsWithSeparators): Added a special case for empty string so we don't call allocChars with a length of 0. (KJS::UString::operator=): Added special characters for both 0 and empty string so we match the behavior of the constructor. This avoids calling allocChars with a length of 0 and making a null string rather than an empty string in that case, and also matches the pattern used in the rest of the functions. (KJS::UString::operator[]): Made the return value const so code that tries to use the operator to modify the string will fail.
  • kjs/string_object.cpp: (KJS::StringProtoFunc::callAsFunction): Rewrote uppercasing and lowercasing functions so they don't need copyForWriting any more -- it wasn't really doing any good for optimization purposes. Instead use a Vector and releaseBuffer.
  • wtf/unicode/icu/UnicodeIcu.h: Eliminate one of the versions of toLower/toUpper -- we now only need the version where both a source and destination buffer is passed in, not the one that works in place.
  • wtf/unicode/qt4/UnicodeQt4.h: Ditto.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/string_object.cpp

    r24881 r24919  
    694694  case ToLowerCase:
    695695  case ToLocaleLowerCase: { // FIXME: See http://www.unicode.org/Public/UNIDATA/SpecialCasing.txt for locale-sensitive mappings that aren't implemented.
    696     u = s;
    697     u.copyForWriting();
    698     ::UChar* dataPtr = reinterpret_cast< ::UChar*>(u.rep()->data());
    699     ::UChar* destIfNeeded;
    700 
    701     int len = Unicode::toLower(dataPtr, u.size(), destIfNeeded);
    702     if (len >= 0)
    703         result = jsString(UString(reinterpret_cast<UChar*>(destIfNeeded ? destIfNeeded : dataPtr), len));
    704     else
    705         result = jsString(s);
    706 
    707     free(destIfNeeded);
    708     break;
     696    StringImp* sVal = thisObj->inherits(&StringInstance::info)
     697        ? static_cast<StringInstance*>(thisObj)->internalValue()
     698        : static_cast<StringImp*>(jsString(s));
     699    int ssize = s.size();
     700    if (!ssize)
     701        return sVal;
     702    Vector< ::UChar> buffer(ssize);
     703    bool error;
     704    int length = Unicode::toLower(buffer.data(), ssize, reinterpret_cast<const ::UChar*>(s.data()), ssize, &error);
     705    if (error) {
     706        buffer.resize(length);
     707        length = Unicode::toLower(buffer.data(), length, reinterpret_cast<const ::UChar*>(s.data()), ssize, &error);
     708        if (error)
     709            return sVal;
     710    }
     711    if (length == ssize && memcmp(buffer.data(), s.data(), length * sizeof(UChar)) == 0)
     712        return sVal;
     713    return jsString(UString(reinterpret_cast<UChar*>(buffer.releaseBuffer()), length, false));
    709714  }
    710715  case ToUpperCase:
    711716  case ToLocaleUpperCase: { // FIXME: See http://www.unicode.org/Public/UNIDATA/SpecialCasing.txt for locale-sensitive mappings that aren't implemented.
    712     u = s;
    713     u.copyForWriting();
    714     ::UChar* dataPtr = reinterpret_cast< ::UChar*>(u.rep()->data());
    715     ::UChar* destIfNeeded;
    716 
    717     int len = Unicode::toUpper(dataPtr, u.size(), destIfNeeded);
    718     if (len >= 0)
    719         result = jsString(UString(reinterpret_cast<UChar *>(destIfNeeded ? destIfNeeded : dataPtr), len));
    720     else
    721         result = jsString(s);
    722 
    723     free(destIfNeeded);
    724     break;
     717    StringImp* sVal = thisObj->inherits(&StringInstance::info)
     718        ? static_cast<StringInstance*>(thisObj)->internalValue()
     719        : static_cast<StringImp*>(jsString(s));
     720    int ssize = s.size();
     721    if (!ssize)
     722        return sVal;
     723    Vector< ::UChar> buffer(ssize);
     724    bool error;
     725    int length = Unicode::toUpper(buffer.data(), ssize, reinterpret_cast<const ::UChar*>(s.data()), ssize, &error);
     726    if (error) {
     727        buffer.resize(length);
     728        length = Unicode::toUpper(buffer.data(), length, reinterpret_cast<const ::UChar*>(s.data()), ssize, &error);
     729        if (error)
     730            return sVal;
     731    }
     732    if (length == ssize && memcmp(buffer.data(), s.data(), length * sizeof(UChar)) == 0)
     733        return sVal;
     734    return jsString(UString(reinterpret_cast<UChar*>(buffer.releaseBuffer()), length, false));
    725735  }
    726736  case LocaleCompare:
Note: See TracChangeset for help on using the changeset viewer.