]> git.saurik.com Git - apple/javascriptcore.git/blob - runtime/ClassInfo.h
JavaScriptCore-1218.34.tar.gz
[apple/javascriptcore.git] / runtime / ClassInfo.h
1 /*
2 * Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
3 * Copyright (C) 2001 Peter Kelly (pmk@post.com)
4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
5 *
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.
10 *
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.
15 *
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.
20 *
21 */
22
23 #ifndef ClassInfo_h
24 #define ClassInfo_h
25
26 #include "CallFrame.h"
27 #include "ConstructData.h"
28 #include "JSCell.h"
29
30 namespace JSC {
31
32 class HashEntry;
33 struct HashTable;
34
35 struct MethodTable {
36 typedef void (*DestroyFunctionPtr)(JSCell*);
37 DestroyFunctionPtr destroy;
38
39 typedef void (*VisitChildrenFunctionPtr)(JSCell*, SlotVisitor&);
40 VisitChildrenFunctionPtr visitChildren;
41
42 typedef void (*CopyBackingStoreFunctionPtr)(JSCell*, CopyVisitor&);
43 CopyBackingStoreFunctionPtr copyBackingStore;
44
45 typedef CallType (*GetCallDataFunctionPtr)(JSCell*, CallData&);
46 GetCallDataFunctionPtr getCallData;
47
48 typedef ConstructType (*GetConstructDataFunctionPtr)(JSCell*, ConstructData&);
49 GetConstructDataFunctionPtr getConstructData;
50
51 typedef void (*PutFunctionPtr)(JSCell*, ExecState*, PropertyName propertyName, JSValue, PutPropertySlot&);
52 PutFunctionPtr put;
53
54 typedef void (*PutByIndexFunctionPtr)(JSCell*, ExecState*, unsigned propertyName, JSValue, bool shouldThrow);
55 PutByIndexFunctionPtr putByIndex;
56
57 typedef bool (*DeletePropertyFunctionPtr)(JSCell*, ExecState*, PropertyName);
58 DeletePropertyFunctionPtr deleteProperty;
59
60 typedef bool (*DeletePropertyByIndexFunctionPtr)(JSCell*, ExecState*, unsigned);
61 DeletePropertyByIndexFunctionPtr deletePropertyByIndex;
62
63 typedef bool (*GetOwnPropertySlotFunctionPtr)(JSCell*, ExecState*, PropertyName, PropertySlot&);
64 GetOwnPropertySlotFunctionPtr getOwnPropertySlot;
65
66 typedef bool (*GetOwnPropertySlotByIndexFunctionPtr)(JSCell*, ExecState*, unsigned, PropertySlot&);
67 GetOwnPropertySlotByIndexFunctionPtr getOwnPropertySlotByIndex;
68
69 typedef JSObject* (*ToThisObjectFunctionPtr)(JSCell*, ExecState*);
70 ToThisObjectFunctionPtr toThisObject;
71
72 typedef JSValue (*DefaultValueFunctionPtr)(const JSObject*, ExecState*, PreferredPrimitiveType);
73 DefaultValueFunctionPtr defaultValue;
74
75 typedef void (*GetOwnPropertyNamesFunctionPtr)(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode);
76 GetOwnPropertyNamesFunctionPtr getOwnPropertyNames;
77
78 typedef void (*GetOwnNonIndexPropertyNamesFunctionPtr)(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode);
79 GetOwnNonIndexPropertyNamesFunctionPtr getOwnNonIndexPropertyNames;
80
81 typedef void (*GetPropertyNamesFunctionPtr)(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode);
82 GetPropertyNamesFunctionPtr getPropertyNames;
83
84 typedef String (*ClassNameFunctionPtr)(const JSObject*);
85 ClassNameFunctionPtr className;
86
87 typedef bool (*CustomHasInstanceFunctionPtr)(JSObject*, ExecState*, JSValue);
88 CustomHasInstanceFunctionPtr customHasInstance;
89
90 typedef void (*PutWithAttributesFunctionPtr)(JSObject*, ExecState*, PropertyName propertyName, JSValue, unsigned attributes);
91 PutWithAttributesFunctionPtr putDirectVirtual;
92
93 typedef bool (*DefineOwnPropertyFunctionPtr)(JSObject*, ExecState*, PropertyName, PropertyDescriptor&, bool);
94 DefineOwnPropertyFunctionPtr defineOwnProperty;
95
96 typedef bool (*GetOwnPropertyDescriptorFunctionPtr)(JSObject*, ExecState*, PropertyName, PropertyDescriptor&);
97 GetOwnPropertyDescriptorFunctionPtr getOwnPropertyDescriptor;
98 };
99
100 #define CREATE_MEMBER_CHECKER(member) \
101 template <typename T> \
102 struct MemberCheck##member { \
103 struct Fallback { \
104 void member(...); \
105 }; \
106 struct Derived : T, Fallback { }; \
107 template <typename U, U> struct Check; \
108 typedef char Yes[2]; \
109 typedef char No[1]; \
110 template <typename U> \
111 static No &func(Check<void (Fallback::*)(...), &U::member>*); \
112 template <typename U> \
113 static Yes &func(...); \
114 enum { has = sizeof(func<Derived>(0)) == sizeof(Yes) }; \
115 }
116
117 #define HAS_MEMBER_NAMED(klass, name) (MemberCheck##name<klass>::has)
118
119 #define CREATE_METHOD_TABLE(ClassName) { \
120 &ClassName::destroy, \
121 &ClassName::visitChildren, \
122 &ClassName::copyBackingStore, \
123 &ClassName::getCallData, \
124 &ClassName::getConstructData, \
125 &ClassName::put, \
126 &ClassName::putByIndex, \
127 &ClassName::deleteProperty, \
128 &ClassName::deletePropertyByIndex, \
129 &ClassName::getOwnPropertySlot, \
130 &ClassName::getOwnPropertySlotByIndex, \
131 &ClassName::toThisObject, \
132 &ClassName::defaultValue, \
133 &ClassName::getOwnPropertyNames, \
134 &ClassName::getOwnNonIndexPropertyNames, \
135 &ClassName::getPropertyNames, \
136 &ClassName::className, \
137 &ClassName::customHasInstance, \
138 &ClassName::putDirectVirtual, \
139 &ClassName::defineOwnProperty, \
140 &ClassName::getOwnPropertyDescriptor, \
141 }, \
142 ClassName::TypedArrayStorageType
143
144 struct ClassInfo {
145 /**
146 * A string denoting the class name. Example: "Window".
147 */
148 const char* className;
149
150 /**
151 * Pointer to the class information of the base class.
152 * 0L if there is none.
153 */
154 const ClassInfo* parentClass;
155 /**
156 * Static hash-table of properties.
157 * For classes that can be used from multiple threads, it is accessed via a getter function that would typically return a pointer to thread-specific value.
158 */
159 const HashTable* propHashTable(ExecState* exec) const
160 {
161 if (classPropHashTableGetterFunction)
162 return classPropHashTableGetterFunction(exec);
163 return staticPropHashTable;
164 }
165
166 bool isSubClassOf(const ClassInfo* other) const
167 {
168 for (const ClassInfo* ci = this; ci; ci = ci->parentClass) {
169 if (ci == other)
170 return true;
171 }
172 return false;
173 }
174
175 bool hasStaticProperties() const
176 {
177 for (const ClassInfo* ci = this; ci; ci = ci->parentClass) {
178 if (ci->staticPropHashTable || ci->classPropHashTableGetterFunction)
179 return true;
180 }
181 return false;
182 }
183
184 const HashTable* staticPropHashTable;
185 typedef const HashTable* (*ClassPropHashTableGetterFunction)(ExecState*);
186 const ClassPropHashTableGetterFunction classPropHashTableGetterFunction;
187
188 MethodTable methodTable;
189
190 TypedArrayType typedArrayStorageType;
191 };
192
193 } // namespace JSC
194
195 #endif // ClassInfo_h