Changeset 54789 in webkit


Ignore:
Timestamp:
Feb 15, 2010 1:03:45 PM (14 years ago)
Author:
barraclough@apple.com
Message:

Bug 34952 - String lengths in UString should be unsigned.
This matches WebCore::StringImpl, and better unifies behaviour throughout JSC.

Reviewed by Geoff Garen.

JavaScriptCore:

  • JavaScriptCore.exp:
  • bytecode/EvalCodeCache.h:
  • runtime/Identifier.cpp:

(JSC::Identifier::equal):

  • runtime/Identifier.h:
  • runtime/JSGlobalObjectFunctions.cpp:

(JSC::globalFuncEscape):

  • runtime/JSONObject.cpp:

(JSC::gap):
(JSC::Stringifier::indent):

  • runtime/NumberPrototype.cpp:

(JSC::numberProtoFuncToFixed):
(JSC::numberProtoFuncToPrecision):

  • runtime/RegExp.cpp:

(JSC::RegExp::match):

  • runtime/StringPrototype.cpp:

(JSC::substituteBackreferencesSlow):
(JSC::stringProtoFuncReplace):
(JSC::stringProtoFuncSplit):
(JSC::trimString):

  • runtime/UString.cpp:

(JSC::UString::UString):
(JSC::UString::from):
(JSC::UString::getCString):
(JSC::UString::ascii):
(JSC::UString::operator[]):
(JSC::UString::toStrictUInt32):
(JSC::UString::find):
(JSC::UString::rfind):
(JSC::UString::substr):
(JSC::operator<):
(JSC::operator>):
(JSC::compare):
(JSC::equal):
(JSC::UString::UTF8String):

  • runtime/UString.h:

(JSC::UString::size):
(JSC::operator==):

  • runtime/UStringImpl.cpp:

(JSC::UStringImpl::create):

  • runtime/UStringImpl.h:

(JSC::UStringImpl::create):
(JSC::UStringImpl::size):
(JSC::UStringImpl::computeHash):
(JSC::UStringImpl::UStringImpl):

WebCore:

  • bindings/js/JSDOMWindowCustom.cpp:

(WebCore::JSDOMWindow::atob):
(WebCore::JSDOMWindow::btoa):

