Changeset 104886 in webkit


Ignore:
Timestamp:
Jan 12, 2012 5:40:22 PM (12 years ago)
Author:
barraclough@apple.com
Message:

Clean up putDirect (part 1)
https://bugs.webkit.org/show_bug.cgi?id=76232

Reviewed by Sam Weinig.

putDirect has ambiguous semantics, clean these up a bit.

putDirect generally behaves a bit like a fast defineOwnProperty, but one that
always creates the property, with no checking to validate the put it permitted.

It also encompasses two slightly different behaviors.
(1) a fast form of put for JSActivation, which doesn't have to handle searching

the prototype chain, getter/setter properties, or the magic proto value.
Break this out as a new method, 'putOwnDataProperty'.

(2) the version of putDirect on JSValue will also check for overwriting ReadOnly

values, in strict mode. This is, however, not so smart on a few level, since
it is only called from op_put_by_id with direct set, which is only used with
an object as the base, and is only used to put new properties onto objects.

  • dfg/DFGOperations.cpp:
  • interpreter/Interpreter.cpp:

(JSC::Interpreter::privateExecute):

  • jit/JITStubs.cpp:

(JSC::DEFINE_STUB_FUNCTION):

  • runtime/JSActivation.cpp:

(JSC::JSActivation::put):

  • runtime/JSFunction.cpp:

(JSC::JSFunction::getOwnPropertySlot):

  • runtime/JSObject.h:

(JSC::JSObject::putOwnDataProperty):

  • runtime/JSValue.h:
