Changeset 93378 in webkit


Ignore:
Timestamp:
Aug 18, 2011 5:58:34 PM (13 years ago)
Author:
commit-queue@webkit.org
Message:

Move allocation in constructors into separate constructorBody() methods
https://bugs.webkit.org/show_bug.cgi?id=66265

Patch by Mark Hahnenberg <mhahnenberg@apple.com> on 2011-08-18
Reviewed by Oliver Hunt.

Source/JavaScriptCore:

Refactoring to put all allocations that need to be done after the object's
initialization list has executed but before the object is ready for use
into a separate constructorBody() method. This method is still called by the constructor,
so the patch doesn't resolve any potential issues, it's just to set up the code for further refactoring.

(GlobalObject::constructorBody):
(GlobalObject::GlobalObject):

  • runtime/ErrorInstance.cpp:

(JSC::ErrorInstance::ErrorInstance):

  • runtime/ErrorInstance.h:

(JSC::ErrorInstance::constructorBody):

  • runtime/ErrorPrototype.cpp:

(JSC::ErrorPrototype::ErrorPrototype):
(JSC::ErrorPrototype::constructorBody):

  • runtime/ErrorPrototype.h:
  • runtime/Executable.cpp:

(JSC::FunctionExecutable::FunctionExecutable):

  • runtime/Executable.h:

(JSC::FunctionExecutable::constructorBody):

  • runtime/InternalFunction.cpp:

(JSC::InternalFunction::InternalFunction):

  • runtime/InternalFunction.h:

(JSC::InternalFunction::constructorBody):

  • runtime/JSByteArray.cpp:

(JSC::JSByteArray::JSByteArray):

  • runtime/JSByteArray.h:

(JSC::JSByteArray::constructorBody):

  • runtime/JSFunction.cpp:

(JSC::JSFunction::JSFunction):
(JSC::JSFunction::constructorBody):

  • runtime/JSFunction.h:
  • runtime/JSGlobalObject.h:

(JSC::JSGlobalObject::JSGlobalObject):
(JSC::JSGlobalObject::constructorBody):

  • runtime/JSPropertyNameIterator.cpp:

(JSC::JSPropertyNameIterator::JSPropertyNameIterator):

  • runtime/JSPropertyNameIterator.h:

(JSC::JSPropertyNameIterator::constructorBody):

  • runtime/JSString.h:

(JSC::RopeBuilder::JSString):
(JSC::RopeBuilder::constructorBody):

  • runtime/NativeErrorConstructor.cpp:

(JSC::NativeErrorConstructor::NativeErrorConstructor):

  • runtime/NativeErrorConstructor.h:

(JSC::NativeErrorConstructor::constructorBody):

  • runtime/NativeErrorPrototype.cpp:

(JSC::NativeErrorPrototype::NativeErrorPrototype):
(JSC::NativeErrorPrototype::constructorBody):

  • runtime/NativeErrorPrototype.h:
  • runtime/StringObject.cpp:
  • runtime/StringObject.h:

(JSC::StringObject::create):

  • runtime/StringObjectThatMasqueradesAsUndefined.h:

(JSC::StringObjectThatMasqueradesAsUndefined::create):
(JSC::StringObjectThatMasqueradesAsUndefined::StringObjectThatMasqueradesAsUndefined):

  • runtime/StringPrototype.cpp:

(JSC::StringPrototype::StringPrototype):

  • runtime/StringPrototype.h:

(JSC::StringPrototype::create):

Source/WebCore:

No new tests.

Refactoring to put all allocations that need to be done after the object's
initialization list has executed but before the object is ready for use
into a separate constructorBody() method. This method is still called by the constructor,
so the patch doesn't resolve any potential issues, it's just to set up the code for further refactoring.

  • bridge/objc/ObjCRuntimeObject.h:

(JSC::Bindings::ObjCRuntimeObject::create):

  • bridge/objc/ObjCRuntimeObject.mm:
  • bridge/objc/objc_instance.mm:

(ObjCRuntimeMethod::create):
(ObjCRuntimeMethod::ObjCRuntimeMethod):

  • bridge/runtime_array.cpp:
  • bridge/runtime_array.h:

(JSC::RuntimeArray::create):