Location:
trunk
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r54788 r54789  
     12010-02-15  Gavin Barraclough  <barraclough@apple.com>
     2
     3        Reviewed by Geoff Garen.
     4
     5        Bug 34952 - String lengths in UString should be unsigned.
     6        This matches WebCore::StringImpl, and better unifies behaviour throughout JSC.
     7
     8        * JavaScriptCore.exp:
     9        * bytecode/EvalCodeCache.h:
     10        * runtime/Identifier.cpp:
     11        (JSC::Identifier::equal):
     12        * runtime/Identifier.h:
     13        * runtime/JSGlobalObjectFunctions.cpp:
     14        (JSC::globalFuncEscape):
     15        * runtime/JSONObject.cpp:
     16        (JSC::gap):
     17        (JSC::Stringifier::indent):
     18        * runtime/NumberPrototype.cpp:
     19        (JSC::numberProtoFuncToFixed):
     20        (JSC::numberProtoFuncToPrecision):
     21        * runtime/RegExp.cpp:
     22        (JSC::RegExp::match):
     23        * runtime/StringPrototype.cpp:
     24        (JSC::substituteBackreferencesSlow):
     25        (JSC::stringProtoFuncReplace):
     26        (JSC::stringProtoFuncSplit):
     27        (JSC::trimString):
     28        * runtime/UString.cpp:
     29        (JSC::UString::UString):
     30        (JSC::UString::from):
     31        (JSC::UString::getCString):
     32        (JSC::UString::ascii):
     33        (JSC::UString::operator[]):
     34        (JSC::UString::toStrictUInt32):
     35        (JSC::UString::find):
     36        (JSC::UString::rfind):
     37        (JSC::UString::substr):
     38        (JSC::operator<):
     39        (JSC::operator>):
     40        (JSC::compare):
     41        (JSC::equal):
     42        (JSC::UString::UTF8String):
     43        * runtime/UString.h:
     44        (JSC::UString::size):
     45        (JSC::operator==):
     46        * runtime/UStringImpl.cpp:
     47        (JSC::UStringImpl::create):
     48        * runtime/UStringImpl.h:
     49        (JSC::UStringImpl::create):
     50        (JSC::UStringImpl::size):
     51        (JSC::UStringImpl::computeHash):
     52        (JSC::UStringImpl::UStringImpl):
     53
    1542010-02-15  Gavin Barraclough  <barraclough@apple.com>
    255
  • trunk/JavaScriptCore/JavaScriptCore.exp

    r54672 r54789  
    241241__ZN3JSC7UString9s_nullRepE
    242242__ZN3JSC7UStringC1EPKc
    243 __ZN3JSC7UStringC1EPKti
     243__ZN3JSC7UStringC1EPKtj
    244244__ZN3JSC8Debugger23recompileAllJSFunctionsEPNS_12JSGlobalDataE
    245245__ZN3JSC8Debugger6attachEPNS_14JSGlobalObjectE
     
    394394__ZNK3JSC7UString5asciiEv
    395395__ZNK3JSC7UString6is8BitEv
    396 __ZNK3JSC7UString6substrEii
     396__ZNK3JSC7UString6substrEjj
    397397__ZNK3JSC7UString8toUInt32EPb
    398398__ZNK3JSC7UString8toUInt32EPbb
  • trunk/JavaScriptCore/bytecode/CodeBlock.cpp

    r52028 r54789  
    5050{
    5151    UString result = str;
    52     int pos = 0;
    53     while ((pos = result.find('\"', pos)) >= 0) {
     52    unsigned pos = 0;
     53    while ((pos = result.find('\"', pos)) != UString::NotFound) {
    5454        result = makeString(result.substr(0, pos), "\"\\\"\"", result.substr(pos + 1));
    5555        pos += 4;
  • trunk/JavaScriptCore/bytecode/EvalCodeCache.h

    r48662 r54789  
    6666
    6767    private:
    68         static const int maxCacheableSourceLength = 256;
     68        static const unsigned maxCacheableSourceLength = 256;
    6969        static const int maxCacheEntries = 64;
    7070
  • trunk/JavaScriptCore/bytecompiler/NodesCodegen.cpp

    r52028 r54789  
    7777static void substitute(UString& string, const UString& substring)
    7878{
    79     int position = string.find("%s");
    80     ASSERT(position != -1);
     79    unsigned position = string.find("%s");
     80    ASSERT(position != UString::NotFound);
    8181    string = makeString(string.substr(0, position), substring, string.substr(position + 2));
    8282}
  • trunk/JavaScriptCore/runtime/Identifier.cpp

    r54510 r54789  
    8888}
    8989
    90 bool Identifier::equal(const UString::Rep* r, const UChar* s, int length)
     90bool Identifier::equal(const UString::Rep* r, const UChar* s, unsigned length)
    9191{
    9292    if (r->size() != length)
    9393        return false;
    9494    const UChar* d = r->data();
    95     for (int i = 0; i != length; ++i)
     95    for (unsigned i = 0; i != length; ++i)
    9696        if (d[i] != s[i])
    9797            return false;
  • trunk/JavaScriptCore/runtime/Identifier.h

    r52856 r54789  
    7777
    7878        static bool equal(const UString::Rep*, const char*);
    79         static bool equal(const UString::Rep*, const UChar*, int length);
     79        static bool equal(const UString::Rep*, const UChar*, unsigned length);
    8080        static bool equal(const UString::Rep* a, const UString::Rep* b) { return JSC::equal(a, b); }
    8181
  • trunk/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp

    r54571 r54789  
    382382    UString str = args.at(0).toString(exec);
    383383    const UChar* c = str.data();
    384     for (int k = 0; k < str.size(); k++, c++) {
     384    for (unsigned k = 0; k < str.size(); k++, c++) {
    385385        int u = c[0];
    386386        if (u > 255) {
  • trunk/JavaScriptCore/runtime/JSONObject.cpp

    r54571 r54789  
    136136static inline UString gap(ExecState* exec, JSValue space)
    137137{
    138     const int maxGapLength = 10;
     138    const unsigned maxGapLength = 10;
    139139    space = unwrapBoxedPrimitive(exec, space);
    140140
     
    457457{
    458458    // Use a single shared string, m_repeatedGap, so we don't keep allocating new ones as we indent and unindent.
    459     int newSize = m_indent.size() + m_gap.size();
     459    unsigned newSize = m_indent.size() + m_gap.size();
    460460    if (newSize > m_repeatedGap.size())
    461461        m_repeatedGap = makeString(m_repeatedGap, m_gap);
  • trunk/JavaScriptCore/runtime/NumberPrototype.cpp

    r54571 r54789  
    266266        m = z.build();
    267267        k = f + 1;
    268         ASSERT(k == m.size());
     268        ASSERT(k == static_cast<int>(m.size()));
    269269    }
    270270    int kMinusf = k - f;
    271271
    272     if (kMinusf < m.size())
     272    if (kMinusf < static_cast<int>(m.size()))
    273273        return jsString(exec, makeString(s, m.substr(0, kMinusf), ".", m.substr(kMinusf)));
    274274    return jsString(exec, makeString(s, m.substr(0, kMinusf)));
     
    445445        return jsString(exec, makeString(s, m));
    446446    if (e >= 0) {
    447         if (e + 1 < m.size())
     447        if (e + 1 < static_cast<int>(m.size()))
    448448            return jsString(exec, makeString(s, m.substr(0, e + 1), ".", m.substr(e + 1)));
    449449        return jsString(exec, makeString(s, m));
  • trunk/JavaScriptCore/runtime/RegExp.cpp

    r53032 r54789  
    7272    // NOTE: The global flag is handled on a case-by-case basis by functions like
    7373    // String::match and RegExpObject::match.
    74     if (flags.find('g') != -1)
     74    if (flags.find('g') != UString::NotFound)
    7575        m_flagBits |= Global;
    76     if (flags.find('i') != -1)
     76    if (flags.find('i') != UString::NotFound)
    7777        m_flagBits |= IgnoreCase;
    78     if (flags.find('m') != -1)
     78    if (flags.find('m') != UString::NotFound)
    7979        m_flagBits |= Multiline;
    8080
     
    118118        ovector->clear();
    119119
    120     if (startOffset > s.size() || s.isNull())
     120    if (static_cast<unsigned>(startOffset) > s.size() || s.isNull())
    121121        return -1;
    122122
  • trunk/JavaScriptCore/runtime/StringPrototype.cpp

    r54532 r54789  
    151151// ------------------------------ Functions --------------------------
    152152
    153 static NEVER_INLINE UString substituteBackreferencesSlow(const UString& replacement, const UString& source, const int* ovector, RegExp* reg, int i)
     153static NEVER_INLINE UString substituteBackreferencesSlow(const UString& replacement, const UString& source, const int* ovector, RegExp* reg, unsigned i)
    154154{
    155155    Vector<UChar> substitutedReplacement;
     
    207207        offset = i + 1;
    208208        substitutedReplacement.append(source.data() + backrefStart, backrefLength);
    209     } while ((i = replacement.find('$', i + 1)) != -1);
     209    } while ((i = replacement.find('$', i + 1)) != UString::NotFound);
    210210
    211211    if (replacement.size() - offset)
     
    218218static inline UString substituteBackreferences(const UString& replacement, const UString& source, const int* ovector, RegExp* reg)
    219219{
    220     int i = replacement.find('$', 0);
    221     if (UNLIKELY(i != -1))
     220    unsigned i = replacement.find('$', 0);
     221    if (UNLIKELY(i != UString::NotFound))
    222222        return substituteBackreferencesSlow(replacement, source, ovector, reg, i);
    223223    return replacement;
     
    330330
    331331        int lastIndex = 0;
    332         int startPosition = 0;
     332        unsigned startPosition = 0;
    333333
    334334        Vector<StringRange, 16> sourceRanges;
     
    433433            return sourceVal;
    434434
    435         if (lastIndex < source.size())
     435        if (static_cast<unsigned>(lastIndex) < source.size())
    436436            sourceRanges.append(StringRange(lastIndex, source.size() - lastIndex));
    437437
     
    442442
    443443    UString patternString = pattern.toString(exec);
    444     int matchPos = source.find(patternString);
    445 
    446     if (matchPos == -1)
     444    unsigned matchPos = source.find(patternString);
     445
     446    if (matchPos == UString::NotFound)
    447447        return sourceVal;
    448448
     
    542542    }
    543543
    544     return jsNumber(exec, s.find(u2, pos));
     544    unsigned result = s.find(u2, pos);
     545    if (result == UString::NotFound)
     546        return jsNumber(exec, -1);
     547    return jsNumber(exec, result);
    545548}
    546549
     
    564567        dpos = len;
    565568#endif
    566     return jsNumber(exec, s.rfind(u2, static_cast<int>(dpos)));
     569
     570    unsigned result = s.rfind(u2, static_cast<unsigned>(dpos));
     571    if (result == UString::NotFound)
     572        return jsNumber(exec, -1);
     573    return jsNumber(exec, result);
    567574}
    568575
     
    676683    JSArray* result = constructEmptyArray(exec);
    677684    unsigned i = 0;
    678     int p0 = 0;
     685    unsigned p0 = 0;
    679686    unsigned limit = a1.isUndefined() ? 0xFFFFFFFFU : a1.toUInt32(exec);
    680687    if (a0.inherits(&RegExpObject::info)) {
     
    684691            return result;
    685692        }
    686         int pos = 0;
     693        unsigned pos = 0;
    687694        while (i != limit && pos < s.size()) {
    688695            Vector<int, 32> ovector;
     
    692699            int mlen = ovector[1] - ovector[0];
    693700            pos = mpos + (mlen == 0 ? 1 : mlen);
    694             if (mpos != p0 || mlen) {
     701            if (static_cast<unsigned>(mpos) != p0 || mlen) {
    695702                result->put(exec, i++, jsSubstring(exec, s, p0, mpos - p0));
    696703                p0 = mpos + mlen;
     
    714721                result->put(exec, i++, jsSingleCharacterSubstring(exec, s, p0++));
    715722        } else {
    716             int pos;
    717             while (i != limit && (pos = s.find(u2, p0)) >= 0) {
     723            unsigned pos;
     724           
     725            while (i != limit && (pos = s.find(u2, p0)) != UString::NotFound) {
    718726                result->put(exec, i++, jsSubstring(exec, s, p0, pos - p0));
    719727                p0 = pos + u2.size();
     
    10231031{
    10241032    UString str = thisValue.toThisString(exec);
    1025     int left = 0;
     1033    unsigned left = 0;
    10261034    if (trimKind & TrimLeft) {
    10271035        while (left < str.size() && isTrimWhitespace(str[left]))
    10281036            left++;
    10291037    }
    1030     int right = str.size();
     1038    unsigned right = str.size();
    10311039    if (trimKind & TrimRight) {
    10321040        while (right > left && isTrimWhitespace(str[right - 1]))
  • trunk/JavaScriptCore/runtime/UString.cpp

    r54545 r54789  
    168168}
    169169
    170 UString::UString(const char* c, int length)
     170UString::UString(const char* c, unsigned length)
    171171    : m_rep(Rep::create(c, length))
    172172{
    173173}
    174174
    175 UString::UString(const UChar* c, int length)
     175UString::UString(const UChar* c, unsigned length)
    176176{
    177177    if (length == 0)
     
    207207    }
    208208
    209     return UString(p, static_cast<int>(end - p));
     209    return UString(p, static_cast<unsigned>(end - p));
    210210}
    211211
     
    240240    }
    241241
    242     return UString(p, static_cast<int>(end - p));
     242    return UString(p, static_cast<unsigned>(end - p));
    243243}
    244244
     
    258258    }
    259259
    260     return UString(p, static_cast<int>(end - p));
     260    return UString(p, static_cast<unsigned>(end - p));
    261261}
    262262
     
    287287    }
    288288
    289     return UString(p, static_cast<int>(end - p));
     289    return UString(p, end - p);
    290290}
    291291
     
    300300bool UString::getCString(CStringBuffer& buffer) const
    301301{
    302     int length = size();
    303     int neededSize = length + 1;
     302    unsigned length = size();
     303    unsigned neededSize = length + 1;
    304304    buffer.resize(neededSize);
    305305    char* buf = buffer.data();
     
    325325    static char* asciiBuffer = 0;
    326326
    327     int length = size();
    328     int neededSize = length + 1;
     327    unsigned length = size();
     328    unsigned neededSize = length + 1;
    329329    delete[] asciiBuffer;
    330330    asciiBuffer = new char[neededSize];
     
    356356}
    357357
    358 UChar UString::operator[](int pos) const
     358UChar UString::operator[](unsigned pos) const
    359359{
    360360    if (pos >= size())
     
    496496
    497497    // Empty string is not OK.
    498     int len = m_rep->size();
     498    unsigned len = m_rep->size();
    499499    if (len == 0)
    500500        return 0;
     
    540540}
    541541
    542 int UString::find(const UString& f, int pos) const
    543 {
    544     int fsz = f.size();
    545 
    546     if (pos < 0)
    547         pos = 0;
     542unsigned UString::find(const UString& f, unsigned pos) const
     543{
     544    unsigned fsz = f.size();
    548545
    549546    if (fsz == 1) {
     
    554551                return static_cast<int>(c - data());
    555552        }
    556         return -1;
    557     }
    558 
    559     int sz = size();
     553        return NotFound;
     554    }
     555
     556    unsigned sz = size();
    560557    if (sz < fsz)
    561         return -1;
     558        return NotFound;
    562559    if (fsz == 0)
    563560        return pos;
    564561    const UChar* end = data() + sz - fsz;
    565     int fsizeminusone = (fsz - 1) * sizeof(UChar);
     562    unsigned fsizeminusone = (fsz - 1) * sizeof(UChar);
    566563    const UChar* fdata = f.data();
    567564    unsigned short fchar = fdata[0];
     
    572569    }
    573570
    574     return -1;
    575 }
    576 
    577 int UString::find(UChar ch, int pos) const
    578 {
    579     if (pos < 0)
    580         pos = 0;
     571    return NotFound;
     572}
     573
     574unsigned UString::find(UChar ch, unsigned pos) const
     575{
    581576    const UChar* end = data() + size();
    582577    for (const UChar* c = data() + pos; c < end; c++) {
     
    585580    }
    586581
    587     return -1;
    588 }
    589 
    590 int UString::rfind(const UString& f, int pos) const
    591 {
    592     int sz = size();
    593     int fsz = f.size();
     582    return NotFound;
     583}
     584
     585unsigned UString::rfind(const UString& f, unsigned pos) const
     586{
     587    unsigned sz = size();
     588    unsigned fsz = f.size();
    594589    if (sz < fsz)
    595         return -1;
    596     if (pos < 0)
    597         pos = 0;
     590        return NotFound;
    598591    if (pos > sz - fsz)
    599592        pos = sz - fsz;
    600593    if (fsz == 0)
    601594        return pos;
    602     int fsizeminusone = (fsz - 1) * sizeof(UChar);
     595    unsigned fsizeminusone = (fsz - 1) * sizeof(UChar);
    603596    const UChar* fdata = f.data();
    604597    for (const UChar* c = data() + pos; c >= data(); c--) {
     
    607600    }
    608601
    609     return -1;
    610 }
    611 
    612 int UString::rfind(UChar ch, int pos) const
     602    return NotFound;
     603}
     604
     605unsigned UString::rfind(UChar ch, unsigned pos) const
    613606{
    614607    if (isEmpty())
    615         return -1;
     608        return NotFound;
    616609    if (pos + 1 >= size())
    617610        pos = size() - 1;
     
    621614    }
    622615
    623     return -1;
    624 }
    625 
    626 UString UString::substr(int pos, int len) const
    627 {
    628     int s = size();
    629 
    630     if (pos < 0)
    631         pos = 0;
    632     else if (pos >= s)
     616    return NotFound;
     617}
     618
     619UString UString::substr(unsigned pos, unsigned len) const
     620{
     621    unsigned s = size();
     622
     623    if (pos >= s)
    633624        pos = s;
    634     if (len < 0)
    635         len = s;
    636     if (pos + len >= s)
    637         len = s - pos;
     625    unsigned limit = s - pos;
     626    if (len > limit)
     627        len = limit;
    638628
    639629    if (pos == 0 && len == s)
     
    662652bool operator<(const UString& s1, const UString& s2)
    663653{
    664     const int l1 = s1.size();
    665     const int l2 = s2.size();
    666     const int lmin = l1 < l2 ? l1 : l2;
     654    const unsigned l1 = s1.size();
     655    const unsigned l2 = s2.size();
     656    const unsigned lmin = l1 < l2 ? l1 : l2;
    667657    const UChar* c1 = s1.data();
    668658    const UChar* c2 = s2.data();
    669     int l = 0;
     659    unsigned l = 0;
    670660    while (l < lmin && *c1 == *c2) {
    671661        c1++;
     
    681671bool operator>(const UString& s1, const UString& s2)
    682672{
    683     const int l1 = s1.size();
    684     const int l2 = s2.size();
    685     const int lmin = l1 < l2 ? l1 : l2;
     673    const unsigned l1 = s1.size();
     674    const unsigned l2 = s2.size();
     675    const unsigned lmin = l1 < l2 ? l1 : l2;
    686676    const UChar* c1 = s1.data();
    687677    const UChar* c2 = s2.data();
    688     int l = 0;
     678    unsigned l = 0;
    689679    while (l < lmin && *c1 == *c2) {
    690680        c1++;
     
    700690int compare(const UString& s1, const UString& s2)
    701691{
    702     const int l1 = s1.size();
    703     const int l2 = s2.size();
    704     const int lmin = l1 < l2 ? l1 : l2;
     692    const unsigned l1 = s1.size();
     693    const unsigned l2 = s2.size();
     694    const unsigned lmin = l1 < l2 ? l1 : l2;
    705695    const UChar* c1 = s1.data();
    706696    const UChar* c2 = s2.data();
    707     int l = 0;
     697    unsigned l = 0;
    708698    while (l < lmin && *c1 == *c2) {
    709699        c1++;
     
    723713bool equal(const UString::Rep* r, const UString::Rep* b)
    724714{
    725     int length = r->size();
     715    unsigned length = r->size();
    726716    if (length != b->size())
    727717        return false;
    728718    const UChar* d = r->data();
    729719    const UChar* s = b->data();
    730     for (int i = 0; i != length; ++i) {
     720    for (unsigned i = 0; i != length; ++i) {
    731721        if (d[i] != s[i])
    732722            return false;
     
    738728{
    739729    // Allocate a buffer big enough to hold all the characters.
    740     const int length = size();
     730    const unsigned length = size();
    741731    Vector<char, 1024> buffer(length * 3);
    742732
  • trunk/JavaScriptCore/runtime/UString.h

    r54788 r54789  
    8383        UString();
    8484        UString(const char*); // Constructor for null-terminated string.
    85         UString(const char*, int length);
    86         UString(const UChar*, int length);
     85        UString(const char*, unsigned length);
     86        UString(const UChar*, unsigned length);
    8787        UString(const Vector<UChar>& buffer);
    8888
     
    137137        bool is8Bit() const;
    138138
    139         int size() const { return m_rep->size(); }
    140 
    141         UChar operator[](int pos) const;
     139        unsigned size() const { return m_rep->size(); }
     140
     141        UChar operator[](unsigned pos) const;
    142142
    143143        double toDouble(bool tolerateTrailingJunk, bool tolerateEmptyString) const;
     
    151151        unsigned toArrayIndex(bool* ok = 0) const;
    152152
    153         int find(const UString& f, int pos = 0) const;
    154         int find(UChar, int pos = 0) const;
    155         int rfind(const UString& f, int pos) const;
    156         int rfind(UChar, int pos) const;
    157 
    158         UString substr(int pos = 0, int len = -1) const;
     153        static const unsigned NotFound = 0xFFFFFFFFu;
     154        unsigned find(const UString& f, unsigned pos = 0) const;
     155        unsigned find(UChar, unsigned pos = 0) const;
     156        unsigned rfind(const UString& f, unsigned pos) const;
     157        unsigned rfind(UChar, unsigned pos) const;
     158
     159        UString substr(unsigned pos = 0, unsigned len = 0xFFFFFFFF) const;
    159160
    160161        static const UString& null() { return *s_nullUString; }
     
    182183    ALWAYS_INLINE bool operator==(const UString& s1, const UString& s2)
    183184    {
    184         int size = s1.size();
     185        unsigned size = s1.size();
    185186        switch (size) {
    186187        case 0:
     
    246247    // this runs too much risk of a tiny initial string holding down a
    247248    // huge buffer.
    248     // FIXME: this should be size_t but that would cause warnings until we
    249     // fix UString sizes to be size_t instead of int
    250     static const int minShareSize = Heap::minExtraCost / sizeof(UChar);
     249    static const unsigned minShareSize = Heap::minExtraCost / sizeof(UChar);
    251250
    252251    struct IdentifierRepHash : PtrHash<RefPtr<JSC::UString::Rep> > {
  • trunk/JavaScriptCore/runtime/UStringImpl.cpp

    r54743 r54789  
    5151}
    5252
    53 PassRefPtr<UStringImpl> UStringImpl::create(const char* c, int length)
     53PassRefPtr<UStringImpl> UStringImpl::create(const char* c, unsigned length)
    5454{
    5555    ASSERT(c);
     
    6060    UChar* d;
    6161    PassRefPtr<UStringImpl> result = UStringImpl::createUninitialized(length, d);
    62     for (int i = 0; i < length; i++)
     62    for (unsigned i = 0; i < length; i++)
    6363        d[i] = static_cast<unsigned char>(c[i]); // use unsigned char to zero-extend instead of sign-extend
    6464    return result;
    6565}
    6666
    67 PassRefPtr<UStringImpl> UStringImpl::create(const UChar* buffer, int length)
     67PassRefPtr<UStringImpl> UStringImpl::create(const UChar* buffer, unsigned length)
    6868{
    6969    UChar* newBuffer;
  • trunk/JavaScriptCore/runtime/UStringImpl.h

    r54743 r54789  
    5454
    5555    static PassRefPtr<UStringImpl> create(const char* c);
    56     static PassRefPtr<UStringImpl> create(const char* c, int length);
    57     static PassRefPtr<UStringImpl> create(const UChar* buffer, int length);
    58 
    59     static PassRefPtr<UStringImpl> create(PassRefPtr<UStringImpl> rep, int offset, int length)
     56    static PassRefPtr<UStringImpl> create(const char* c, unsigned length);
     57    static PassRefPtr<UStringImpl> create(const UChar* buffer, unsigned length);
     58
     59    static PassRefPtr<UStringImpl> create(PassRefPtr<UStringImpl> rep, unsigned offset, unsigned length)
    6060    {
    6161        ASSERT(rep);
     
    6464    }
    6565
    66     static PassRefPtr<UStringImpl> create(PassRefPtr<SharedUChar> sharedBuffer, UChar* buffer, int length)
     66    static PassRefPtr<UStringImpl> create(PassRefPtr<SharedUChar> sharedBuffer, UChar* buffer, unsigned length)
    6767    {
    6868        return adoptRef(new UStringImpl(buffer, length, sharedBuffer));
     
    101101    SharedUChar* sharedBuffer();
    102102    UChar* data() const { return m_data; }
    103     int size() const { return m_length; }
     103    unsigned size() const { return m_length; }
    104104    size_t cost()
    105105    {
     
    137137    }
    138138
    139     static unsigned computeHash(const UChar* s, int length) { ASSERT(length >= 0); return WTF::stringHash(s, length); }
    140     static unsigned computeHash(const char* s, int length) { ASSERT(length >= 0); return WTF::stringHash(s, length); }
     139    static unsigned computeHash(const UChar* s, unsigned length) { return WTF::stringHash(s, length); }
     140    static unsigned computeHash(const char* s, unsigned length) { return WTF::stringHash(s, length); }
    141141    static unsigned computeHash(const char* s) { return WTF::stringHash(s); }
    142142
     
    163163
    164164    // Used to construct normal strings with an internal or external buffer.
    165     UStringImpl(UChar* data, int length, BufferOwnership ownership)
     165    UStringImpl(UChar* data, unsigned length, BufferOwnership ownership)
    166166        : m_data(data)
    167167        , m_buffer(0)
     
    178178    // static strings will be shared across threads & ref-counted in a non-threadsafe manner.
    179179    enum StaticStringConstructType { ConstructStaticString };
    180     UStringImpl(UChar* data, int length, StaticStringConstructType)
     180    UStringImpl(UChar* data, unsigned length, StaticStringConstructType)
    181181        : m_data(data)
    182182        , m_buffer(0)
     
    189189
    190190    // Used to create new strings that are a substring of an existing string.
    191     UStringImpl(UChar* data, int length, PassRefPtr<UStringImpl> base)
     191    UStringImpl(UChar* data, unsigned length, PassRefPtr<UStringImpl> base)
    192192        : m_data(data)
    193193        , m_bufferSubstring(base.releaseRef())
     
    205205
    206206    // Used to construct new strings sharing an existing shared buffer.
    207     UStringImpl(UChar* data, int length, PassRefPtr<SharedUChar> sharedBuffer)
     207    UStringImpl(UChar* data, unsigned length, PassRefPtr<SharedUChar> sharedBuffer)
    208208        : m_data(data)
    209209        , m_bufferShared(sharedBuffer.releaseRef())
     
    221221
    222222    // This number must be at least 2 to avoid sharing empty, null as well as 1 character strings from SmallStrings.
    223     static const int s_minLengthToShare = 10;
     223    static const unsigned s_minLengthToShare = 10;
    224224    static const unsigned s_copyCharsInlineCutOff = 20;
    225225    // We initialize and increment/decrement the refCount for all normal (non-static) strings by the value 2.
    226226    // We initialize static strings with an odd number (specifically, 1), such that the refCount cannot reach zero.
    227227    static const unsigned s_refCountMask = 0xFFFFFFF0;
    228     static const int s_refCountIncrement = 0x20;
    229     static const int s_refCountFlagStatic = 0x10;
     228    static const unsigned s_refCountIncrement = 0x20;
     229    static const unsigned s_refCountFlagStatic = 0x10;
    230230    static const unsigned s_refCountFlagHasReportedCost = 0x8;
    231231    static const unsigned s_refCountFlagIsIdentifier = 0x4;
     
    245245        SharedUChar* m_bufferShared;
    246246    };
    247     int m_length;
     247    unsigned m_length;
    248248    unsigned m_refCountAndFlags;
    249249    mutable unsigned m_hash;
  • trunk/WebCore/ChangeLog

    r54786 r54789  
     12010-02-15  Gavin Barraclough  <barraclough@apple.com>
     2
     3        Reviewed by Geoff Garen.
     4
     5        Bug 34952 - String lengths in UString should be unsigned.
     6        This matches WebCore::StringImpl, and better unifies behaviour throughout JSC.
     7
     8        * bindings/js/JSDOMWindowCustom.cpp:
     9        (WebCore::JSDOMWindow::atob):
     10        (WebCore::JSDOMWindow::btoa):
     11
    1122010-02-15  Gustavo Noronha Silva  <gustavo.noronha@collabora.co.uk>
    213
  • trunk/WebCore/bindings/js/JSDOMWindowCustom.cpp

    r54681 r54789  
    955955
    956956    Vector<char> in(s.size());
    957     for (int i = 0; i < s.size(); ++i)
     957    for (unsigned i = 0; i < s.size(); ++i)
    958958        in[i] = static_cast<char>(s.data()[i]);
    959959    Vector<char> out;
     
    981981
    982982    Vector<char> in(s.size());
    983     for (int i = 0; i < s.size(); ++i)
     983    for (unsigned i = 0; i < s.size(); ++i)
    984984        in[i] = static_cast<char>(s.data()[i]);
    985985    Vector<char> out;
Note: See TracChangeset for help on using the changeset viewer.