Changeset 56021 in webkit


Ignore:
Timestamp:
Mar 15, 2010 3:59:45 PM (14 years ago)
Author:
barraclough@apple.com
Message:

https://bugs.webkit.org/show_bug.cgi?id=35843
Re-land reverted fix to JSString::getIndex()

Reviewed by Sam Weinig.

Calling getIndex() on a JSString in rope form may result in a JSException being thrown
if there is insuficient memory so value(exec) returns UString() with length zero,
which will be passed to jsSingleCharacterSubstring.
Add a slow case function to trap the error & return a safe null value, until the
exception is handled.

  • runtime/JSString.cpp:

(JSC::JSString::getIndexSlowCase):
(JSC::JSString::getStringPropertyDescriptor):

  • runtime/JSString.h:

(JSC::jsSingleCharacterSubstring):
(JSC::JSString::getIndex):
(JSC::jsSingleCharacterString):
(JSC::JSString::getStringPropertySlot):

Location:
trunk/JavaScriptCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r56015 r56021  
     12010-03-15  Gavin Barraclough  <barraclough@apple.com>
     2
     3        Reviewed by Sam Weinig.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=35843
     6        Re-land reverted fix to JSString::getIndex()
     7
     8        Calling getIndex() on a JSString in rope form may result in a JSException being thrown
     9        if there is insuficient memory so value(exec) returns UString() with length zero,
     10        which will be passed to jsSingleCharacterSubstring.
     11        Add a slow case function to trap the error & return a safe null value, until the
     12        exception is handled.
     13
     14        * runtime/JSString.cpp:
     15        (JSC::JSString::getIndexSlowCase):
     16        (JSC::JSString::getStringPropertyDescriptor):
     17        * runtime/JSString.h:
     18        (JSC::jsSingleCharacterSubstring):
     19        (JSC::JSString::getIndex):
     20        (JSC::jsSingleCharacterString):
     21        (JSC::JSString::getStringPropertySlot):
     22
    1232010-03-04  Kenneth Rohde Christiansen  <kenneth@webkit.org>
    224
  • trunk/JavaScriptCore/runtime/JSString.cpp

    r55833 r56021  
    105105}
    106106
     107JSString* JSString::getIndexSlowCase(ExecState* exec, unsigned i)
     108{
     109    ASSERT(isRope());
     110    resolveRope(exec);
     111    // Return a safe no-value result, this should never be used, since the excetion will be thrown.
     112    if (exec->exception())
     113        return jsString(exec, "");
     114    ASSERT(!isRope());
     115    ASSERT(i < m_value.size());
     116    return jsSingleCharacterSubstring(exec, m_value, i);
     117}
     118
    107119JSValue JSString::toPrimitive(ExecState*, PreferredPrimitiveType) const
    108120{
     
    188200    unsigned i = propertyName.toStrictUInt32(&isStrictUInt32);
    189201    if (isStrictUInt32 && i < m_length) {
    190         descriptor.setDescriptor(jsSingleCharacterSubstring(exec, value(exec), i), DontDelete | ReadOnly);
     202        descriptor.setDescriptor(getIndex(exec, i), DontDelete | ReadOnly);
    191203        return true;
    192204    }
  • trunk/JavaScriptCore/runtime/JSString.h

    r55679 r56021  
    4242    JSString* jsSingleCharacterString(JSGlobalData*, UChar);
    4343    JSString* jsSingleCharacterString(ExecState*, UChar);
    44     JSString* jsSingleCharacterSubstring(JSGlobalData*, const UString&, unsigned offset);
    4544    JSString* jsSingleCharacterSubstring(ExecState*, const UString&, unsigned offset);
    4645    JSString* jsSubstring(JSGlobalData*, const UString&, unsigned offset, unsigned length);
     
    241240        bool canGetIndex(unsigned i) { return i < m_length; }
    242241        JSString* getIndex(ExecState*, unsigned);
     242        JSString* getIndexSlowCase(ExecState*, unsigned);
    243243
    244244        static PassRefPtr<Structure> createStructure(JSValue proto) { return Structure::create(proto, TypeInfo(StringType, OverridesGetOwnPropertySlot | NeedsThisConversion), AnonymousSlotCount); }
     
    366366    }
    367367
    368     inline JSString* jsSingleCharacterSubstring(JSGlobalData* globalData, const UString& s, unsigned offset)
    369     {
     368    inline JSString* jsSingleCharacterSubstring(ExecState* exec, const UString& s, unsigned offset)
     369    {
     370        JSGlobalData* globalData = &exec->globalData();
    370371        ASSERT(offset < static_cast<unsigned>(s.size()));
    371372        UChar c = s.data()[offset];
     
    392393    {
    393394        ASSERT(canGetIndex(i));
    394         return jsSingleCharacterSubstring(&exec->globalData(), value(exec), i);
     395        if (isRope())
     396            return getIndexSlowCase(exec, i);
     397        ASSERT(i < m_value.size());
     398        return jsSingleCharacterSubstring(exec, value(exec), i);
    395399    }
    396400
     
    446450    inline JSString* jsString(ExecState* exec, const UString& s) { return jsString(&exec->globalData(), s); }
    447451    inline JSString* jsSingleCharacterString(ExecState* exec, UChar c) { return jsSingleCharacterString(&exec->globalData(), c); }
    448     inline JSString* jsSingleCharacterSubstring(ExecState* exec, const UString& s, unsigned offset) { return jsSingleCharacterSubstring(&exec->globalData(), s, offset); }
    449452    inline JSString* jsSubstring(ExecState* exec, const UString& s, unsigned offset, unsigned length) { return jsSubstring(&exec->globalData(), s, offset, length); }
    450453    inline JSString* jsNontrivialString(ExecState* exec, const UString& s) { return jsNontrivialString(&exec->globalData(), s); }
     
    462465        unsigned i = propertyName.toStrictUInt32(&isStrictUInt32);
    463466        if (isStrictUInt32 && i < m_length) {
    464             slot.setValue(jsSingleCharacterSubstring(exec, value(exec), i));
     467            slot.setValue(getIndex(exec, i));
    465468            return true;
    466469        }
     
    472475    {
    473476        if (propertyName < m_length) {
    474             slot.setValue(jsSingleCharacterSubstring(exec, value(exec), propertyName));
     477            slot.setValue(getIndex(exec, propertyName));
    475478            return true;
    476479        }
Note: See TracChangeset for help on using the changeset viewer.