1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
/*
* Copyright (C) 2005, 2007, 2008 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#ifndef PropertySlot_h
#define PropertySlot_h
#include "Identifier.h"
#include "JSValue.h"
#include "Register.h"
#include <wtf/Assertions.h>
#include <wtf/NotFound.h>
namespace JSC {
class ExecState;
class JSObject;
#define JSC_VALUE_SLOT_MARKER 0
#define JSC_REGISTER_SLOT_MARKER reinterpret_cast<GetValueFunc>(1)
class PropertySlot {
public:
PropertySlot()
{
clearBase();
clearOffset();
clearValue();
}
explicit PropertySlot(const JSValue base)
: m_slotBase(base)
{
clearOffset();
clearValue();
}
typedef JSValue (*GetValueFunc)(ExecState*, const Identifier&, const PropertySlot&);
JSValue getValue(ExecState* exec, const Identifier& propertyName) const
{
if (m_getValue == JSC_VALUE_SLOT_MARKER)
return *m_data.valueSlot;
if (m_getValue == JSC_REGISTER_SLOT_MARKER)
return (*m_data.registerSlot).jsValue();
return m_getValue(exec, propertyName, *this);
}
JSValue getValue(ExecState* exec, unsigned propertyName) const
{
if (m_getValue == JSC_VALUE_SLOT_MARKER)
return *m_data.valueSlot;
if (m_getValue == JSC_REGISTER_SLOT_MARKER)
return (*m_data.registerSlot).jsValue();
return m_getValue(exec, Identifier::from(exec, propertyName), *this);
}
bool isCacheable() const { return m_offset != WTF::notFound; }
size_t cachedOffset() const
{
ASSERT(isCacheable());
return m_offset;
}
void setValueSlot(JSValue* valueSlot)
{
ASSERT(valueSlot);
clearBase();
clearOffset();
m_getValue = JSC_VALUE_SLOT_MARKER;
m_data.valueSlot = valueSlot;
}
void setValueSlot(JSValue slotBase, JSValue* valueSlot)
{
ASSERT(valueSlot);
m_getValue = JSC_VALUE_SLOT_MARKER;
m_slotBase = slotBase;
m_data.valueSlot = valueSlot;
}
void setValueSlot(JSValue slotBase, JSValue* valueSlot, size_t offset)
{
ASSERT(valueSlot);
m_getValue = JSC_VALUE_SLOT_MARKER;
m_slotBase = slotBase;
m_data.valueSlot = valueSlot;
m_offset = offset;
}
void setValue(JSValue value)
{
ASSERT(value);
clearBase();
clearOffset();
m_getValue = JSC_VALUE_SLOT_MARKER;
m_value = value;
m_data.valueSlot = &m_value;
}
void setRegisterSlot(Register* registerSlot)
{
ASSERT(registerSlot);
clearBase();
clearOffset();
m_getValue = JSC_REGISTER_SLOT_MARKER;
m_data.registerSlot = registerSlot;
}
void setCustom(JSValue slotBase, GetValueFunc getValue)
{
ASSERT(slotBase);
ASSERT(getValue);
m_getValue = getValue;
m_slotBase = slotBase;
}
void setCustomIndex(JSValue slotBase, unsigned index, GetValueFunc getValue)
{
ASSERT(slotBase);
ASSERT(getValue);
m_getValue = getValue;
m_slotBase = slotBase;
m_data.index = index;
}
void setGetterSlot(JSObject* getterFunc)
{
ASSERT(getterFunc);
m_getValue = functionGetter;
m_data.getterFunc = getterFunc;
}
void setUndefined()
{
setValue(jsUndefined());
}
JSValue slotBase() const
{
return m_slotBase;
}
void setBase(JSValue base)
{
ASSERT(m_slotBase);
ASSERT(base);
m_slotBase = base;
}
void clearBase()
{
#ifndef NDEBUG
m_slotBase = JSValue();
#endif
}
void clearValue()
{
#ifndef NDEBUG
m_value = JSValue();
#endif
}
void clearOffset()
{
// Clear offset even in release builds, in case this PropertySlot has been used before.
// (For other data members, we don't need to clear anything because reuse would meaningfully overwrite them.)
m_offset = WTF::notFound;
}
unsigned index() const { return m_data.index; }
private:
static JSValue functionGetter(ExecState*, const Identifier&, const PropertySlot&);
GetValueFunc m_getValue;
JSValue m_slotBase;
union {
JSObject* getterFunc;
JSValue* valueSlot;
Register* registerSlot;
unsigned index;
} m_data;
JSValue m_value;
size_t m_offset;
};
} // namespace JSC
#endif // PropertySlot_h
|