]> git.saurik.com Git - apple/javascriptcore.git/blame - runtime/ClassInfo.h
JavaScriptCore-1218.0.1.tar.gz
[apple/javascriptcore.git] / runtime / ClassInfo.h
CommitLineData
9dae56ea
A
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"
6fe7ccc8
A
27#include "ConstructData.h"
28#include "JSCell.h"
9dae56ea
A
29
30namespace JSC {
31
93a37866
A
32class HashEntry;
33struct HashTable;
9dae56ea 34
93a37866
A
35struct MethodTable {
36 typedef void (*DestroyFunctionPtr)(JSCell*);
37 DestroyFunctionPtr destroy;
6fe7ccc8 38
93a37866
A
39 typedef void (*VisitChildrenFunctionPtr)(JSCell*, SlotVisitor&);
40 VisitChildrenFunctionPtr visitChildren;
6fe7ccc8 41
93a37866
A
42 typedef void (*CopyBackingStoreFunctionPtr)(JSCell*, CopyVisitor&);
43 CopyBackingStoreFunctionPtr copyBackingStore;
6fe7ccc8 44
93a37866
A
45 typedef CallType (*GetCallDataFunctionPtr)(JSCell*, CallData&);
46 GetCallDataFunctionPtr getCallData;
6fe7ccc8 47
93a37866
A
48 typedef ConstructType (*GetConstructDataFunctionPtr)(JSCell*, ConstructData&);
49 GetConstructDataFunctionPtr getConstructData;
6fe7ccc8 50
93a37866
A
51 typedef void (*PutFunctionPtr)(JSCell*, ExecState*, PropertyName propertyName, JSValue, PutPropertySlot&);
52 PutFunctionPtr put;
6fe7ccc8 53
93a37866
A
54 typedef void (*PutByIndexFunctionPtr)(JSCell*, ExecState*, unsigned propertyName, JSValue, bool shouldThrow);
55 PutByIndexFunctionPtr putByIndex;
6fe7ccc8 56
93a37866
A
57 typedef bool (*DeletePropertyFunctionPtr)(JSCell*, ExecState*, PropertyName);
58 DeletePropertyFunctionPtr deleteProperty;
6fe7ccc8 59
93a37866
A
60 typedef bool (*DeletePropertyByIndexFunctionPtr)(JSCell*, ExecState*, unsigned);
61 DeletePropertyByIndexFunctionPtr deletePropertyByIndex;
6fe7ccc8 62
93a37866
A
63 typedef bool (*GetOwnPropertySlotFunctionPtr)(JSCell*, ExecState*, PropertyName, PropertySlot&);
64 GetOwnPropertySlotFunctionPtr getOwnPropertySlot;
6fe7ccc8 65
93a37866
A
66 typedef bool (*GetOwnPropertySlotByIndexFunctionPtr)(JSCell*, ExecState*, unsigned, PropertySlot&);
67 GetOwnPropertySlotByIndexFunctionPtr getOwnPropertySlotByIndex;
6fe7ccc8 68
93a37866
A
69 typedef JSObject* (*ToThisObjectFunctionPtr)(JSCell*, ExecState*);
70 ToThisObjectFunctionPtr toThisObject;
6fe7ccc8 71
93a37866
A
72 typedef JSValue (*DefaultValueFunctionPtr)(const JSObject*, ExecState*, PreferredPrimitiveType);
73 DefaultValueFunctionPtr defaultValue;
6fe7ccc8 74
93a37866
A
75 typedef void (*GetOwnPropertyNamesFunctionPtr)(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode);
76 GetOwnPropertyNamesFunctionPtr getOwnPropertyNames;
6fe7ccc8 77
93a37866
A
78 typedef void (*GetOwnNonIndexPropertyNamesFunctionPtr)(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode);
79 GetOwnNonIndexPropertyNamesFunctionPtr getOwnNonIndexPropertyNames;
6fe7ccc8 80
93a37866
A
81 typedef void (*GetPropertyNamesFunctionPtr)(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode);
82 GetPropertyNamesFunctionPtr getPropertyNames;
6fe7ccc8 83
93a37866
A
84 typedef String (*ClassNameFunctionPtr)(const JSObject*);
85 ClassNameFunctionPtr className;
6fe7ccc8 86
93a37866
A
87 typedef bool (*CustomHasInstanceFunctionPtr)(JSObject*, ExecState*, JSValue);
88 CustomHasInstanceFunctionPtr customHasInstance;
6fe7ccc8 89
93a37866
A
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};
6fe7ccc8
A
99
100#define CREATE_MEMBER_CHECKER(member) \
93a37866
A
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 }
6fe7ccc8
A
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, \
93a37866 122 &ClassName::copyBackingStore, \
6fe7ccc8
A
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, \
93a37866 134 &ClassName::getOwnNonIndexPropertyNames, \
6fe7ccc8
A
135 &ClassName::getPropertyNames, \
136 &ClassName::className, \
93a37866 137 &ClassName::customHasInstance, \
6fe7ccc8
A
138 &ClassName::putDirectVirtual, \
139 &ClassName::defineOwnProperty, \
140 &ClassName::getOwnPropertyDescriptor, \
141 }, \
142 ClassName::TypedArrayStorageType
143
93a37866
A
144struct 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 }
6fe7ccc8 165
93a37866
A
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;
6fe7ccc8 171 }
93a37866
A
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;
6fe7ccc8 180 }
93a37866
A
181 return false;
182 }
9dae56ea 183
93a37866
A
184 const HashTable* staticPropHashTable;
185 typedef const HashTable* (*ClassPropHashTableGetterFunction)(ExecState*);
186 const ClassPropHashTableGetterFunction classPropHashTableGetterFunction;
6fe7ccc8 187
93a37866 188 MethodTable methodTable;
6fe7ccc8 189
93a37866
A
190 TypedArrayType typedArrayStorageType;
191};
9dae56ea
A
192
193} // namespace JSC
194
195#endif // ClassInfo_h