]>
Commit | Line | Data |
---|---|---|
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 | |
30 | namespace JSC { | |
31 | ||
f9bf01c6 | 32 | class HashEntry; |
9dae56ea A |
33 | struct HashTable; |
34 | ||
6fe7ccc8 A |
35 | struct MethodTable { |
36 | typedef void (*DestroyFunctionPtr)(JSCell*); | |
37 | DestroyFunctionPtr destroy; | |
38 | ||
39 | typedef void (*VisitChildrenFunctionPtr)(JSCell*, SlotVisitor&); | |
40 | VisitChildrenFunctionPtr visitChildren; | |
41 | ||
42 | typedef CallType (*GetCallDataFunctionPtr)(JSCell*, CallData&); | |
43 | GetCallDataFunctionPtr getCallData; | |
44 | ||
45 | typedef ConstructType (*GetConstructDataFunctionPtr)(JSCell*, ConstructData&); | |
46 | GetConstructDataFunctionPtr getConstructData; | |
47 | ||
48 | typedef void (*PutFunctionPtr)(JSCell*, ExecState*, const Identifier& propertyName, JSValue, PutPropertySlot&); | |
49 | PutFunctionPtr put; | |
50 | ||
51 | typedef void (*PutByIndexFunctionPtr)(JSCell*, ExecState*, unsigned propertyName, JSValue, bool shouldThrow); | |
52 | PutByIndexFunctionPtr putByIndex; | |
53 | ||
54 | typedef bool (*DeletePropertyFunctionPtr)(JSCell*, ExecState*, const Identifier&); | |
55 | DeletePropertyFunctionPtr deleteProperty; | |
56 | ||
57 | typedef bool (*DeletePropertyByIndexFunctionPtr)(JSCell*, ExecState*, unsigned); | |
58 | DeletePropertyByIndexFunctionPtr deletePropertyByIndex; | |
59 | ||
60 | typedef bool (*GetOwnPropertySlotFunctionPtr)(JSCell*, ExecState*, const Identifier&, PropertySlot&); | |
61 | GetOwnPropertySlotFunctionPtr getOwnPropertySlot; | |
62 | ||
63 | typedef bool (*GetOwnPropertySlotByIndexFunctionPtr)(JSCell*, ExecState*, unsigned, PropertySlot&); | |
64 | GetOwnPropertySlotByIndexFunctionPtr getOwnPropertySlotByIndex; | |
65 | ||
66 | typedef JSObject* (*ToThisObjectFunctionPtr)(JSCell*, ExecState*); | |
67 | ToThisObjectFunctionPtr toThisObject; | |
68 | ||
69 | typedef JSValue (*DefaultValueFunctionPtr)(const JSObject*, ExecState*, PreferredPrimitiveType); | |
70 | DefaultValueFunctionPtr defaultValue; | |
71 | ||
72 | typedef void (*GetOwnPropertyNamesFunctionPtr)(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode); | |
73 | GetOwnPropertyNamesFunctionPtr getOwnPropertyNames; | |
74 | ||
75 | typedef void (*GetPropertyNamesFunctionPtr)(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode); | |
76 | GetPropertyNamesFunctionPtr getPropertyNames; | |
77 | ||
78 | typedef UString (*ClassNameFunctionPtr)(const JSObject*); | |
79 | ClassNameFunctionPtr className; | |
80 | ||
81 | typedef bool (*HasInstanceFunctionPtr)(JSObject*, ExecState*, JSValue, JSValue); | |
82 | HasInstanceFunctionPtr hasInstance; | |
83 | ||
84 | typedef void (*PutWithAttributesFunctionPtr)(JSObject*, ExecState*, const Identifier& propertyName, JSValue, unsigned attributes); | |
85 | PutWithAttributesFunctionPtr putDirectVirtual; | |
86 | ||
87 | typedef bool (*DefineOwnPropertyFunctionPtr)(JSObject*, ExecState*, const Identifier&, PropertyDescriptor&, bool); | |
88 | DefineOwnPropertyFunctionPtr defineOwnProperty; | |
89 | ||
90 | typedef bool (*GetOwnPropertyDescriptorFunctionPtr)(JSObject*, ExecState*, const Identifier&, PropertyDescriptor&); | |
91 | GetOwnPropertyDescriptorFunctionPtr getOwnPropertyDescriptor; | |
92 | }; | |
93 | ||
94 | #define CREATE_MEMBER_CHECKER(member) \ | |
95 | template <typename T> \ | |
96 | struct MemberCheck##member { \ | |
97 | struct Fallback { \ | |
98 | void member(...); \ | |
99 | }; \ | |
100 | struct Derived : T, Fallback { }; \ | |
101 | template <typename U, U> struct Check; \ | |
102 | typedef char Yes[2]; \ | |
103 | typedef char No[1]; \ | |
104 | template <typename U> \ | |
105 | static No &func(Check<void (Fallback::*)(...), &U::member>*); \ | |
106 | template <typename U> \ | |
107 | static Yes &func(...); \ | |
108 | enum { has = sizeof(func<Derived>(0)) == sizeof(Yes) }; \ | |
109 | } | |
110 | ||
111 | #define HAS_MEMBER_NAMED(klass, name) (MemberCheck##name<klass>::has) | |
112 | ||
113 | #define CREATE_METHOD_TABLE(ClassName) { \ | |
114 | &ClassName::destroy, \ | |
115 | &ClassName::visitChildren, \ | |
116 | &ClassName::getCallData, \ | |
117 | &ClassName::getConstructData, \ | |
118 | &ClassName::put, \ | |
119 | &ClassName::putByIndex, \ | |
120 | &ClassName::deleteProperty, \ | |
121 | &ClassName::deletePropertyByIndex, \ | |
122 | &ClassName::getOwnPropertySlot, \ | |
123 | &ClassName::getOwnPropertySlotByIndex, \ | |
124 | &ClassName::toThisObject, \ | |
125 | &ClassName::defaultValue, \ | |
126 | &ClassName::getOwnPropertyNames, \ | |
127 | &ClassName::getPropertyNames, \ | |
128 | &ClassName::className, \ | |
129 | &ClassName::hasInstance, \ | |
130 | &ClassName::putDirectVirtual, \ | |
131 | &ClassName::defineOwnProperty, \ | |
132 | &ClassName::getOwnPropertyDescriptor, \ | |
133 | }, \ | |
134 | ClassName::TypedArrayStorageType | |
135 | ||
9dae56ea A |
136 | struct ClassInfo { |
137 | /** | |
138 | * A string denoting the class name. Example: "Window". | |
139 | */ | |
140 | const char* className; | |
141 | ||
142 | /** | |
143 | * Pointer to the class information of the base class. | |
144 | * 0L if there is none. | |
145 | */ | |
146 | const ClassInfo* parentClass; | |
147 | /** | |
148 | * Static hash-table of properties. | |
149 | * 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. | |
150 | */ | |
151 | const HashTable* propHashTable(ExecState* exec) const | |
152 | { | |
153 | if (classPropHashTableGetterFunction) | |
154 | return classPropHashTableGetterFunction(exec); | |
155 | return staticPropHashTable; | |
156 | } | |
6fe7ccc8 A |
157 | |
158 | bool isSubClassOf(const ClassInfo* other) const | |
159 | { | |
160 | for (const ClassInfo* ci = this; ci; ci = ci->parentClass) { | |
161 | if (ci == other) | |
162 | return true; | |
163 | } | |
164 | return false; | |
165 | } | |
166 | ||
167 | bool hasStaticProperties() const | |
168 | { | |
169 | for (const ClassInfo* ci = this; ci; ci = ci->parentClass) { | |
170 | if (ci->staticPropHashTable || ci->classPropHashTableGetterFunction) | |
171 | return true; | |
172 | } | |
173 | return false; | |
174 | } | |
9dae56ea A |
175 | |
176 | const HashTable* staticPropHashTable; | |
177 | typedef const HashTable* (*ClassPropHashTableGetterFunction)(ExecState*); | |
178 | const ClassPropHashTableGetterFunction classPropHashTableGetterFunction; | |
6fe7ccc8 A |
179 | |
180 | MethodTable methodTable; | |
181 | ||
182 | TypedArrayType typedArrayStorageType; | |
9dae56ea A |
183 | }; |
184 | ||
185 | } // namespace JSC | |
186 | ||
187 | #endif // ClassInfo_h |