Ignore:
Timestamp:
Feb 9, 2010, 3:55:39 AM (15 years ago)
Author:
[email protected]
Message:

Three small string fixes:
(1) StringBuilder::release should CRASH if the buffer allocation failed.
(2) Remove weird, dead code from JSString::tryGetValue, replace with an ASSERT.
(3) Move UString::createFromUTF8 out to the API, as tryCreateStringFromUTF8.

This is only used from the API, and (now) unlike other UString::create
methods may return UString::null() to indicate failure cases. Better
handle these in the API.

Reviewed by Oliver Hunt.

  • API/JSClassRef.cpp:

(tryCreateStringFromUTF8):
(OpaqueJSClass::OpaqueJSClass):
(OpaqueJSClassContextData::OpaqueJSClassContextData):

  • runtime/JSString.h:

(JSC::Fiber::tryGetValue):

  • runtime/StringBuilder.h:

(JSC::StringBuilder::release):

  • runtime/UString.cpp:

(JSC::UString::UString):
(JSC::UString::from):
(JSC::UString::find):

  • runtime/UString.h:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/UString.cpp

    r54531 r54545  
    5454
    5555namespace JSC {
    56  
     56
    5757extern const double NaN;
    5858extern const double Inf;
     
    147147}
    148148
    149 // These static strings are immutable, except for rc, whose initial value is chosen to 
     149// These static strings are immutable, except for rc, whose initial value is chosen to
    150150// reduce the possibility of it becoming zero due to ref/deref not being thread-safe.
    151151static UChar sharedEmptyChar;
     
    175175UString::UString(const UChar* c, int length)
    176176{
    177     if (length == 0) 
     177    if (length == 0)
    178178        m_rep = &Rep::empty();
    179179    else
     
    181181}
    182182
    183 UString UString::createFromUTF8(const char* string)
    184 {
    185     if (!string)
    186         return null();
    187 
    188     size_t length = strlen(string);
    189     Vector<UChar, 1024> buffer(length);
    190     UChar* p = buffer.data();
    191     if (conversionOK != convertUTF8ToUTF16(&string, string + length, &p, p + length))
    192         return null();
    193 
    194     return UString(buffer.data(), p - buffer.data());
    195 }
    196 
    197183UString UString::from(int i)
    198184{
     
    200186    UChar* end = buf + sizeof(buf) / sizeof(UChar);
    201187    UChar* p = end;
    202  
     188
    203189    if (i == 0)
    204190        *--p = '0';
     
    262248    UChar* end = buf + sizeof(buf) / sizeof(UChar);
    263249    UChar* p = end;
    264    
     250
    265251    if (u == 0)
    266252        *--p = '0';
     
    271257        }
    272258    }
    273    
     259
    274260    return UString(p, static_cast<int>(end - p));
    275261}
     
    598584            return static_cast<int>(c - data());
    599585    }
    600    
     586
    601587    return -1;
    602588}
Note: See TracChangeset for help on using the changeset viewer.