fix logic
[personal-kdelibs.git] / kjs / property_slot.h
blobd59d0a66acb5837c82dddc67739a7ba862f22a67
1 // -*- c-basic-offset: 4 -*-
2 /*
3 * This file is part of the KDE libraries
4 * Copyright (C) 2005 Apple Computer, Inc.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
23 #ifndef KJS_PROPERTY_SLOT_H
24 #define KJS_PROPERTY_SLOT_H
26 #include <assert.h>
27 #include "identifier.h"
28 #include "value.h"
30 namespace KJS {
32 struct HashEntry;
33 class ExecState;
34 class JSObject;
36 #define VALUE_SLOT_MARKER ((GetValueFunc)1)
37 class KJS_EXPORT PropertySlot
39 public:
40 typedef JSValue *(*GetValueFunc)(ExecState *, JSObject *originalObject, const Identifier&, const PropertySlot&);
42 JSValue *getValue(ExecState *exec, JSObject *originalObject, const Identifier& propertyName) const
44 if (m_getValue == VALUE_SLOT_MARKER)
45 return *m_data.valueSlot;
46 return m_getValue(exec, originalObject, propertyName, *this);
49 JSValue *getValue(ExecState *exec, JSObject *originalObject, unsigned propertyName) const
51 if (m_getValue == VALUE_SLOT_MARKER)
52 return *m_data.valueSlot;
53 return m_getValue(exec, originalObject, Identifier::from(propertyName), *this);
56 void setValueSlot(JSObject *slotBase, JSValue **valueSlot)
58 m_slotBase = slotBase;
59 m_data.valueSlot = valueSlot;
60 m_getValue = VALUE_SLOT_MARKER;
63 void setStaticEntry(JSObject *slotBase, const HashEntry *staticEntry, GetValueFunc getValue)
65 assert(getValue);
66 m_slotBase = slotBase;
67 m_data.staticEntry = staticEntry;
68 m_getValue = getValue;
71 void setCustom(JSObject *slotBase, GetValueFunc getValue)
73 assert(getValue);
74 m_slotBase = slotBase;
75 m_getValue = getValue;
78 void setCustomIndex(JSObject *slotBase, unsigned index, GetValueFunc getValue)
80 assert(getValue);
81 m_slotBase = slotBase;
82 m_data.index = index;
83 m_getValue = getValue;
86 void setCustomValue(JSObject *slotBase, void* value, GetValueFunc getValue)
88 assert(getValue);
89 m_slotBase = slotBase;
90 m_data.value = value;
91 m_getValue = getValue;
94 void setGetterSlot(JSObject *slotBase, JSObject *getterFunc)
96 m_getValue = functionGetter;
97 m_slotBase = slotBase;
98 m_data.getterFunc = getterFunc;
101 void setUndefined(JSObject *slotBase)
103 m_slotBase = slotBase;
104 m_getValue = undefinedGetter;
107 JSObject *slotBase() const { return m_slotBase; }
109 const HashEntry *staticEntry() const { return m_data.staticEntry; }
110 unsigned index() const { return m_data.index; }
111 void* customValue() const { return m_data.value; }
113 private:
114 static JSValue *undefinedGetter(ExecState *, JSObject *, const Identifier&, const PropertySlot&);
115 static JSValue *functionGetter(ExecState *, JSObject *, const Identifier&, const PropertySlot&);
117 GetValueFunc m_getValue;
119 JSObject *m_slotBase;
120 union {
121 JSObject *getterFunc;
122 JSValue **valueSlot;
123 const HashEntry *staticEntry;
124 unsigned index;
125 void* value;
126 } m_data;
131 #endif // KJS_PROPERTY_SLOT_H