Location:
trunk/Source/JavaScriptCore
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r104871 r104886  
     12012-01-12  Gavin Barraclough  <barraclough@apple.com>
     2
     3        Clean up putDirect (part 1)
     4        https://bugs.webkit.org/show_bug.cgi?id=76232
     5
     6        Reviewed by Sam Weinig.
     7
     8        putDirect has ambiguous semantics, clean these up a bit.
     9
     10        putDirect generally behaves a bit like a fast defineOwnProperty, but one that
     11        always creates the property, with no checking to validate the put it permitted.
     12
     13        It also encompasses two slightly different behaviors.
     14        (1) a fast form of put for JSActivation, which doesn't have to handle searching
     15            the prototype chain, getter/setter properties, or the magic __proto__ value.
     16            Break this out as a new method, 'putOwnDataProperty'.
     17        (2) the version of putDirect on JSValue will also check for overwriting ReadOnly
     18            values, in strict mode. This is, however, not so smart on a few level, since
     19            it is only called from op_put_by_id with direct set, which is only used with
     20            an object as the base, and is only used to put new properties onto objects.
     21
     22        * dfg/DFGOperations.cpp:
     23        * interpreter/Interpreter.cpp:
     24        (JSC::Interpreter::privateExecute):
     25        * jit/JITStubs.cpp:
     26        (JSC::DEFINE_STUB_FUNCTION):
     27        * runtime/JSActivation.cpp:
     28        (JSC::JSActivation::put):
     29        * runtime/JSFunction.cpp:
     30        (JSC::JSFunction::getOwnPropertySlot):
     31        * runtime/JSObject.h:
     32        (JSC::JSObject::putOwnDataProperty):
     33        * runtime/JSValue.h:
     34
    1352012-01-12  Gavin Barraclough  <barraclough@apple.com>
    236
  • trunk/Source/JavaScriptCore/dfg/DFGOperations.cpp

    r104630 r104886  
    432432{
    433433    PutPropertySlot slot(true);
    434     JSValue(base).putDirect(exec, *propertyName, JSValue::decode(encodedValue), slot);
     434    ASSERT(base->isObject());
     435    asObject(base)->putDirect(exec->globalData(), *propertyName, JSValue::decode(encodedValue), slot);
    435436}
    436437
     
    438439{
    439440    PutPropertySlot slot(false);
    440     JSValue(base).putDirect(exec, *propertyName, JSValue::decode(encodedValue), slot);
     441    ASSERT(base->isObject());
     442    asObject(base)->putDirect(exec->globalData(), *propertyName, JSValue::decode(encodedValue), slot);
    441443}
    442444
     
    477479{
    478480    JSValue value = JSValue::decode(encodedValue);
    479     JSValue baseValue(base);
    480481    PutPropertySlot slot(true);
    481482   
    482     baseValue.putDirect(exec, *propertyName, value, slot);
     483    ASSERT(base->isObject());
     484    asObject(base)->putDirect(exec->globalData(), *propertyName, value, slot);
    483485   
    484486    StructureStubInfo& stubInfo = exec->codeBlock()->getStubInfo(returnAddress);
    485487    if (stubInfo.seen)
    486         dfgRepatchPutByID(exec, baseValue, *propertyName, slot, stubInfo, Direct);
     488        dfgRepatchPutByID(exec, base, *propertyName, slot, stubInfo, Direct);
    487489    else
    488490        stubInfo.seen = true;
     
    493495{
    494496    JSValue value = JSValue::decode(encodedValue);
    495     JSValue baseValue(base);
    496497    PutPropertySlot slot(false);
    497498   
    498     baseValue.putDirect(exec, *propertyName, value, slot);
     499    ASSERT(base->isObject());
     500    asObject(base)->putDirect(exec->globalData(), *propertyName, value, slot);
    499501   
    500502    StructureStubInfo& stubInfo = exec->codeBlock()->getStubInfo(returnAddress);
    501503    if (stubInfo.seen)
    502         dfgRepatchPutByID(exec, baseValue, *propertyName, slot, stubInfo, Direct);
     504        dfgRepatchPutByID(exec, base, *propertyName, slot, stubInfo, Direct);
    503505    else
    504506        stubInfo.seen = true;
  • trunk/Source/JavaScriptCore/interpreter/Interpreter.cpp

    r104630 r104886  
    33093309
    33103310        JSValue baseValue = callFrame->r(base).jsValue();
     3311        ASSERT(baseValue.isObject());
     3312        JSObject* baseObject = asObject(baseValue);
    33113313        Identifier& ident = codeBlock->identifier(property);
    33123314        PutPropertySlot slot(codeBlock->isStrictMode());
    33133315        if (direct)
    3314             baseValue.putDirect(callFrame, ident, callFrame->r(value).jsValue(), slot);
     3316            baseObject->putDirect(*globalData, ident, callFrame->r(value).jsValue(), slot);
    33153317        else
    33163318            baseValue.put(callFrame, ident, callFrame->r(value).jsValue(), slot);
     
    34273429
    34283430        JSValue baseValue = callFrame->r(base).jsValue();
     3431        ASSERT(baseValue.isObject());
     3432        JSObject* baseObject = asObject(baseValue);
    34293433        Identifier& ident = codeBlock->identifier(property);
    34303434        PutPropertySlot slot(codeBlock->isStrictMode());
    34313435        if (direct)
    3432             baseValue.putDirect(callFrame, ident, callFrame->r(value).jsValue(), slot);
     3436            baseObject->putDirect(*globalData, ident, callFrame->r(value).jsValue(), slot);
    34333437        else
    34343438            baseValue.put(callFrame, ident, callFrame->r(value).jsValue(), slot);
  • trunk/Source/JavaScriptCore/jit/JITStubs.cpp

    r104630 r104886  
    13831383   
    13841384    PutPropertySlot slot(stackFrame.callFrame->codeBlock()->isStrictMode());
    1385     stackFrame.args[0].jsValue().putDirect(stackFrame.callFrame, stackFrame.args[1].identifier(), stackFrame.args[2].jsValue(), slot);
     1385    JSValue baseValue = stackFrame.args[0].jsValue();
     1386    ASSERT(baseValue.isObject());
     1387    asObject(baseValue)->putDirect(stackFrame.callFrame->globalData(), stackFrame.args[1].identifier(), stackFrame.args[2].jsValue(), slot);
    13861388    CHECK_FOR_EXCEPTION_AT_END();
    13871389}
     
    14281430   
    14291431    PutPropertySlot slot(callFrame->codeBlock()->isStrictMode());
    1430     stackFrame.args[0].jsValue().putDirect(callFrame, ident, stackFrame.args[2].jsValue(), slot);
     1432    JSValue baseValue = stackFrame.args[0].jsValue();
     1433    ASSERT(baseValue.isObject());
     1434    asObject(baseValue)->putDirect(callFrame->globalData(), ident, stackFrame.args[2].jsValue(), slot);
    14311435   
    14321436    CodeBlock* codeBlock = stackFrame.callFrame->codeBlock();
     
    14611465   
    14621466    PutPropertySlot slot(callFrame->codeBlock()->isStrictMode());
    1463     stackFrame.args[0].jsValue().putDirect(callFrame, ident, stackFrame.args[2].jsValue(), slot);
     1467    JSValue baseValue = stackFrame.args[0].jsValue();
     1468    ASSERT(baseValue.isObject());
     1469    asObject(baseValue)->putDirect(callFrame->globalData(), ident, stackFrame.args[2].jsValue(), slot);
    14641470   
    14651471    CHECK_FOR_EXCEPTION_AT_END();
  • trunk/Source/JavaScriptCore/runtime/JSActivation.cpp

    r103697 r104886  
    185185    // expose in the activation object.
    186186    ASSERT(!thisObject->hasGetterSetterProperties());
    187     thisObject->putDirect(exec->globalData(), propertyName, value, 0, true, slot);
     187    thisObject->putOwnDataProperty(exec->globalData(), propertyName, value, slot);
    188188}
    189189
  • trunk/Source/JavaScriptCore/runtime/JSFunction.cpp

    r104784 r104886  
    205205            JSObject* prototype = constructEmptyObject(exec, thisObject->globalObject()->emptyObjectStructure());
    206206            prototype->putDirect(exec->globalData(), exec->propertyNames().constructor, thisObject, DontEnum);
    207             PutPropertySlot slot;
    208             thisObject->putDirect(exec->globalData(), exec->propertyNames().prototype, prototype, DontDelete | DontEnum, false, slot);
     207            thisObject->putDirect(exec->globalData(), exec->propertyNames().prototype, prototype, DontDelete | DontEnum);
    209208            location = thisObject->getDirectLocation(exec->globalData(), exec->propertyNames().prototype);
    210209        }
  • trunk/Source/JavaScriptCore/runtime/JSObject.h

    r104784 r104886  
    108108        static void putByIndex(JSCell*, ExecState*, unsigned propertyName, JSValue);
    109109
     110        // putWithAttributes is effectively an unchecked vesion of 'defineOwnProperty':
     111        //  - the prototype chain is not consulted
     112        //  - accessors are not called.
     113        //  - attributes will be respected (after the call the property will exist with the given attributes)
    110114        static void putWithAttributes(JSObject*, ExecState*, const Identifier& propertyName, JSValue, unsigned attributes);
    111115        void putWithAttributes(JSGlobalData*, const Identifier& propertyName, JSValue, unsigned attributes);
     
    171175        bool hasGetterSetterProperties() { return structure()->hasGetterSetterProperties(); }
    172176
    173         bool putDirect(JSGlobalData&, const Identifier& propertyName, JSValue, unsigned attr, bool checkReadOnly, PutPropertySlot&);
     177        // putOwnDataProperty has 'put' like semantics, however this method:
     178        //  - assumes the object contains no own getter/setter properties.
     179        //  - provides no special handling for __proto__
     180        //  - does not walk the prototype chain (to check for accessors or non-writable properties).
     181        // This is used by JSActivation.
     182        bool putOwnDataProperty(JSGlobalData&, const Identifier& propertyName, JSValue, PutPropertySlot&);
     183
    174184        void putDirect(JSGlobalData&, const Identifier& propertyName, JSValue, unsigned attr = 0);
    175185        bool putDirect(JSGlobalData&, const Identifier& propertyName, JSValue, PutPropertySlot&);
     
    739749}
    740750
    741 inline bool JSObject::putDirect(JSGlobalData& globalData, const Identifier& propertyName, JSValue value, unsigned attributes, bool checkReadOnly, PutPropertySlot& slot)
     751inline bool JSObject::putOwnDataProperty(JSGlobalData& globalData, const Identifier& propertyName, JSValue value, PutPropertySlot& slot)
    742752{
    743753    ASSERT(value);
    744754    ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));
    745 
    746     return putDirectInternal(globalData, propertyName, value, attributes, checkReadOnly, slot, getJSFunction(value));
     755    ASSERT(!structure()->hasGetterSetterProperties());
     756
     757    return putDirectInternal(globalData, propertyName, value, 0, true, slot, getJSFunction(value));
    747758}
    748759
     
    841852}
    842853
    843 inline void JSValue::putDirect(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot)
    844 {
    845     ASSERT(isCell() && isObject());
    846     if (!asObject(asCell())->putDirect(exec->globalData(), propertyName, value, slot) && slot.isStrictMode())
    847         throwTypeError(exec, StrictModeReadonlyPropertyWriteError);
    848 }
    849 
    850854inline void JSValue::put(ExecState* exec, unsigned propertyName, JSValue value)
    851855{
  • trunk/Source/JavaScriptCore/runtime/JSValue.h

    r99629 r104886  
    219219        JSValue get(ExecState*, unsigned propertyName, PropertySlot&) const;
    220220        void put(ExecState*, const Identifier& propertyName, JSValue, PutPropertySlot&);
    221         void putDirect(ExecState*, const Identifier& propertyName, JSValue, PutPropertySlot&);
    222221        void put(ExecState*, unsigned propertyName, JSValue);
    223222
Note: See TracChangeset for help on using the changeset viewer.