source: webkit/trunk/JavaScriptCore/runtime/PropertySlot.h@ 38528

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

2008-11-05 Cameron Zwarich <[email protected]>

Not reviewed.

Fix the build for case-sensitive build systems.

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