source: webkit/trunk/JavaScriptCore/kjs/JSVariableObject.h@ 37428

Last change on this file since 37428 was 37428, checked in by [email protected], 17 years ago

Roll out r37427 because it causes an infinite recursion loading about:blank.

https://bugs.webkit.org/show_bug.cgi?id=21476

  • Property svn:eol-style set to native
File size: 6.7 KB
Line 
1/*
2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifndef JSVariableObject_h
30#define JSVariableObject_h
31
32#include "JSObject.h"
33#include "Register.h"
34#include "SymbolTable.h"
35#include "UnusedParam.h"
36#include <wtf/OwnArrayPtr.h>
37#include <wtf/UnusedParam.h>
38
39namespace JSC {
40
41 class Register;
42
43 class JSVariableObject : public JSObject {
44 public:
45 SymbolTable& symbolTable() const { return *d->symbolTable; }
46
47 virtual void putWithAttributes(ExecState*, const Identifier&, JSValue*, unsigned attributes) = 0;
48
49 virtual bool deleteProperty(ExecState*, const Identifier&);
50 virtual void getPropertyNames(ExecState*, PropertyNameArray&);
51
52 virtual bool isVariableObject() const;
53 virtual bool isDynamicScope() const = 0;
54
55 virtual bool getPropertyAttributes(ExecState*, const Identifier& propertyName, unsigned& attributes) const;
56
57 Register& registerAt(int index) const { return d->registers[index]; }
58
59 protected:
60 // Subclasses of JSVariableObject can subclass this struct to add data
61 // without increasing their own size (since there's a hard limit on the
62 // size of a JSCell).
63 struct JSVariableObjectData {
64 JSVariableObjectData(SymbolTable* symbolTable_, Register* registers_)
65 : symbolTable(symbolTable_)
66 , registers(registers_)
67 {
68 ASSERT(symbolTable_);
69 }
70
71 SymbolTable* symbolTable; // Maps name -> offset from "r" in register file.
72 Register* registers; // "r" in the register file.
73 OwnArrayPtr<Register> registerArray; // Independent copy of registers, used when a variable object copies its registers out of the register file.
74
75 static inline ptrdiff_t offsetOf_registers()
76 {
77 return OBJECT_OFFSET(JSVariableObjectData, registers);
78 }
79
80 private:
81 JSVariableObjectData(const JSVariableObjectData&);
82 JSVariableObjectData& operator=(const JSVariableObjectData&);
83 };
84
85 JSVariableObject(PassRefPtr<StructureID> structureID, JSVariableObjectData* data)
86 : JSObject(structureID)
87 , d(data) // Subclass owns this pointer.
88 {
89 }
90
91 Register* copyRegisterArray(Register* src, size_t count);
92 void setRegisters(Register* r, Register* registerArray);
93
94 bool symbolTableGet(const Identifier&, PropertySlot&);
95 bool symbolTableGet(const Identifier&, PropertySlot&, bool& slotIsWriteable);
96 bool symbolTablePut(const Identifier&, JSValue*);
97 bool symbolTablePutWithAttributes(const Identifier&, JSValue*, unsigned attributes);
98
99 JSVariableObjectData* d;
100
101 public:
102 static inline ptrdiff_t offsetOf_d()
103 {
104 return OBJECT_OFFSET(JSVariableObject, d);
105 }
106
107 static inline ptrdiff_t offsetOf_Data_registers()
108 {
109 return JSVariableObjectData::offsetOf_registers();
110 }
111 };
112
113 inline bool JSVariableObject::symbolTableGet(const Identifier& propertyName, PropertySlot& slot)
114 {
115 SymbolTableEntry entry = symbolTable().inlineGet(propertyName.ustring().rep());
116 if (!entry.isNull()) {
117 slot.setRegisterSlot(&registerAt(entry.getIndex()));
118 return true;
119 }
120 return false;
121 }
122
123 inline bool JSVariableObject::symbolTableGet(const Identifier& propertyName, PropertySlot& slot, bool& slotIsWriteable)
124 {
125 SymbolTableEntry entry = symbolTable().inlineGet(propertyName.ustring().rep());
126 if (!entry.isNull()) {
127 slot.setRegisterSlot(&registerAt(entry.getIndex()));
128 slotIsWriteable = !entry.isReadOnly();
129 return true;
130 }
131 return false;
132 }
133
134 inline bool JSVariableObject::symbolTablePut(const Identifier& propertyName, JSValue* value)
135 {
136 ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));
137
138 SymbolTableEntry entry = symbolTable().inlineGet(propertyName.ustring().rep());
139 if (entry.isNull())
140 return false;
141 if (entry.isReadOnly())
142 return true;
143 registerAt(entry.getIndex()) = value;
144 return true;
145 }
146
147 inline bool JSVariableObject::symbolTablePutWithAttributes(const Identifier& propertyName, JSValue* value, unsigned attributes)
148 {
149 ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));
150
151 SymbolTable::iterator iter = symbolTable().find(propertyName.ustring().rep());
152 if (iter == symbolTable().end())
153 return false;
154 SymbolTableEntry& entry = iter->second;
155 ASSERT(!entry.isNull());
156 entry.setAttributes(attributes);
157 registerAt(entry.getIndex()) = value;
158 return true;
159 }
160
161 inline Register* JSVariableObject::copyRegisterArray(Register* src, size_t count)
162 {
163 Register* registerArray = new Register[count];
164 memcpy(registerArray, src, count * sizeof(Register));
165
166 return registerArray;
167 }
168
169 inline void JSVariableObject::setRegisters(Register* registers, Register* registerArray)
170 {
171 ASSERT(registerArray != d->registerArray.get());
172 d->registerArray.set(registerArray);
173 d->registers = registers;
174 }
175
176} // namespace JSC
177
178#endif // JSVariableObject_h
Note: See TracBrowser for help on using the repository browser.