Ignore:
Timestamp:
Feb 6, 2010, 12:55:31 AM (15 years ago)
Author:
[email protected]
Message:

Change UStringImpl::create to CRASH if the string cannot be allocated,
rather than returning a null string (which will behave like a zero-length
string if used).

Reviewed by Geoff Garen.

Also move createRep function from UString to become new overloaded
UStringImpl::create methods. In doing so, bring their behaviour closer to
being in line with WebCore::StringImpl, in removing the behaviour that they
can be used to produce null UStrings (ASSERT the char* provided is non-null).
This behaviour of converting null C-strings to null UStrings is inefficient
(cmompared to just using UString::null()), incompatible with WebCore::StringImpl's
behaviour, and may generate unexpected behaviour, since in many cases a null
UString can be used like an empty string.

With these changes UStringImpl need not have a concept of null impls, we can
start transitioning this to become an implementation detail of UString, that
internally it chooses to use a null-object rather than an actually zero impl
pointer.

(JSC::Debugger::recompileAllJSFunctions):

  • debugger/DebuggerCallFrame.cpp:

(JSC::DebuggerCallFrame::calculatedFunctionName):

  • parser/Parser.cpp:

(JSC::Parser::parse):

  • profiler/Profile.cpp:

(JSC::Profile::Profile):

  • profiler/ProfileGenerator.cpp:

(JSC::ProfileGenerator::stopProfiling):

  • runtime/Error.cpp:

(JSC::Error::create):
(JSC::throwError):

  • runtime/ExceptionHelpers.cpp:

(JSC::createError):

  • runtime/Identifier.cpp:

(JSC::Identifier::add):

  • runtime/PropertyNameArray.cpp:

(JSC::PropertyNameArray::add):

  • runtime/UString.cpp:

(JSC::initializeUString):
(JSC::UString::UString):
(JSC::UString::operator=):

  • runtime/UString.h:

(JSC::UString::isNull):
(JSC::UString::null):
(JSC::UString::rep):
(JSC::UString::UString):

  • runtime/UStringImpl.cpp:

(JSC::UStringImpl::create):

  • runtime/UStringImpl.h:
File:
1 edited

Legend:

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

    r53444 r54464  
    158158        const UChar* data() const { return m_rep->data(); }
    159159
    160         bool isNull() const { return m_rep == &Rep::null(); }
     160        bool isNull() const { return m_rep == s_nullRep; }
    161161        bool isEmpty() const { return !m_rep->size(); }
    162162
     
    184184        UString substr(int pos = 0, int len = -1) const;
    185185
    186         static const UString& null() { return *nullUString; }
     186        static const UString& null() { return *s_nullUString; }
    187187
    188188        Rep* rep() const { return m_rep.get(); }
    189         static Rep* nullRep();
    190189
    191190        UString(PassRefPtr<Rep> r)
     
    198197
    199198    private:
    200         void makeNull();
    201 
    202199        RefPtr<Rep> m_rep;
    203         static UString* nullUString;
     200
     201        JS_EXPORTDATA static Rep* s_nullRep;
     202        static UString* s_nullUString;
    204203
    205204        friend void initializeUString();
     
    256255
    257256    inline UString::UString()
    258         : m_rep(&Rep::null())
     257        : m_rep(s_nullRep)
    259258    {
    260259    }
Note: See TracChangeset for help on using the changeset viewer.