0
|
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 |
|
|
39 |
namespace JSC {
|
|
40 |
|
|
41 |
class Register;
|
|
42 |
|
|
43 |
class JSVariableObject : public JSObject {
|
|
44 |
friend class JIT;
|
|
45 |
|
|
46 |
public:
|
|
47 |
SymbolTable& symbolTable() const { return *d->symbolTable; }
|
|
48 |
|
|
49 |
virtual void putWithAttributes(ExecState*, const Identifier&, JSValue, unsigned attributes) = 0;
|
|
50 |
|
|
51 |
virtual bool deleteProperty(ExecState*, const Identifier&);
|
|
52 |
virtual void getOwnPropertyNames(ExecState*, PropertyNameArray&);
|
|
53 |
|
|
54 |
virtual bool isVariableObject() const;
|
|
55 |
virtual bool isDynamicScope() const = 0;
|
|
56 |
|
|
57 |
virtual bool getPropertyAttributes(ExecState*, const Identifier& propertyName, unsigned& attributes) const;
|
|
58 |
|
|
59 |
Register& registerAt(int index) const { return d->registers[index]; }
|
|
60 |
|
|
61 |
static PassRefPtr<Structure> createStructure(JSValue prototype)
|
|
62 |
{
|
|
63 |
return Structure::create(prototype, TypeInfo(ObjectType, StructureFlags));
|
|
64 |
}
|
|
65 |
|
|
66 |
protected:
|
|
67 |
static const unsigned StructureFlags = OverridesGetPropertyNames | JSObject::StructureFlags;
|
|
68 |
// Subclasses of JSVariableObject can subclass this struct to add data
|
|
69 |
// without increasing their own size (since there's a hard limit on the
|
|
70 |
// size of a JSCell).
|
|
71 |
struct JSVariableObjectData {
|
|
72 |
JSVariableObjectData(SymbolTable* symbolTable, Register* registers)
|
|
73 |
: symbolTable(symbolTable)
|
|
74 |
, registers(registers)
|
|
75 |
{
|
|
76 |
ASSERT(symbolTable);
|
|
77 |
}
|
|
78 |
|
|
79 |
SymbolTable* symbolTable; // Maps name -> offset from "r" in register file.
|
|
80 |
Register* registers; // "r" in the register file.
|
|
81 |
OwnArrayPtr<Register> registerArray; // Independent copy of registers, used when a variable object copies its registers out of the register file.
|
|
82 |
|
|
83 |
private:
|
|
84 |
JSVariableObjectData(const JSVariableObjectData&);
|
|
85 |
JSVariableObjectData& operator=(const JSVariableObjectData&);
|
|
86 |
};
|
|
87 |
|
|
88 |
JSVariableObject(NonNullPassRefPtr<Structure> structure, JSVariableObjectData* data)
|
|
89 |
: JSObject(structure)
|
|
90 |
, d(data) // Subclass owns this pointer.
|
|
91 |
{
|
|
92 |
}
|
|
93 |
|
|
94 |
Register* copyRegisterArray(Register* src, size_t count);
|
|
95 |
void setRegisters(Register* r, Register* registerArray);
|
|
96 |
|
|
97 |
bool symbolTableGet(const Identifier&, PropertySlot&);
|
|
98 |
bool symbolTableGet(const Identifier&, PropertyDescriptor&);
|
|
99 |
bool symbolTableGet(const Identifier&, PropertySlot&, bool& slotIsWriteable);
|
|
100 |
bool symbolTablePut(const Identifier&, JSValue);
|
|
101 |
bool symbolTablePutWithAttributes(const Identifier&, JSValue, unsigned attributes);
|
|
102 |
|
|
103 |
JSVariableObjectData* d;
|
|
104 |
};
|
|
105 |
|
|
106 |
inline bool JSVariableObject::symbolTableGet(const Identifier& propertyName, PropertySlot& slot)
|
|
107 |
{
|
|
108 |
SymbolTableEntry entry = symbolTable().inlineGet(propertyName.ustring().rep());
|
|
109 |
if (!entry.isNull()) {
|
|
110 |
slot.setRegisterSlot(®isterAt(entry.getIndex()));
|
|
111 |
return true;
|
|
112 |
}
|
|
113 |
return false;
|
|
114 |
}
|
|
115 |
|
|
116 |
inline bool JSVariableObject::symbolTableGet(const Identifier& propertyName, PropertySlot& slot, bool& slotIsWriteable)
|
|
117 |
{
|
|
118 |
SymbolTableEntry entry = symbolTable().inlineGet(propertyName.ustring().rep());
|
|
119 |
if (!entry.isNull()) {
|
|
120 |
slot.setRegisterSlot(®isterAt(entry.getIndex()));
|
|
121 |
slotIsWriteable = !entry.isReadOnly();
|
|
122 |
return true;
|
|
123 |
}
|
|
124 |
return false;
|
|
125 |
}
|
|
126 |
|
|
127 |
inline bool JSVariableObject::symbolTablePut(const Identifier& propertyName, JSValue value)
|
|
128 |
{
|
|
129 |
ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));
|
|
130 |
|
|
131 |
SymbolTableEntry entry = symbolTable().inlineGet(propertyName.ustring().rep());
|
|
132 |
if (entry.isNull())
|
|
133 |
return false;
|
|
134 |
if (entry.isReadOnly())
|
|
135 |
return true;
|
|
136 |
registerAt(entry.getIndex()) = value;
|
|
137 |
return true;
|
|
138 |
}
|
|
139 |
|
|
140 |
inline bool JSVariableObject::symbolTablePutWithAttributes(const Identifier& propertyName, JSValue value, unsigned attributes)
|
|
141 |
{
|
|
142 |
ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this));
|
|
143 |
|
|
144 |
SymbolTable::iterator iter = symbolTable().find(propertyName.ustring().rep());
|
|
145 |
if (iter == symbolTable().end())
|
|
146 |
return false;
|
|
147 |
SymbolTableEntry& entry = iter->second;
|
|
148 |
ASSERT(!entry.isNull());
|
|
149 |
entry.setAttributes(attributes);
|
|
150 |
registerAt(entry.getIndex()) = value;
|
|
151 |
return true;
|
|
152 |
}
|
|
153 |
|
|
154 |
inline Register* JSVariableObject::copyRegisterArray(Register* src, size_t count)
|
|
155 |
{
|
|
156 |
Register* registerArray = new Register[count];
|
|
157 |
memcpy(registerArray, src, count * sizeof(Register));
|
|
158 |
|
|
159 |
return registerArray;
|
|
160 |
}
|
|
161 |
|
|
162 |
inline void JSVariableObject::setRegisters(Register* registers, Register* registerArray)
|
|
163 |
{
|
|
164 |
ASSERT(registerArray != d->registerArray.get());
|
|
165 |
d->registerArray.set(registerArray);
|
|
166 |
d->registers = registers;
|
|
167 |
}
|
|
168 |
|
|
169 |
} // namespace JSC
|
|
170 |
|
|
171 |
#endif // JSVariableObject_h
|