Changeset 47292 in webkit for trunk/JavaScriptCore/runtime


Ignore:
Timestamp:
Aug 14, 2009, 1:18:09 PM (16 years ago)
Author:
[email protected]
Message:

[ES5] Arguments object should inherit from Array
https://bugs.webkit.org/show_bug.cgi?id=28298

Reviewed by Gavin Barraclough

Make the Arguments object conform to the behaviour specified in ES5.
The simple portion of this is to make Arguments use Array.prototype
as its prototype rather than Object.prototype.

The spec then requires us to set instance.constructor to the pristine
Object constructor, and instance.toString and instance.toLocaleString
to the pristine versions from Object.prototype. To do this we now
make the ObjectPrototype constructor return its toString and
toLocaleString functions (similar to the call and apply functions
from FunctionPrototype).

Oddly enough this reports itself as a slight win, but given the code
isn't hit in the tests that claim to have improved I put this down to
code motion.

Location:
trunk/JavaScriptCore/runtime
Files:
5 edited

Legend:

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

    r47022 r47292  
    2929#include "JSGlobalObject.h"
    3030#include "Interpreter.h"
     31#include "ObjectConstructor.h"
    3132
    3233namespace JSC {
     
    99100
    100101        void init(CallFrame*);
     102        void initializeStandardProperties(CallFrame*);
    101103
    102104        OwnPtr<ArgumentsData> d;
     
    132134        , d(new ArgumentsData)
    133135    {
     136        initializeStandardProperties(callFrame);
    134137        JSFunction* callee;
    135138        ptrdiff_t firstParameterIndex;
     
    170173    {
    171174        ASSERT(!callFrame->callee()->body()->parameterCount());
    172 
     175       
     176        initializeStandardProperties(callFrame);
    173177        unsigned numArguments = callFrame->argumentCount() - 1;
    174178
     
    238242    }
    239243   
     244   
     245    inline void Arguments::initializeStandardProperties(CallFrame* callFrame)
     246    {
     247        putDirectFunction(callFrame->propertyNames().constructor, callFrame->lexicalGlobalObject()->objectConstructor(), DontEnum);
     248        putDirectFunction(callFrame->propertyNames().toString, callFrame->lexicalGlobalObject()->objectToStringFunction(), DontEnum);
     249        putDirectFunction(callFrame->propertyNames().toLocaleString, callFrame->lexicalGlobalObject()->objectToLocaleStringFunction(), DontEnum);
     250    }
    240251
    241252} // namespace JSC
  • trunk/JavaScriptCore/runtime/JSGlobalObject.cpp

    r47271 r47292  
    211211    d()->callFunction = callFunction;
    212212    d()->applyFunction = applyFunction;
    213     d()->objectPrototype = new (exec) ObjectPrototype(exec, ObjectPrototype::createStructure(jsNull()), d()->prototypeFunctionStructure.get());
     213    NativeFunctionWrapper* objectToStringFunction = 0;
     214    NativeFunctionWrapper* objectToLocaleStringFunction = 0;
     215    d()->objectPrototype = new (exec) ObjectPrototype(exec, ObjectPrototype::createStructure(jsNull()), d()->prototypeFunctionStructure.get(), &objectToStringFunction, &objectToLocaleStringFunction);
     216    d()->objectToStringFunction = objectToStringFunction;
     217    d()->objectToLocaleStringFunction = objectToLocaleStringFunction;
    214218    d()->functionPrototype->structure()->setPrototypeWithoutTransition(d()->objectPrototype);
    215219
     
    218222    d()->functionStructure = JSFunction::createStructure(d()->functionPrototype);
    219223    d()->callbackFunctionStructure = JSCallbackFunction::createStructure(d()->functionPrototype);
    220     d()->argumentsStructure = Arguments::createStructure(d()->objectPrototype);
    221224    d()->callbackConstructorStructure = JSCallbackConstructor::createStructure(d()->objectPrototype);
    222225    d()->callbackObjectStructure = JSCallbackObject<JSObject>::createStructure(d()->objectPrototype);
    223226
    224227    d()->arrayPrototype = new (exec) ArrayPrototype(ArrayPrototype::createStructure(d()->objectPrototype));
     228    d()->argumentsStructure = Arguments::createStructure(d()->arrayPrototype);
    225229    d()->arrayStructure = JSArray::createStructure(d()->arrayPrototype);
    226230    d()->regExpMatchesArrayStructure = RegExpMatchesArray::createStructure(d()->arrayPrototype);
     
    257261    // Constructors
    258262
    259     JSCell* objectConstructor = new (exec) ObjectConstructor(exec, ObjectConstructor::createStructure(d()->functionPrototype), d()->objectPrototype, d()->prototypeFunctionStructure.get());
     263    ObjectConstructor* objectConstructor = new (exec) ObjectConstructor(exec, ObjectConstructor::createStructure(d()->functionPrototype), d()->objectPrototype, d()->prototypeFunctionStructure.get());
    260264    JSCell* functionConstructor = new (exec) FunctionConstructor(exec, FunctionConstructor::createStructure(d()->functionPrototype), d()->functionPrototype);
    261265    JSCell* arrayConstructor = new (exec) ArrayConstructor(exec, ArrayConstructor::createStructure(d()->functionPrototype), d()->arrayPrototype, d()->prototypeFunctionStructure.get());
     
    271275    RefPtr<Structure> nativeErrorStructure = NativeErrorConstructor::createStructure(d()->functionPrototype);
    272276
     277    d()->objectConstructor = objectConstructor;
    273278    d()->evalErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, evalErrorPrototype);
    274279    d()->rangeErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, rangeErrorPrototype);
     
    369374    if (registerFile.globalObject() == this)
    370375        registerFile.markGlobals(markStack, &globalData()->heap);
    371 
     376   
     377    markIfNeeded(markStack, d()->objectConstructor);
    372378    markIfNeeded(markStack, d()->regExpConstructor);
    373379    markIfNeeded(markStack, d()->errorConstructor);
     
    382388    markIfNeeded(markStack, d()->callFunction);
    383389    markIfNeeded(markStack, d()->applyFunction);
     390    markIfNeeded(markStack, d()->objectToStringFunction);
     391    markIfNeeded(markStack, d()->objectToLocaleStringFunction);
    384392
    385393    markIfNeeded(markStack, d()->objectPrototype);
  • trunk/JavaScriptCore/runtime/JSGlobalObject.h

    r47022 r47292  
    4141    class GlobalEvalFunction;
    4242    class NativeErrorConstructor;
     43    class ObjectConstructor;
    4344    class ProgramCodeBlock;
    4445    class PrototypeFunction;
     
    6162                , registerArraySize(0)
    6263                , globalScopeChain(NoScopeChain())
     64                , objectConstructor(0)
    6365                , regExpConstructor(0)
    6466                , errorConstructor(0)
     
    7274                , callFunction(0)
    7375                , applyFunction(0)
     76                , objectToStringFunction(0)
     77                , objectToLocaleStringFunction(0)
    7478                , objectPrototype(0)
    7579                , functionPrototype(0)
     
    100104            int recursion;
    101105
     106            ObjectConstructor* objectConstructor;
    102107            RegExpConstructor* regExpConstructor;
    103108            ErrorConstructor* errorConstructor;
     
    112117            NativeFunctionWrapper* callFunction;
    113118            NativeFunctionWrapper* applyFunction;
     119            NativeFunctionWrapper* objectToStringFunction;
     120            NativeFunctionWrapper* objectToLocaleStringFunction;
    114121
    115122            ObjectPrototype* objectPrototype;
     
    184191        // replaces the global object's associated property.
    185192
     193        ObjectConstructor* objectConstructor() const { return d()->objectConstructor; }
    186194        RegExpConstructor* regExpConstructor() const { return d()->regExpConstructor; }
    187195
     
    204212        DatePrototype* datePrototype() const { return d()->datePrototype; }
    205213        RegExpPrototype* regExpPrototype() const { return d()->regExpPrototype; }
     214
     215        NativeFunctionWrapper* objectToStringFunction() const { return d()->objectToStringFunction; }
     216        NativeFunctionWrapper* objectToLocaleStringFunction() const { return d()->objectToLocaleStringFunction; }
    206217
    207218        JSObject* methodCallDummy() const { return d()->methodCallDummy; }
  • trunk/JavaScriptCore/runtime/ObjectPrototype.cpp

    r43372 r47292  
    4141static JSValue JSC_HOST_CALL objectProtoFuncToLocaleString(ExecState*, JSObject*, JSValue, const ArgList&);
    4242
    43 ObjectPrototype::ObjectPrototype(ExecState* exec, PassRefPtr<Structure> stucture, Structure* prototypeFunctionStructure)
     43ObjectPrototype::ObjectPrototype(ExecState* exec, PassRefPtr<Structure> stucture, Structure* prototypeFunctionStructure, NativeFunctionWrapper** toStringFunction, NativeFunctionWrapper** toLocaleStringFunction)
    4444    : JSObject(stucture)
    4545{
    46     putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, prototypeFunctionStructure, 0, exec->propertyNames().toString, objectProtoFuncToString), DontEnum);
    47     putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, prototypeFunctionStructure, 0, exec->propertyNames().toLocaleString, objectProtoFuncToLocaleString), DontEnum);
     46    NativeFunctionWrapper* toString = new (exec) NativeFunctionWrapper(exec, prototypeFunctionStructure, 0, exec->propertyNames().toString, objectProtoFuncToString);
     47    NativeFunctionWrapper* toLocaleString = new (exec) NativeFunctionWrapper(exec, prototypeFunctionStructure, 0, exec->propertyNames().toLocaleString, objectProtoFuncToLocaleString);
     48    *toStringFunction = toString;
     49    *toLocaleStringFunction = toLocaleString;
     50    putDirectFunctionWithoutTransition(exec, toString, DontEnum);
     51    putDirectFunctionWithoutTransition(exec, toLocaleString, DontEnum);
    4852    putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, prototypeFunctionStructure, 0, exec->propertyNames().valueOf, objectProtoFuncValueOf), DontEnum);
    4953    putDirectFunctionWithoutTransition(exec, new (exec) NativeFunctionWrapper(exec, prototypeFunctionStructure, 1, exec->propertyNames().hasOwnProperty, objectProtoFuncHasOwnProperty), DontEnum);
  • trunk/JavaScriptCore/runtime/ObjectPrototype.h

    r43372 r47292  
    2828    class ObjectPrototype : public JSObject {
    2929    public:
    30         ObjectPrototype(ExecState*, PassRefPtr<Structure>, Structure* prototypeFunctionStructure);
     30        ObjectPrototype(ExecState*, PassRefPtr<Structure>, Structure* prototypeFunctionStructure, NativeFunctionWrapper** toStringFunction, NativeFunctionWrapper** toLocaleStringFunction);
    3131    };
    3232
Note: See TracChangeset for help on using the changeset viewer.