Location:
trunk/Source
Files:
35 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r93375 r93378  
     12011-08-18  Mark Hahnenberg  <mhahnenberg@apple.com>
     2
     3        Move allocation in constructors into separate constructorBody() methods
     4        https://bugs.webkit.org/show_bug.cgi?id=66265
     5
     6        Reviewed by Oliver Hunt.
     7
     8        Refactoring to put all allocations that need to be done after the object's
     9        initialization list has executed but before the object is ready for use
     10        into a separate constructorBody() method.  This method is still called by the constructor,
     11        so the patch doesn't resolve any potential issues, it's just to set up the code for further refactoring.
     12
     13        * JavaScriptCore.exp:
     14        * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def:
     15        * jsc.cpp:
     16        (GlobalObject::constructorBody):
     17        (GlobalObject::GlobalObject):
     18        * runtime/ErrorInstance.cpp:
     19        (JSC::ErrorInstance::ErrorInstance):
     20        * runtime/ErrorInstance.h:
     21        (JSC::ErrorInstance::constructorBody):
     22        * runtime/ErrorPrototype.cpp:
     23        (JSC::ErrorPrototype::ErrorPrototype):
     24        (JSC::ErrorPrototype::constructorBody):
     25        * runtime/ErrorPrototype.h:
     26        * runtime/Executable.cpp:
     27        (JSC::FunctionExecutable::FunctionExecutable):
     28        * runtime/Executable.h:
     29        (JSC::FunctionExecutable::constructorBody):
     30        * runtime/InternalFunction.cpp:
     31        (JSC::InternalFunction::InternalFunction):
     32        * runtime/InternalFunction.h:
     33        (JSC::InternalFunction::constructorBody):
     34        * runtime/JSByteArray.cpp:
     35        (JSC::JSByteArray::JSByteArray):
     36        * runtime/JSByteArray.h:
     37        (JSC::JSByteArray::constructorBody):
     38        * runtime/JSFunction.cpp:
     39        (JSC::JSFunction::JSFunction):
     40        (JSC::JSFunction::constructorBody):
     41        * runtime/JSFunction.h:
     42        * runtime/JSGlobalObject.h:
     43        (JSC::JSGlobalObject::JSGlobalObject):
     44        (JSC::JSGlobalObject::constructorBody):
     45        * runtime/JSPropertyNameIterator.cpp:
     46        (JSC::JSPropertyNameIterator::JSPropertyNameIterator):
     47        * runtime/JSPropertyNameIterator.h:
     48        (JSC::JSPropertyNameIterator::constructorBody):
     49        * runtime/JSString.h:
     50        (JSC::RopeBuilder::JSString):
     51        (JSC::RopeBuilder::constructorBody):
     52        * runtime/NativeErrorConstructor.cpp:
     53        (JSC::NativeErrorConstructor::NativeErrorConstructor):
     54        * runtime/NativeErrorConstructor.h:
     55        (JSC::NativeErrorConstructor::constructorBody):
     56        * runtime/NativeErrorPrototype.cpp:
     57        (JSC::NativeErrorPrototype::NativeErrorPrototype):
     58        (JSC::NativeErrorPrototype::constructorBody):
     59        * runtime/NativeErrorPrototype.h:
     60        * runtime/StringObject.cpp:
     61        * runtime/StringObject.h:
     62        (JSC::StringObject::create):
     63        * runtime/StringObjectThatMasqueradesAsUndefined.h:
     64        (JSC::StringObjectThatMasqueradesAsUndefined::create):
     65        (JSC::StringObjectThatMasqueradesAsUndefined::StringObjectThatMasqueradesAsUndefined):
     66        * runtime/StringPrototype.cpp:
     67        (JSC::StringPrototype::StringPrototype):
     68        * runtime/StringPrototype.h:
     69        (JSC::StringPrototype::create):
     70
    1712011-08-10  Filip Pizlo  <fpizlo@apple.com>
    272
  • trunk/Source/JavaScriptCore/JavaScriptCore.exp

    r92224 r93378  
    152152__ZN3JSC12StringObject3putEPNS_9ExecStateERKNS_10IdentifierENS_7JSValueERNS_15PutPropertySlotE
    153153__ZN3JSC12StringObject6s_infoE
    154 __ZN3JSC12StringObjectC2EPNS_9ExecStateEPNS_9StructureERKNS_7UStringE
     154__ZN3JSC12StringObjectC2ERNS_12JSGlobalDataEPNS_9StructureEPNS_8JSStringE
    155155__ZN3JSC13SamplingFlags4stopEv
    156156__ZN3JSC13SamplingFlags5startEv
  • trunk/Source/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def

    r92230 r93378  
    2020    ??0RegExpObject@JSC@@IAE@PAVJSGlobalObject@1@PAVStructure@1@PAVRegExp@1@@Z
    2121    ??0SHA1@WTF@@QAE@XZ
    22     ??0StringObject@JSC@@IAE@PAVExecState@1@PAVStructure@1@ABVUString@1@@Z
     22    ??0StringObject@JSC@@IAE@AAVJSGlobalData@1@PAVStructure@1@PAVJSString@1@@Z
    2323    ??0Structure@JSC@@AAE@AAVJSGlobalData@1@VJSValue@1@ABVTypeInfo@1@IPBUClassInfo@1@@Z
    2424    ??0ThreadCondition@WTF@@QAE@XZ
  • trunk/Source/JavaScriptCore/jsc.cpp

    r92706 r93378  
    156156    }
    157157    virtual UString className() const { return "global"; }
     158
     159protected:
     160    void constructorBody(const Vector<UString>& arguments)
     161    {
     162        putDirectFunction(globalExec(), JSFunction::create(globalExec(), this, functionStructure(), 1, Identifier(globalExec(), "debug"), functionDebug));
     163        putDirectFunction(globalExec(), JSFunction::create(globalExec(), this, functionStructure(), 1, Identifier(globalExec(), "print"), functionPrint));
     164        putDirectFunction(globalExec(), JSFunction::create(globalExec(), this, functionStructure(), 0, Identifier(globalExec(), "quit"), functionQuit));
     165        putDirectFunction(globalExec(), JSFunction::create(globalExec(), this, functionStructure(), 0, Identifier(globalExec(), "gc"), functionGC));
     166#ifndef NDEBUG
     167        putDirectFunction(globalExec(), JSFunction::create(globalExec(), this, functionStructure(), 0, Identifier(globalExec(), "releaseExecutableMemory"), functionReleaseExecutableMemory));
     168#endif
     169        putDirectFunction(globalExec(), JSFunction::create(globalExec(), this, functionStructure(), 1, Identifier(globalExec(), "version"), functionVersion));
     170        putDirectFunction(globalExec(), JSFunction::create(globalExec(), this, functionStructure(), 1, Identifier(globalExec(), "run"), functionRun));
     171        putDirectFunction(globalExec(), JSFunction::create(globalExec(), this, functionStructure(), 1, Identifier(globalExec(), "load"), functionLoad));
     172        putDirectFunction(globalExec(), JSFunction::create(globalExec(), this, functionStructure(), 1, Identifier(globalExec(), "checkSyntax"), functionCheckSyntax));
     173        putDirectFunction(globalExec(), JSFunction::create(globalExec(), this, functionStructure(), 0, Identifier(globalExec(), "readline"), functionReadline));
     174        putDirectFunction(globalExec(), JSFunction::create(globalExec(), this, functionStructure(), 0, Identifier(globalExec(), "preciseTime"), functionPreciseTime));
     175
     176#if ENABLE(SAMPLING_FLAGS)
     177        putDirectFunction(globalExec(), JSFunction::create(globalExec(), this, functionStructure(), 1, Identifier(globalExec(), "setSamplingFlags"), functionSetSamplingFlags));
     178        putDirectFunction(globalExec(), JSFunction::create(globalExec(), this, functionStructure(), 1, Identifier(globalExec(), "clearSamplingFlags"), functionClearSamplingFlags));
     179#endif
     180
     181        JSObject* array = constructEmptyArray(globalExec());
     182        for (size_t i = 0; i < arguments.size(); ++i)
     183            array->put(globalExec(), i, jsString(globalExec(), arguments[i]));
     184        putDirect(globalExec()->globalData(), Identifier(globalExec(), "arguments"), array);
     185    }
    158186};
    159187COMPILE_ASSERT(!IsInteger<GlobalObject>::value, WTF_IsInteger_GlobalObject_false);
     
    163191    : JSGlobalObject(globalData, structure)
    164192{
    165     putDirectFunction(globalExec(), JSFunction::create(globalExec(), this, functionStructure(), 1, Identifier(globalExec(), "debug"), functionDebug));
    166     putDirectFunction(globalExec(), JSFunction::create(globalExec(), this, functionStructure(), 1, Identifier(globalExec(), "print"), functionPrint));
    167     putDirectFunction(globalExec(), JSFunction::create(globalExec(), this, functionStructure(), 0, Identifier(globalExec(), "quit"), functionQuit));
    168     putDirectFunction(globalExec(), JSFunction::create(globalExec(), this, functionStructure(), 0, Identifier(globalExec(), "gc"), functionGC));
    169 #ifndef NDEBUG
    170     putDirectFunction(globalExec(), JSFunction::create(globalExec(), this, functionStructure(), 0, Identifier(globalExec(), "releaseExecutableMemory"), functionReleaseExecutableMemory));
    171 #endif
    172     putDirectFunction(globalExec(), JSFunction::create(globalExec(), this, functionStructure(), 1, Identifier(globalExec(), "version"), functionVersion));
    173     putDirectFunction(globalExec(), JSFunction::create(globalExec(), this, functionStructure(), 1, Identifier(globalExec(), "run"), functionRun));
    174     putDirectFunction(globalExec(), JSFunction::create(globalExec(), this, functionStructure(), 1, Identifier(globalExec(), "load"), functionLoad));
    175     putDirectFunction(globalExec(), JSFunction::create(globalExec(), this, functionStructure(), 1, Identifier(globalExec(), "checkSyntax"), functionCheckSyntax));
    176     putDirectFunction(globalExec(), JSFunction::create(globalExec(), this, functionStructure(), 0, Identifier(globalExec(), "readline"), functionReadline));
    177     putDirectFunction(globalExec(), JSFunction::create(globalExec(), this, functionStructure(), 0, Identifier(globalExec(), "preciseTime"), functionPreciseTime));
    178 
    179 #if ENABLE(SAMPLING_FLAGS)
    180     putDirectFunction(globalExec(), JSFunction::create(globalExec(), this, functionStructure(), 1, Identifier(globalExec(), "setSamplingFlags"), functionSetSamplingFlags));
    181     putDirectFunction(globalExec(), JSFunction::create(globalExec(), this, functionStructure(), 1, Identifier(globalExec(), "clearSamplingFlags"), functionClearSamplingFlags));
    182 #endif
    183 
    184     JSObject* array = constructEmptyArray(globalExec());
    185     for (size_t i = 0; i < arguments.size(); ++i)
    186         array->put(globalExec(), i, jsString(globalExec(), arguments[i]));
    187     putDirect(globalExec()->globalData(), Identifier(globalExec(), "arguments"), array);
     193    constructorBody(arguments);
    188194}
    189195
  • trunk/Source/JavaScriptCore/runtime/ErrorInstance.cpp

    r91194 r93378  
    3030    , m_appendSourceToMessage(false)
    3131{
    32     ASSERT(inherits(&s_info));
    33     putDirect(globalData, globalData.propertyNames->message, jsString(&globalData, ""), DontEnum);
     32    constructorBody(globalData);
    3433}
    3534
  • trunk/Source/JavaScriptCore/runtime/ErrorInstance.h

    r92706 r93378  
    5151        explicit ErrorInstance(JSGlobalData&, Structure*, const UString&);
    5252
     53        void constructorBody(JSGlobalData& globalData)
     54        {
     55            ASSERT(inherits(&s_info));
     56            putDirect(globalData, globalData.propertyNames->message, jsString(&globalData, ""), DontEnum);
     57        }
     58
    5359        bool m_appendSourceToMessage;
    5460    };
  • trunk/Source/JavaScriptCore/runtime/ErrorPrototype.cpp

    r91194 r93378  
    5454    : ErrorInstance(exec->globalData(), structure)
    5555{
     56    constructorBody(exec, globalObject);
     57}
     58
     59void ErrorPrototype::constructorBody(ExecState* exec, JSGlobalObject* globalObject)
     60{
     61    ASSERT(inherits(&s_info));
    5662    putDirect(exec->globalData(), exec->propertyNames().name, jsNontrivialString(exec, "Error"), DontEnum);
    57 
    58     ASSERT(inherits(&s_info));
    5963    putAnonymousValue(globalObject->globalData(), 0, globalObject);
    6064}
  • trunk/Source/JavaScriptCore/runtime/ErrorPrototype.h

    r92706 r93378  
    4646    protected:
    4747        ErrorPrototype(ExecState*, JSGlobalObject*, Structure*);
     48        void constructorBody(ExecState*, JSGlobalObject*);
     49
    4850        static const unsigned StructureFlags = OverridesGetOwnPropertySlot | ErrorInstance::StructureFlags;
    4951        static const unsigned AnonymousSlotCount = ErrorInstance::AnonymousSlotCount + 1;
  • trunk/Source/JavaScriptCore/runtime/Executable.cpp

    r92250 r93378  
    143143    , m_symbolTable(0)
    144144{
    145     m_firstLine = firstLine;
    146     m_lastLine = lastLine;
    147     m_nameValue.set(globalData, this, jsString(&globalData, name.ustring()));
     145    constructorBody(globalData, name, firstLine, lastLine);
    148146}
    149147
     
    158156    m_firstLine = firstLine;
    159157    m_lastLine = lastLine;
    160     m_nameValue.set(exec->globalData(), this, jsString(&exec->globalData(), name.ustring()));
     158    constructorBody(exec->globalData(), name, firstLine, lastLine);
    161159}
    162160
  • trunk/Source/JavaScriptCore/runtime/Executable.h

    r92706 r93378  
    505505        static const ClassInfo s_info;
    506506
     507    protected:
     508        void constructorBody(JSGlobalData& globalData, const Identifier& name, int firstLine, int lastLine)
     509        {
     510            m_firstLine = firstLine;
     511            m_lastLine = lastLine;
     512            m_nameValue.set(globalData, this, jsString(&globalData, name.ustring()));
     513        }
     514
    507515    private:
    508516        FunctionExecutable(JSGlobalData&, const Identifier& name, const SourceCode&, bool forceUsesArguments, FunctionParameters*, bool, int firstLine, int lastLine);
  • trunk/Source/JavaScriptCore/runtime/InternalFunction.cpp

    r84052 r93378  
    4545    : JSObjectWithGlobalObject(globalObject, structure)
    4646{
    47     ASSERT(inherits(&s_info));
    48     putDirect(*globalData, globalData->propertyNames->name, jsString(globalData, name.isNull() ? "" : name.ustring()), DontDelete | ReadOnly | DontEnum);
     47    constructorBody(*globalData, name);
    4948}
    5049
  • trunk/Source/JavaScriptCore/runtime/InternalFunction.h

    r92706 r93378  
    5555        InternalFunction(JSGlobalData*, JSGlobalObject*, Structure*, const Identifier&);
    5656
     57        void constructorBody(JSGlobalData& globalData, const Identifier& name)
     58        {
     59            ASSERT(inherits(&s_info));
     60            putDirect(globalData, globalData.propertyNames->name, jsString(&globalData, name.isNull() ? "" : name.ustring()), DontDelete | ReadOnly | DontEnum);
     61        }
     62
    5763    private:
    5864        virtual CallType getCallData(CallData&) = 0;
  • trunk/Source/JavaScriptCore/runtime/JSByteArray.cpp

    r91790 r93378  
    4040    , m_storage(storage)
    4141{
    42     putDirect(exec->globalData(), exec->globalData().propertyNames->length, jsNumber(m_storage->length()), ReadOnly | DontDelete);
     42    constructorBody(exec);
    4343}
    4444       
  • trunk/Source/JavaScriptCore/runtime/JSByteArray.h

    r91790 r93378  
    105105        static const unsigned StructureFlags = OverridesGetOwnPropertySlot | OverridesGetPropertyNames | JSObject::StructureFlags;
    106106
     107        void constructorBody(ExecState* exec)
     108        {
     109            putDirect(exec->globalData(), exec->globalData().propertyNames->length, jsNumber(m_storage->length()), ReadOnly | DontDelete);
     110        }
     111
    107112    private:
    108113        JSByteArray(VPtrStealingHackType)
  • trunk/Source/JavaScriptCore/runtime/JSFunction.cpp

    r92250 r93378  
    6464JSFunction::JSFunction(ExecState* exec, JSGlobalObject* globalObject, Structure* structure, int length, const Identifier& name, NativeExecutable* thunk)
    6565    : Base(globalObject, structure)
    66     , m_executable(exec->globalData(), this, thunk)
     66    , m_executable()
    6767    , m_scopeChain(exec->globalData(), this, globalObject->globalScopeChain())
    6868{
    69     ASSERT(inherits(&s_info));
    70     putDirect(exec->globalData(), exec->globalData().propertyNames->name, jsString(exec, name.isNull() ? "" : name.ustring()), DontDelete | ReadOnly | DontEnum);
    71     putDirect(exec->globalData(), exec->propertyNames().length, jsNumber(length), DontDelete | ReadOnly | DontEnum);
     69    constructorBody(exec, length, name, thunk);
    7270}
    7371
    7472JSFunction::JSFunction(ExecState* exec, JSGlobalObject* globalObject, Structure* structure, int length, const Identifier& name, NativeFunction func)
    7573    : Base(globalObject, structure)
     74    , m_executable()
    7675    , m_scopeChain(exec->globalData(), this, globalObject->globalScopeChain())
    7776{
    78     ASSERT(inherits(&s_info));
    79    
    8077    // Can't do this during initialization because getHostFunction might do a GC allocation.
    81     m_executable.set(exec->globalData(), this, exec->globalData().getHostFunction(func));
    82    
    83     putDirect(exec->globalData(), exec->globalData().propertyNames->name, jsString(exec, name.isNull() ? "" : name.ustring()), DontDelete | ReadOnly | DontEnum);
    84     putDirect(exec->globalData(), exec->propertyNames().length, jsNumber(length), DontDelete | ReadOnly | DontEnum);
     78    constructorBody(exec, length, name,  exec->globalData().getHostFunction(func));
    8579}
    8680
     
    9387    setStructure(exec->globalData(), scopeChainNode->globalObject->namedFunctionStructure());
    9488    putDirectOffset(exec->globalData(), scopeChainNode->globalObject->functionNameOffset(), executable->nameValue());
     89}
     90
     91inline void JSFunction::constructorBody(ExecState* exec, int length, const Identifier& name, ExecutableBase* executable)
     92{
     93    ASSERT(inherits(&s_info));
     94    m_executable.set(exec->globalData(), this, executable);
     95    putDirect(exec->globalData(), exec->globalData().propertyNames->name, jsString(exec, name.isNull() ? "" : name.ustring()), DontDelete | ReadOnly | DontEnum);
     96    putDirect(exec->globalData(), exec->propertyNames().length, jsNumber(length), DontDelete | ReadOnly | DontEnum);
    9597}
    9698
  • trunk/Source/JavaScriptCore/runtime/JSFunction.h

    r92706 r93378  
    124124        const static unsigned StructureFlags = OverridesGetOwnPropertySlot | ImplementsHasInstance | OverridesVisitChildren | OverridesGetPropertyNames | JSObject::StructureFlags;
    125125
     126        void constructorBody(ExecState*, int length, const Identifier& name, ExecutableBase*);
     127
    126128    private:
    127129        explicit JSFunction(VPtrStealingHackType);
  • trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h

    r92706 r93378  
    160160            , m_evalEnabled(true)
    161161        {
    162             COMPILE_ASSERT(JSGlobalObject::AnonymousSlotCount == 1, JSGlobalObject_has_only_a_single_slot);
    163             putThisToAnonymousValue(0);
    164             init(this);
     162            constructorBody(this);
    165163        }
    166164
     
    171169            , m_weakRandom(static_cast<unsigned>(randomNumber() * (std::numeric_limits<unsigned>::max() + 1.0)))
    172170            , m_evalEnabled(true)
     171        {
     172            constructorBody(thisValue);
     173        }
     174
     175        void constructorBody(JSObject* thisValue)
    173176        {
    174177            COMPILE_ASSERT(JSGlobalObject::AnonymousSlotCount == 1, JSGlobalObject_has_only_a_single_slot);
  • trunk/Source/JavaScriptCore/runtime/JSPropertyNameIterator.cpp

    r91194 r93378  
    4444    , m_jsStrings(adoptArrayPtr(new WriteBarrier<Unknown>[m_jsStringsSize]))
    4545{
    46     PropertyNameArrayData::PropertyNameVector& propertyNameVector = propertyNameArrayData->propertyNameVector();
    47     for (size_t i = 0; i < m_jsStringsSize; ++i)
    48         m_jsStrings[i].set(exec->globalData(), this, jsOwnedString(exec, propertyNameVector[i].ustring()));
     46    constructorBody(exec, propertyNameArrayData);
    4947}
    5048
  • trunk/Source/JavaScriptCore/runtime/JSPropertyNameIterator.h

    r92706 r93378  
    8585        static const ClassInfo s_info;
    8686
     87    protected:
     88        void constructorBody(ExecState* exec, PropertyNameArrayData* propertyNameArrayData)
     89        {
     90            PropertyNameArrayData::PropertyNameVector& propertyNameVector = propertyNameArrayData->propertyNameVector();
     91            for (size_t i = 0; i < m_jsStringsSize; ++i)
     92                m_jsStrings[i].set(exec->globalData(), this, jsOwnedString(exec, propertyNameVector[i].ustring()));
     93        }
     94
    8795    private:
    8896        JSPropertyNameIterator(ExecState*, PropertyNameArrayData* propertyNameArrayData, size_t numCacheableSlot);
  • trunk/Source/JavaScriptCore/runtime/JSString.h

    r92706 r93378  
    268268            , m_fiberCount(s_maxInternalRopeLength)
    269269        {
     270            constructorBody(exec, v1, v2, v3);
     271        }
     272
     273        // This constructor constructs a new string by concatenating u1 & u2.
     274        JSString(JSGlobalData& globalData, const UString& u1, const UString& u2)
     275            : JSCell(globalData, globalData.stringStructure.get())
     276            , m_length(u1.length() + u2.length())
     277            , m_fiberCount(2)
     278        {
     279            unsigned index = 0;
     280            appendStringInConstruct(index, u1);
     281            appendStringInConstruct(index, u2);
     282            ASSERT(index <= s_maxInternalRopeLength);
     283        }
     284
     285        // This constructor constructs a new string by concatenating u1, u2 & u3.
     286        JSString(JSGlobalData& globalData, const UString& u1, const UString& u2, const UString& u3)
     287            : JSCell(globalData, globalData.stringStructure.get())
     288            , m_length(u1.length() + u2.length() + u3.length())
     289            , m_fiberCount(s_maxInternalRopeLength)
     290        {
     291            unsigned index = 0;
     292            appendStringInConstruct(index, u1);
     293            appendStringInConstruct(index, u2);
     294            appendStringInConstruct(index, u3);
     295            ASSERT(index <= s_maxInternalRopeLength);
     296        }
     297
     298    protected:
     299        void constructorBody(ExecState* exec, JSValue v1, JSValue v2, JSValue v3)
     300        {
    270301            unsigned index = 0;
    271302            appendValueInConstructAndIncrementLength(exec, index, v1);
     
    273304            appendValueInConstructAndIncrementLength(exec, index, v3);
    274305            ASSERT(index == s_maxInternalRopeLength);
    275         }
    276 
    277         // This constructor constructs a new string by concatenating u1 & u2.
    278         JSString(JSGlobalData& globalData, const UString& u1, const UString& u2)
    279             : JSCell(globalData, globalData.stringStructure.get())
    280             , m_length(u1.length() + u2.length())
    281             , m_fiberCount(2)
    282         {
    283             unsigned index = 0;
    284             appendStringInConstruct(index, u1);
    285             appendStringInConstruct(index, u2);
    286             ASSERT(index <= s_maxInternalRopeLength);
    287         }
    288 
    289         // This constructor constructs a new string by concatenating u1, u2 & u3.
    290         JSString(JSGlobalData& globalData, const UString& u1, const UString& u2, const UString& u3)
    291             : JSCell(globalData, globalData.stringStructure.get())
    292             , m_length(u1.length() + u2.length() + u3.length())
    293             , m_fiberCount(s_maxInternalRopeLength)
    294         {
    295             unsigned index = 0;
    296             appendStringInConstruct(index, u1);
    297             appendStringInConstruct(index, u2);
    298             appendStringInConstruct(index, u3);
    299             ASSERT(index <= s_maxInternalRopeLength);
    300306        }
    301307
  • trunk/Source/JavaScriptCore/runtime/NativeErrorConstructor.cpp

    r91194 r93378  
    3636    : InternalFunction(&exec->globalData(), globalObject, structure, Identifier(exec, nameAndMessage))
    3737{
    38     ASSERT(inherits(&s_info));
    39 
    40     NativeErrorPrototype* prototype = NativeErrorPrototype::create(exec, globalObject, prototypeStructure, nameAndMessage, this);
    41 
    42     putDirect(exec->globalData(), exec->propertyNames().length, jsNumber(1), DontDelete | ReadOnly | DontEnum); // ECMA 15.11.7.5
    43     putDirect(exec->globalData(), exec->propertyNames().prototype, prototype, DontDelete | ReadOnly | DontEnum);
    44     m_errorStructure.set(exec->globalData(), this, ErrorInstance::createStructure(exec->globalData(), prototype));
    45     ASSERT(m_errorStructure);
    46     ASSERT(m_errorStructure->typeInfo().type() == ObjectType);
     38    constructorBody(exec, globalObject, prototypeStructure, nameAndMessage);
    4739}
    4840
  • trunk/Source/JavaScriptCore/runtime/NativeErrorConstructor.h

    r92706 r93378  
    2323
    2424#include "InternalFunction.h"
     25#include "NativeErrorPrototype.h"
    2526
    2627namespace JSC {
     
    4849        Structure* errorStructure() { return m_errorStructure.get(); }
    4950
     51    protected:
     52        void constructorBody(ExecState* exec, JSGlobalObject* globalObject, Structure* prototypeStructure, const UString& nameAndMessage)
     53        {
     54            ASSERT(inherits(&s_info));
     55
     56            NativeErrorPrototype* prototype = NativeErrorPrototype::create(exec, globalObject, prototypeStructure, nameAndMessage, this);
     57
     58            putDirect(exec->globalData(), exec->propertyNames().length, jsNumber(1), DontDelete | ReadOnly | DontEnum); // ECMA 15.11.7.5
     59            putDirect(exec->globalData(), exec->propertyNames().prototype, prototype, DontDelete | ReadOnly | DontEnum);
     60            m_errorStructure.set(exec->globalData(), this, ErrorInstance::createStructure(exec->globalData(), prototype));
     61            ASSERT(m_errorStructure);
     62            ASSERT(m_errorStructure->typeInfo().type() == ObjectType);
     63        }
     64
    5065    private:
    5166        NativeErrorConstructor(ExecState*, JSGlobalObject*, Structure*, Structure* prototypeStructure, const UString&);
  • trunk/Source/JavaScriptCore/runtime/NativeErrorPrototype.cpp

    r91116 r93378  
    3434    : ErrorPrototype(exec, globalObject, structure)
    3535{
     36    constructorBody(exec, nameAndMessage, constructor);
     37}
     38
     39inline void NativeErrorPrototype::constructorBody(ExecState* exec, const UString& nameAndMessage, NativeErrorConstructor* constructor)
     40{
    3641    putDirect(exec->globalData(), exec->propertyNames().name, jsString(exec, nameAndMessage), DontEnum);
    3742    putDirect(exec->globalData(), exec->propertyNames().message, jsString(exec, nameAndMessage), DontEnum);
  • trunk/Source/JavaScriptCore/runtime/NativeErrorPrototype.h

    r92706 r93378  
    3838            return new (allocateCell<NativeErrorPrototype>(*exec->heap())) NativeErrorPrototype(exec, globalObject, structure, nameAndMessage, constructor);
    3939        }
     40
     41    protected:
     42        void constructorBody(ExecState*, const UString& nameAndMessage, NativeErrorConstructor*);
    4043    };
    4144
  • trunk/Source/JavaScriptCore/runtime/StringObject.cpp

    r84052 r93378  
    3030const ClassInfo StringObject::s_info = { "String", &JSWrapperObject::s_info, 0, 0 };
    3131
    32 StringObject::StringObject(ExecState* exec, Structure* structure)
    33     : JSWrapperObject(exec->globalData(), structure)
    34 {
    35     ASSERT(inherits(&s_info));
    36     setInternalValue(exec->globalData(), jsEmptyString(exec));
    37 }
    38 
    3932StringObject::StringObject(JSGlobalData& globalData, Structure* structure, JSString* string)
    4033    : JSWrapperObject(globalData, structure)
     
    4235    ASSERT(inherits(&s_info));
    4336    setInternalValue(globalData, string);
    44 }
    45 
    46 StringObject::StringObject(ExecState* exec, Structure* structure, const UString& string)
    47     : JSWrapperObject(exec->globalData(), structure)
    48 {
    49     ASSERT(inherits(&s_info));
    50     setInternalValue(exec->globalData(), jsString(exec, string));
    5137}
    5238
  • trunk/Source/JavaScriptCore/runtime/StringObject.h

    r92706 r93378  
    3333        static StringObject* create(ExecState* exec, Structure* structure)
    3434        {
    35             return new (allocateCell<StringObject>(*exec->heap())) StringObject(exec, structure); 
     35            JSString* string = jsEmptyString(exec);
     36            return new (allocateCell<StringObject>(*exec->heap())) StringObject(exec->globalData(), structure, string); 
    3637        }
    3738        static StringObject* create(ExecState* exec, Structure* structure, const UString& str)
    3839        {
    39             return new (allocateCell<StringObject>(*exec->heap())) StringObject(exec, structure, str); 
     40            JSString* string = jsString(exec, str);
     41            return new (allocateCell<StringObject>(*exec->heap())) StringObject(exec->globalData(), structure, string);
    4042        }
    4143        static StringObject* create(ExecState*, JSGlobalObject*, JSString*);
    42        
    4344
    4445        virtual bool getOwnPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);
     
    6061
    6162    protected:
    62         StringObject(ExecState*, Structure*);
    63         StringObject(ExecState*, Structure*, const UString&);
    6463        static const unsigned StructureFlags = OverridesGetOwnPropertySlot | OverridesGetPropertyNames | JSWrapperObject::StructureFlags;
    6564        StringObject(JSGlobalData&, Structure*, JSString*);
  • trunk/Source/JavaScriptCore/runtime/StringObjectThatMasqueradesAsUndefined.h

    r92706 r93378  
    3535        static StringObjectThatMasqueradesAsUndefined* create(ExecState* exec, const UString& string)
    3636        {
     37            JSString* newString = jsString(exec, string);
    3738            return new (allocateCell<StringObjectThatMasqueradesAsUndefined>(*exec->heap())) StringObjectThatMasqueradesAsUndefined(exec,
    38                 createStructure(exec->globalData(), exec->lexicalGlobalObject()->stringPrototype()), string);
     39                createStructure(exec->globalData(), exec->lexicalGlobalObject()->stringPrototype()), newString);
    3940        }
    4041
    4142    private:
    42         StringObjectThatMasqueradesAsUndefined(ExecState* exec, Structure* structure, const UString& string)
    43             : StringObject(exec, structure, string)
     43        StringObjectThatMasqueradesAsUndefined(ExecState* exec, Structure* structure, JSString* string)
     44            : StringObject(exec->globalData(), structure, string)
    4445        {
    4546        }
  • trunk/Source/JavaScriptCore/runtime/StringPrototype.cpp

    r92540 r93378  
    132132
    133133// ECMA 15.5.4
    134 StringPrototype::StringPrototype(ExecState* exec, JSGlobalObject* globalObject, Structure* structure)
    135     : StringObject(exec, structure)
     134StringPrototype::StringPrototype(ExecState* exec, JSGlobalObject* globalObject, Structure* structure, JSString* nameAndMessage)
     135    : StringObject(exec->globalData(), structure, nameAndMessage)
    136136{
    137137    ASSERT(inherits(&s_info));
  • trunk/Source/JavaScriptCore/runtime/StringPrototype.h

    r92706 r93378  
    3030    class StringPrototype : public StringObject {
    3131    private:
    32         StringPrototype(ExecState*, JSGlobalObject*, Structure*);
     32        StringPrototype(ExecState*, JSGlobalObject*, Structure*, JSString*);
    3333
    3434    public:
     
    3737        static StringPrototype* create(ExecState* exec, JSGlobalObject* globalObject, Structure* structure)
    3838        {
    39             return new (allocateCell<StringPrototype>(*exec->heap())) StringPrototype(exec, globalObject, structure);
     39            JSString* nameAndMessage = jsEmptyString(exec);
     40            return new (allocateCell<StringPrototype>(*exec->heap())) StringPrototype(exec, globalObject, structure, nameAndMessage);
    4041        }
    4142
  • trunk/Source/WebCore/ChangeLog

    r93377 r93378  
     12011-08-18  Mark Hahnenberg  <mhahnenberg@apple.com>
     2
     3        Move allocation in constructors into separate constructorBody() methods
     4        https://bugs.webkit.org/show_bug.cgi?id=66265
     5
     6        Reviewed by Oliver Hunt.
     7
     8        No new tests.
     9
     10        Refactoring to put all allocations that need to be done after the object's
     11        initialization list has executed but before the object is ready for use
     12        into a separate constructorBody() method.  This method is still called by the constructor,
     13        so the patch doesn't resolve any potential issues, it's just to set up the code for further refactoring.
     14
     15        * bridge/objc/ObjCRuntimeObject.h:
     16        (JSC::Bindings::ObjCRuntimeObject::create):
     17        * bridge/objc/ObjCRuntimeObject.mm:
     18        * bridge/objc/objc_instance.mm:
     19        (ObjCRuntimeMethod::create):
     20        (ObjCRuntimeMethod::ObjCRuntimeMethod):
     21        * bridge/runtime_array.cpp:
     22        * bridge/runtime_array.h:
     23        (JSC::RuntimeArray::create):
     24
    1252011-08-18  Beth Dakin  <bdakin@apple.com>
    226
  • trunk/Source/WebCore/bridge/objc/ObjCRuntimeObject.h

    r92788 r93378  
    4040    static ObjCRuntimeObject* create(ExecState* exec, JSGlobalObject* globalObject, PassRefPtr<ObjcInstance> inst)
    4141    {
     42        // FIXME: deprecatedGetDOMStructure uses the prototype off of the wrong global object
     43        // We need to pass in the right global object for "i".
    4244        Structure* structure = WebCore::deprecatedGetDOMStructure<ObjCRuntimeObject>(exec);
    4345        return new (allocateCell<ObjCRuntimeObject>(*exec->heap())) ObjCRuntimeObject(exec, globalObject, inst, structure);
  • trunk/Source/WebCore/bridge/objc/ObjCRuntimeObject.mm

    r92788 r93378  
    3737
    3838ObjCRuntimeObject::ObjCRuntimeObject(ExecState* exec, JSGlobalObject* globalObject, PassRefPtr<ObjcInstance> instance, Structure* structure)
    39     // FIXME: deprecatedGetDOMStructure uses the prototype off of the wrong global object
    40     // We need to pass in the right global object for "i".
    4139    : RuntimeObject(exec, globalObject, structure, instance)
    4240{
  • trunk/Source/WebCore/bridge/objc/objc_instance.mm

    r92788 r93378  
    176176    static ObjCRuntimeMethod* create(ExecState* exec, JSGlobalObject* globalObject, const Identifier& name, Bindings::MethodList& list)
    177177    {
    178         return new (allocateCell<ObjCRuntimeMethod>(*exec->heap())) ObjCRuntimeMethod(exec, globalObject, name, list);
     178        // FIXME: deprecatedGetDOMStructure uses the prototype off of the wrong global object
     179        // We need to pass in the right global object for "i".
     180        Structure* domStructure = WebCore::deprecatedGetDOMStructure<ObjCRuntimeMethod>(exec);
     181        return new (allocateCell<ObjCRuntimeMethod>(*exec->heap())) ObjCRuntimeMethod(exec, globalObject, domStructure, name, list);
    179182    }
    180183
     
    187190
    188191private:
    189     ObjCRuntimeMethod(ExecState* exec, JSGlobalObject* globalObject, const Identifier& name, Bindings::MethodList& list)
    190         // FIXME: deprecatedGetDOMStructure uses the prototype off of the wrong global object
    191         // We need to pass in the right global object for "i".
    192         : RuntimeMethod(exec, globalObject, WebCore::deprecatedGetDOMStructure<ObjCRuntimeMethod>(exec), name, list)
     192    ObjCRuntimeMethod(ExecState* exec, JSGlobalObject* globalObject, Structure* structure, const Identifier& name, Bindings::MethodList& list)
     193        : RuntimeMethod(exec, globalObject, structure, name, list)
    193194    {
    194195        ASSERT(inherits(&s_info));
  • trunk/Source/WebCore/bridge/runtime_array.cpp

    r93059 r93378  
    3939
    4040RuntimeArray::RuntimeArray(ExecState* exec, Structure* structure, Bindings::Array* array)
    41     // FIXME: deprecatedGetDOMStructure uses the prototype off of the wrong global object
    42     // We need to pass in the right global object for "array".
    4341    : JSArray(exec->globalData(), structure)
    4442{
  • trunk/Source/WebCore/bridge/runtime_array.h

    r93059 r93378  
    3939    static RuntimeArray* create(ExecState* exec, Bindings::Array* array)
    4040    {
     41        // FIXME: deprecatedGetDOMStructure uses the prototype off of the wrong global object
     42        // We need to pass in the right global object for "array".
    4143        Structure* domStructure = WebCore::deprecatedGetDOMStructure<RuntimeArray>(exec);
    4244        return new (allocateCell<RuntimeArray>(*exec->heap())) RuntimeArray(exec, domStructure, array);
Note: See TracChangeset for help on using the changeset viewer.