]>
git.saurik.com Git - apple/javascriptcore.git/blob - runtime/PropertySlot.h
2 * Copyright (C) 2005, 2007, 2008 Apple Inc. All rights reserved.
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.
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.
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.
21 #ifndef PropertySlot_h
22 #define PropertySlot_h
24 #include "Identifier.h"
27 #include <wtf/Assertions.h>
28 #include <wtf/NotFound.h>
35 #define JSC_VALUE_SLOT_MARKER 0
36 #define JSC_REGISTER_SLOT_MARKER reinterpret_cast<GetValueFunc>(1)
47 explicit PropertySlot(const JSValue base
)
54 typedef JSValue (*GetValueFunc
)(ExecState
*, const Identifier
&, const PropertySlot
&);
56 JSValue
getValue(ExecState
* exec
, const Identifier
& propertyName
) const
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();
62 return m_getValue(exec
, propertyName
, *this);
65 JSValue
getValue(ExecState
* exec
, unsigned propertyName
) const
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();
71 return m_getValue(exec
, Identifier::from(exec
, propertyName
), *this);
74 bool isCacheable() const { return m_offset
!= WTF::notFound
; }
75 size_t cachedOffset() const
77 ASSERT(isCacheable());
81 void setValueSlot(JSValue
* valueSlot
)
86 m_getValue
= JSC_VALUE_SLOT_MARKER
;
87 m_data
.valueSlot
= valueSlot
;
90 void setValueSlot(JSValue slotBase
, JSValue
* valueSlot
)
93 m_getValue
= JSC_VALUE_SLOT_MARKER
;
94 m_slotBase
= slotBase
;
95 m_data
.valueSlot
= valueSlot
;
98 void setValueSlot(JSValue slotBase
, JSValue
* valueSlot
, size_t offset
)
101 m_getValue
= JSC_VALUE_SLOT_MARKER
;
102 m_slotBase
= slotBase
;
103 m_data
.valueSlot
= valueSlot
;
107 void setValue(JSValue value
)
112 m_getValue
= JSC_VALUE_SLOT_MARKER
;
114 m_data
.valueSlot
= &m_value
;
117 void setRegisterSlot(Register
* registerSlot
)
119 ASSERT(registerSlot
);
122 m_getValue
= JSC_REGISTER_SLOT_MARKER
;
123 m_data
.registerSlot
= registerSlot
;
126 void setCustom(JSValue slotBase
, GetValueFunc getValue
)
130 m_getValue
= getValue
;
131 m_slotBase
= slotBase
;
134 void setCustomIndex(JSValue slotBase
, unsigned index
, GetValueFunc getValue
)
138 m_getValue
= getValue
;
139 m_slotBase
= slotBase
;
140 m_data
.index
= index
;
143 void setGetterSlot(JSObject
* getterFunc
)
146 m_getValue
= functionGetter
;
147 m_data
.getterFunc
= getterFunc
;
152 setValue(jsUndefined());
155 JSValue
slotBase() const
160 void setBase(JSValue base
)
170 m_slotBase
= JSValue();
183 // Clear offset even in release builds, in case this PropertySlot has been used before.
184 // (For other data members, we don't need to clear anything because reuse would meaningfully overwrite them.)
185 m_offset
= WTF::notFound
;
188 unsigned index() const { return m_data
.index
; }
191 static JSValue
functionGetter(ExecState
*, const Identifier
&, const PropertySlot
&);
193 GetValueFunc m_getValue
;
197 JSObject
* getterFunc
;
199 Register
* registerSlot
;
210 #endif // PropertySlot_h