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/JSVariableObject.h

    r32652 r33979  
    3030#define JSVariableObject_h
    3131
    32 #include "LocalStorageEntry.h"
     32#include "Register.h"
    3333#include "SymbolTable.h"
     34#include "UnusedParam.h"
    3435#include "object.h"
     36#include <wtf/UnusedParam.h>
    3537
    3638namespace KJS {
     39
     40    class Register;
    3741
    3842    class JSVariableObject : public JSObject {
    3943    public:
    4044        SymbolTable& symbolTable() const { return *d->symbolTable; }
    41         LocalStorage& localStorage() const { return d->localStorage; }
    4245
    4346        virtual void putWithAttributes(ExecState*, const Identifier&, JSValue*, unsigned attributes) = 0;
     
    4649        virtual void getPropertyNames(ExecState*, PropertyNameArray&);
    4750       
    48         virtual void mark();
    49 
    5051        virtual bool isVariableObject() const;
    5152        virtual bool isDynamicScope() const = 0;
     
    5354        virtual bool getPropertyAttributes(ExecState*, const Identifier& propertyName, unsigned& attributes) const;
    5455
     56        JSValue*& valueAt(int index) const { return registers()[index].u.jsValue; }
    5557    protected:
    5658        // Subclasses of JSVariableObject can subclass this struct to add data
     
    5860        // size of a JSCell).
    5961        struct JSVariableObjectData {
    60             JSVariableObjectData() { }
    61             JSVariableObjectData(SymbolTable* s)
    62                 : symbolTable(s) // Subclass owns this pointer.
     62            JSVariableObjectData(SymbolTable* symbolTable_, Register** registerBase_, int registerOffset_)
     63                : symbolTable(symbolTable_)
     64                , registerBase(registerBase_)
     65                , registerOffset(registerOffset_)
    6366            {
     67                ASSERT(symbolTable_);
     68                ASSERT(registerBase_);
    6469            }
    6570
    66             LocalStorage localStorage; // Storage for variables in the symbol table.
    67             SymbolTable* symbolTable; // Maps name -> index in localStorage.
     71            SymbolTable* symbolTable; // Maps name -> offset from "r" in register file.
     72
     73            Register** registerBase; // Location where a pointer to the base of the register file is stored.
     74            int registerOffset; // Offset of "r", the register past the end of local storage.
    6875        };
    69 
    70         JSVariableObject() { }
    7176
    7277        JSVariableObject(JSVariableObjectData* data)
     
    8186        }
    8287
     88        Register** registerBase() const { return d->registerBase; }
     89        Register* registers() const { return *registerBase() + d->registerOffset; }
     90
    8391        bool symbolTableGet(const Identifier&, PropertySlot&);
     92        bool symbolTableGet(const Identifier&, PropertySlot&, bool& slotIsWriteable);
    8493        bool symbolTablePut(const Identifier&, JSValue*);
    8594        bool symbolTablePutWithAttributes(const Identifier&, JSValue*, unsigned attributes);
    86         bool symbolTableInsert(const Identifier&, JSValue*, unsigned attributes);
    8795
    8896        JSVariableObjectData* d;
     
    9199    inline bool JSVariableObject::symbolTableGet(const Identifier& propertyName, PropertySlot& slot)
    92100    {
    93         size_t index = symbolTable().inlineGet(propertyName.ustring().rep());
    94         if (index == missingSymbolMarker())
    95             return false;
    96 #ifndef NDEBUG
    97         // During initialization, the variable object needs to advertise that it has certain
    98         // properties, even if they're not ready for access yet. This check verifies that
    99         // no one tries to access such a property. In a release build, we optimize this check
    100         // away and just return an invalid pointer. There's no harm in an invalid pointer,
    101         // since no one dereferences it.
    102         if (index >= d->localStorage.size()) {
    103             slot.setUngettable(this);
     101        SymbolTableEntry entry = symbolTable().inlineGet(propertyName.ustring().rep());
     102        if (!entry.isEmpty()) {
     103            slot.setValueSlot(this, &valueAt(entry.getIndex()));
    104104            return true;
    105105        }
    106 #endif
    107         slot.setValueSlot(this, &d->localStorage[index].value);
    108         return true;
     106        return false;
     107    }
     108
     109    inline bool JSVariableObject::symbolTableGet(const Identifier& propertyName, PropertySlot& slot, bool& slotIsWriteable)
     110    {
     111        SymbolTableEntry entry = symbolTable().inlineGet(propertyName.ustring().rep());
     112        if (!entry.isEmpty()) {
     113            slot.setValueSlot(this, &valueAt(entry.getIndex()));
     114            slotIsWriteable = !entry.isReadOnly();
     115            return true;
     116        }
     117        return false;
    109118    }
    110119
    111120    inline bool JSVariableObject::symbolTablePut(const Identifier& propertyName, JSValue* value)
    112121    {
    113         size_t index = symbolTable().inlineGet(propertyName.ustring().rep());
    114         if (index == missingSymbolMarker())
     122        SymbolTableEntry entry = symbolTable().inlineGet(propertyName.ustring().rep());
     123        if (entry.isEmpty())
    115124            return false;
    116         LocalStorageEntry& entry = d->localStorage[index];
    117         if (entry.attributes & ReadOnly)
     125        if (entry.isReadOnly())
    118126            return true;
    119         entry.value = value;
     127        valueAt(entry.getIndex()) = value;
    120128        return true;
    121129    }
     
    123131    inline bool JSVariableObject::symbolTablePutWithAttributes(const Identifier& propertyName, JSValue* value, unsigned attributes)
    124132    {
    125         size_t index = symbolTable().get(propertyName.ustring().rep());
    126         if (index == missingSymbolMarker())
     133        SymbolTable::iterator iter = symbolTable().find(propertyName.ustring().rep());
     134        if (iter == symbolTable().end())
    127135            return false;
    128         LocalStorageEntry& entry = d->localStorage[index];
    129         entry.value = value;
    130         entry.attributes = attributes;
    131         return true;
    132     }
    133 
    134     inline bool JSVariableObject::symbolTableInsert(const Identifier& propertyName, JSValue* value, unsigned attributes)
    135     {
    136         if (symbolTable().get(propertyName.ustring().rep()) != missingSymbolMarker())
    137             return false;
    138         size_t localStorageIndex = d->localStorage.size();
    139         d->localStorage.append(LocalStorageEntry(value, attributes));
    140         symbolTable().add(propertyName.ustring().rep(), localStorageIndex);
     136        SymbolTableEntry& entry = iter->second;
     137        ASSERT(!entry.isEmpty());
     138        entry.setAttributes(attributes);
     139        valueAt(entry.getIndex()) = value;
    141140        return true;
    142141    }
Note: See TracChangeset for help on using the changeset viewer.