Ignore:
Timestamp:
May 21, 2008, 6:20:45 PM (17 years ago)
Author:
[email protected]
Message:

Merge squirrelfish branch into trunk.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/JSGlobalObject.h

    r33038 r33979  
    22/*
    33 *  Copyright (C) 2007 Eric Seidel <[email protected]>
    4  *  Copyright (C) 2007 Apple Inc. All rights reserved.
     4 *  Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
    55 *
    66 *  This library is free software; you can redistribute it and/or
     
    2525
    2626#include "JSVariableObject.h"
    27 #include "Activation.h"
     27#include "RegisterFile.h"
     28#include "RegisterFileStack.h"
     29#include <wtf/HashSet.h>
     30#include <wtf/OwnPtr.h>
    2831
    2932namespace KJS {
    3033
    31     class ActivationImp;
    3234    class ArrayObjectImp;
    3335    class ArrayPrototype;
     
    5153    class ObjectObjectImp;
    5254    class ObjectPrototype;
     55    class ProgramCodeBlock;
    5356    class PrototypeReflexiveFunction;
    5457    class RangeError;
     
    7881
    7982        struct JSGlobalObjectData : public JSVariableObjectData {
    80             JSGlobalObjectData()
    81                 : JSVariableObjectData(&inlineSymbolTable)
     83            JSGlobalObjectData(JSGlobalObject* globalObject, JSObject* thisValue)
     84                : JSVariableObjectData(&symbolTable, registerFileStack.globalBasePointer(), 0)
     85                , globalScopeChain(globalObject)
     86                , globalExec(new ExecState(globalObject, thisValue, globalScopeChain.node()))
    8287            {
    8388            }
     
    8893            Debugger* debugger;
    8994           
    90             OwnPtr<GlobalExecState> globalExec;
     95            RegisterFileStack registerFileStack;
     96            ScopeChain globalScopeChain;
     97            OwnPtr<ExecState> globalExec;
     98
    9199            int recursion;
    92100
     
    132140            NativeErrorPrototype* URIErrorPrototype;
    133141           
    134             SymbolTable inlineSymbolTable;
    135 
    136             ExecStateStack activeExecStates;
    137 
    138             ActivationStackNode* activations;
    139             size_t activationCount;
    140            
     142            SymbolTable symbolTable;
    141143            unsigned pageGroupIdentifier;
    142144
     145            PerThreadData perThreadData;
     146
     147            HashSet<ProgramCodeBlock*> codeBlocks;
     148
    143149            OwnPtr<HashSet<JSObject*> > arrayVisitedElements; // Global data shared by array prototype functions.
    144 
    145             PerThreadData perThreadData;
    146150        };
    147151
    148152    public:
    149153        JSGlobalObject()
    150             : JSVariableObject(new JSGlobalObjectData)
     154            : JSVariableObject(new JSGlobalObjectData(this, this))
    151155        {
    152156            init(this);
     
    155159    protected:
    156160        JSGlobalObject(JSValue* proto, JSObject* globalThisValue)
    157             : JSVariableObject(proto, new JSGlobalObjectData)
     161            : JSVariableObject(proto, new JSGlobalObjectData(this, globalThisValue))
    158162        {
    159163            init(globalThisValue);
     
    164168
    165169        virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
     170        virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&, bool& slotIsWriteable);
    166171        virtual void put(ExecState*, const Identifier&, JSValue*);
    167172        virtual void putWithAttributes(ExecState*, const Identifier& propertyName, JSValue* value, unsigned attributes);
     
    228233        void incRecursion() { ++d()->recursion; }
    229234        void decRecursion() { --d()->recursion; }
     235       
     236        ScopeChain& globalScopeChain() { return d()->globalScopeChain; }
    230237
    231238        virtual void mark();
     
    240247        virtual bool allowsAccessFrom(const JSGlobalObject*) const { return true; }
    241248
    242         ActivationImp* pushActivation(ExecState*);
    243         void popActivation();
    244         void tearOffActivation(ExecState*, bool markAsRelic = false);
    245 
    246249        virtual bool isDynamicScope() const;
    247250
    248         ExecStateStack& activeExecStates() const { return d()->activeExecStates; }
    249 
    250251        HashSet<JSObject*>& arrayVisitedElements() { if (!d()->arrayVisitedElements) d()->arrayVisitedElements.set(new HashSet<JSObject*>); return *d()->arrayVisitedElements; }
     252
     253        HashSet<ProgramCodeBlock*>& codeBlocks() { return d()->codeBlocks; }
     254
     255        RegisterFileStack& registerFileStack() { return d()->registerFileStack; }
    251256
    252257        // Per-thread hash tables, cached on the global object for faster access.
     
    261266        JSGlobalObjectData* d() const { return static_cast<JSGlobalObjectData*>(JSVariableObject::d); }
    262267
     268        struct GlobalPropertyInfo {
     269            GlobalPropertyInfo(const Identifier& i, JSValue* v, unsigned a)
     270                : identifier(i)
     271                , value(v)
     272                , attributes(a)
     273            {
     274            }
     275
     276            const Identifier& identifier;
     277            JSValue* value;
     278            unsigned attributes;
     279        };
     280        void addStaticGlobals(GlobalPropertyInfo*, int count);
     281
    263282        bool checkTimeout();
    264283        void resetTimeoutCheck();
    265284
    266         void deleteActivationStack();
    267         void checkActivationCount();
    268 
    269285        static JSGlobalObject* s_head;
    270286    };
    271287
     288    inline void JSGlobalObject::addStaticGlobals(GlobalPropertyInfo* globals, int count)
     289    {
     290        RegisterFile* registerFile = registerFileStack().current();
     291        ASSERT(registerFile->safeForReentry() && registerFile->isGlobal() && !registerFile->size());
     292        int index = -registerFile->numGlobalSlots() - 1;
     293        registerFile->addGlobalSlots(count);
     294        for (int i = 0; i < count; ++i) {
     295            ASSERT(globals[i].attributes & DontDelete);
     296            SymbolTableEntry newEntry(index, globals[i].attributes);
     297            symbolTable().add(globals[i].identifier.ustring().rep(), newEntry);
     298            valueAt(index) = globals[i].value;
     299            --index;
     300        }
     301    }
     302
     303    inline bool JSGlobalObject::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
     304    {
     305        if (JSVariableObject::getOwnPropertySlot(exec, propertyName, slot))
     306            return true;
     307        return symbolTableGet(propertyName, slot);
     308    }
     309
     310    inline bool JSGlobalObject::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot, bool& slotIsWriteable)
     311    {
     312        if (JSVariableObject::getOwnPropertySlotForWrite(exec, propertyName, slot, slotIsWriteable))
     313            return true;
     314        return symbolTableGet(propertyName, slot, slotIsWriteable);
     315    }
     316
    272317    inline bool JSGlobalObject::timedOut()
    273318    {
     
    280325    }
    281326
    282     inline ActivationImp* JSGlobalObject::pushActivation(ExecState* exec)
    283     {
    284         if (d()->activationCount == activationStackNodeSize) {
    285             ActivationStackNode* newNode = new ActivationStackNode;
    286             newNode->prev = d()->activations;
    287             d()->activations = newNode;
    288             d()->activationCount = 0;
    289         }
    290        
    291         StackActivation* stackEntry = &d()->activations->data[d()->activationCount++];
    292         stackEntry->activationStorage.init(exec);
    293         return &stackEntry->activationStorage;
    294     }
    295 
    296     inline void JSGlobalObject::checkActivationCount()
    297     {
    298         if (!d()->activationCount) {
    299             ActivationStackNode* prev = d()->activations->prev;
    300             ASSERT(prev);
    301             delete d()->activations;
    302             d()->activations = prev;
    303             d()->activationCount = activationStackNodeSize;
    304         }
    305     }
    306 
    307     inline void JSGlobalObject::popActivation()
    308     {
    309         checkActivationCount();
    310         d()->activations->data[--d()->activationCount].activationDataStorage.localStorage.shrink(0);   
     327    inline JSGlobalObject* ScopeChainNode::globalObject() const
     328    {
     329        JSGlobalObject* globalObject = static_cast<JSGlobalObject*>(bottom());
     330        ASSERT(globalObject->isGlobalObject());
     331        return globalObject;
    311332    }
    312333
Note: See TracChangeset for help on using the changeset viewer.