1 // -*- c-basic-offset: 4 -*-
3 * Copyright (C) 2005, 2007 Apple Inc. All rights reserved.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
22 #ifndef KJS_PROPERTY_SLOT_H
23 #define KJS_PROPERTY_SLOT_H
25 #include "identifier.h"
27 #include <wtf/Assertions.h>
36 #define KJS_VALUE_SLOT_MARKER 0
37 #define KJS_NUMERIC_PROPERTY_NAME_SLOT_MARKER reinterpret_cast<GetValueFunc>(1)
41 typedef JSValue
* (*GetValueFunc
)(ExecState
*, JSObject
* originalObject
, const Identifier
&, const PropertySlot
&);
42 typedef JSValue
* (*GetValueNumericFunc
)(ExecState
*, JSObject
* originalObject
, unsigned index
, const PropertySlot
&);
44 JSValue
* getValue(ExecState
* exec
, JSObject
* originalObject
, const Identifier
& propertyName
) const
46 if (m_getValue
== KJS_VALUE_SLOT_MARKER
)
47 return *m_data
.valueSlot
;
48 ASSERT(m_getValue
!= KJS_NUMERIC_PROPERTY_NAME_SLOT_MARKER
);
49 return m_getValue(exec
, originalObject
, propertyName
, *this);
52 JSValue
* getValue(ExecState
* exec
, JSObject
* originalObject
, unsigned propertyName
) const
54 if (m_getValue
== KJS_VALUE_SLOT_MARKER
)
55 return *m_data
.valueSlot
;
56 if (m_getValue
== KJS_NUMERIC_PROPERTY_NAME_SLOT_MARKER
)
57 return m_data
.numericFunc(exec
, originalObject
, propertyName
, *this);
58 return m_getValue(exec
, originalObject
, Identifier::from(propertyName
), *this);
61 void setValueSlot(JSObject
* slotBase
, JSValue
** valueSlot
)
63 m_getValue
= KJS_VALUE_SLOT_MARKER
;
64 m_slotBase
= slotBase
;
65 m_data
.valueSlot
= valueSlot
;
68 void setStaticEntry(JSObject
* slotBase
, const HashEntry
* staticEntry
, GetValueFunc getValue
)
71 m_getValue
= getValue
;
72 m_slotBase
= slotBase
;
73 m_data
.staticEntry
= staticEntry
;
76 void setCustom(JSObject
* slotBase
, GetValueFunc getValue
)
79 m_getValue
= getValue
;
80 m_slotBase
= slotBase
;
83 void setCustomIndex(JSObject
* slotBase
, unsigned index
, GetValueFunc getValue
)
86 m_getValue
= getValue
;
87 m_slotBase
= slotBase
;
91 void setCustomNumeric(JSObject
* slotBase
, GetValueNumericFunc getValue
)
94 m_slotBase
= slotBase
;
95 m_getValue
= KJS_NUMERIC_PROPERTY_NAME_SLOT_MARKER
;
96 m_data
.numericFunc
= getValue
;
99 void setGetterSlot(JSObject
* slotBase
, JSObject
* getterFunc
)
101 m_getValue
= functionGetter
;
102 m_slotBase
= slotBase
;
103 m_data
.getterFunc
= getterFunc
;
106 void setUndefined(JSObject
*slotBase
)
108 m_slotBase
= slotBase
;
109 m_getValue
= undefinedGetter
;
112 void setUngettable(JSObject
* slotBase
) // Used to signal that you have a property, but trying to get it at this time is an error.
114 m_slotBase
= slotBase
;
115 m_getValue
= ungettableGetter
;
118 JSObject
* slotBase() const { return m_slotBase
; }
120 const HashEntry
* staticEntry() const { return m_data
.staticEntry
; }
121 unsigned index() const { return m_data
.index
; }
124 static JSValue
* undefinedGetter(ExecState
*, JSObject
*, const Identifier
&, const PropertySlot
&);
125 static JSValue
* ungettableGetter(ExecState
*, JSObject
*, const Identifier
&, const PropertySlot
&);
126 static JSValue
* functionGetter(ExecState
*, JSObject
*, const Identifier
&, const PropertySlot
&);
128 GetValueFunc m_getValue
;
130 JSObject
* m_slotBase
;
132 JSObject
* getterFunc
;
134 const HashEntry
* staticEntry
;
136 GetValueNumericFunc numericFunc
;
142 #endif // KJS_PROPERTY_SLOT_H