Changeset 33979 in webkit for trunk/JavaScriptCore/kjs/JSVariableObject.h
- Timestamp:
- May 21, 2008, 6:20:45 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/JSVariableObject.h
r32652 r33979 30 30 #define JSVariableObject_h 31 31 32 #include " LocalStorageEntry.h"32 #include "Register.h" 33 33 #include "SymbolTable.h" 34 #include "UnusedParam.h" 34 35 #include "object.h" 36 #include <wtf/UnusedParam.h> 35 37 36 38 namespace KJS { 39 40 class Register; 37 41 38 42 class JSVariableObject : public JSObject { 39 43 public: 40 44 SymbolTable& symbolTable() const { return *d->symbolTable; } 41 LocalStorage& localStorage() const { return d->localStorage; }42 45 43 46 virtual void putWithAttributes(ExecState*, const Identifier&, JSValue*, unsigned attributes) = 0; … … 46 49 virtual void getPropertyNames(ExecState*, PropertyNameArray&); 47 50 48 virtual void mark();49 50 51 virtual bool isVariableObject() const; 51 52 virtual bool isDynamicScope() const = 0; … … 53 54 virtual bool getPropertyAttributes(ExecState*, const Identifier& propertyName, unsigned& attributes) const; 54 55 56 JSValue*& valueAt(int index) const { return registers()[index].u.jsValue; } 55 57 protected: 56 58 // Subclasses of JSVariableObject can subclass this struct to add data … … 58 60 // size of a JSCell). 59 61 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_) 63 66 { 67 ASSERT(symbolTable_); 68 ASSERT(registerBase_); 64 69 } 65 70 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. 68 75 }; 69 70 JSVariableObject() { }71 76 72 77 JSVariableObject(JSVariableObjectData* data) … … 81 86 } 82 87 88 Register** registerBase() const { return d->registerBase; } 89 Register* registers() const { return *registerBase() + d->registerOffset; } 90 83 91 bool symbolTableGet(const Identifier&, PropertySlot&); 92 bool symbolTableGet(const Identifier&, PropertySlot&, bool& slotIsWriteable); 84 93 bool symbolTablePut(const Identifier&, JSValue*); 85 94 bool symbolTablePutWithAttributes(const Identifier&, JSValue*, unsigned attributes); 86 bool symbolTableInsert(const Identifier&, JSValue*, unsigned attributes);87 95 88 96 JSVariableObjectData* d; … … 91 99 inline bool JSVariableObject::symbolTableGet(const Identifier& propertyName, PropertySlot& slot) 92 100 { 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())); 104 104 return true; 105 105 } 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; 109 118 } 110 119 111 120 inline bool JSVariableObject::symbolTablePut(const Identifier& propertyName, JSValue* value) 112 121 { 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()) 115 124 return false; 116 LocalStorageEntry& entry = d->localStorage[index]; 117 if (entry.attributes & ReadOnly) 125 if (entry.isReadOnly()) 118 126 return true; 119 entry.value= value;127 valueAt(entry.getIndex()) = value; 120 128 return true; 121 129 } … … 123 131 inline bool JSVariableObject::symbolTablePutWithAttributes(const Identifier& propertyName, JSValue* value, unsigned attributes) 124 132 { 125 size_t index = symbolTable().get(propertyName.ustring().rep());126 if (i ndex == missingSymbolMarker())133 SymbolTable::iterator iter = symbolTable().find(propertyName.ustring().rep()); 134 if (iter == symbolTable().end()) 127 135 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; 141 140 return true; 142 141 }
Note:
See TracChangeset
for help on using the changeset viewer.