]> git.saurik.com Git - apple/javascriptcore.git/blame - runtime/ClassInfo.h
JavaScriptCore-7600.1.4.16.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 27#include "ConstructData.h"
81345200 28#include "CopyToken.h"
6fe7ccc8 29#include "JSCell.h"
9dae56ea
A
30
31namespace JSC {
32
81345200 33class JSArrayBufferView;
93a37866 34struct HashTable;
9dae56ea 35
93a37866
A
36struct MethodTable {
37 typedef void (*DestroyFunctionPtr)(JSCell*);
38 DestroyFunctionPtr destroy;
6fe7ccc8 39
93a37866
A
40 typedef void (*VisitChildrenFunctionPtr)(JSCell*, SlotVisitor&);
41 VisitChildrenFunctionPtr visitChildren;
6fe7ccc8 42
81345200 43 typedef void (*CopyBackingStoreFunctionPtr)(JSCell*, CopyVisitor&, CopyToken);
93a37866 44 CopyBackingStoreFunctionPtr copyBackingStore;
6fe7ccc8 45
93a37866
A
46 typedef CallType (*GetCallDataFunctionPtr)(JSCell*, CallData&);
47 GetCallDataFunctionPtr getCallData;
6fe7ccc8 48
93a37866
A
49 typedef ConstructType (*GetConstructDataFunctionPtr)(JSCell*, ConstructData&);
50 GetConstructDataFunctionPtr getConstructData;
6fe7ccc8 51
93a37866
A
52 typedef void (*PutFunctionPtr)(JSCell*, ExecState*, PropertyName propertyName, JSValue, PutPropertySlot&);
53 PutFunctionPtr put;
6fe7ccc8 54
93a37866
A
55 typedef void (*PutByIndexFunctionPtr)(JSCell*, ExecState*, unsigned propertyName, JSValue, bool shouldThrow);
56 PutByIndexFunctionPtr putByIndex;
6fe7ccc8 57
93a37866
A
58 typedef bool (*DeletePropertyFunctionPtr)(JSCell*, ExecState*, PropertyName);
59 DeletePropertyFunctionPtr deleteProperty;
6fe7ccc8 60
93a37866
A
61 typedef bool (*DeletePropertyByIndexFunctionPtr)(JSCell*, ExecState*, unsigned);
62 DeletePropertyByIndexFunctionPtr deletePropertyByIndex;
6fe7ccc8 63
81345200 64 typedef bool (*GetOwnPropertySlotFunctionPtr)(JSObject*, ExecState*, PropertyName, PropertySlot&);
93a37866 65 GetOwnPropertySlotFunctionPtr getOwnPropertySlot;
6fe7ccc8 66
81345200 67 typedef bool (*GetOwnPropertySlotByIndexFunctionPtr)(JSObject*, ExecState*, unsigned, PropertySlot&);
93a37866 68 GetOwnPropertySlotByIndexFunctionPtr getOwnPropertySlotByIndex;
6fe7ccc8 69
81345200
A
70 typedef JSValue (*ToThisFunctionPtr)(JSCell*, ExecState*, ECMAMode);
71 ToThisFunctionPtr toThis;
6fe7ccc8 72
93a37866
A
73 typedef JSValue (*DefaultValueFunctionPtr)(const JSObject*, ExecState*, PreferredPrimitiveType);
74 DefaultValueFunctionPtr defaultValue;
6fe7ccc8 75
93a37866
A
76 typedef void (*GetOwnPropertyNamesFunctionPtr)(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode);
77 GetOwnPropertyNamesFunctionPtr getOwnPropertyNames;
6fe7ccc8 78
93a37866
A
79 typedef void (*GetOwnNonIndexPropertyNamesFunctionPtr)(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode);
80 GetOwnNonIndexPropertyNamesFunctionPtr getOwnNonIndexPropertyNames;
6fe7ccc8 81
93a37866
A
82 typedef void (*GetPropertyNamesFunctionPtr)(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode);
83 GetPropertyNamesFunctionPtr getPropertyNames;
6fe7ccc8 84
93a37866
A
85 typedef String (*ClassNameFunctionPtr)(const JSObject*);
86 ClassNameFunctionPtr className;
6fe7ccc8 87
93a37866
A
88 typedef bool (*CustomHasInstanceFunctionPtr)(JSObject*, ExecState*, JSValue);
89 CustomHasInstanceFunctionPtr customHasInstance;
6fe7ccc8 90
81345200 91 typedef bool (*DefineOwnPropertyFunctionPtr)(JSObject*, ExecState*, PropertyName, const PropertyDescriptor&, bool);
93a37866
A
92 DefineOwnPropertyFunctionPtr defineOwnProperty;
93
81345200
A
94 typedef ArrayBuffer* (*SlowDownAndWasteMemory)(JSArrayBufferView*);
95 SlowDownAndWasteMemory slowDownAndWasteMemory;
96
97 typedef PassRefPtr<ArrayBufferView> (*GetTypedArrayImpl)(JSArrayBufferView*);
98 GetTypedArrayImpl getTypedArrayImpl;
99
100 typedef void (*DumpToStreamFunctionPtr)(const JSCell*, PrintStream&);
101 DumpToStreamFunctionPtr dumpToStream;
93a37866 102};
6fe7ccc8
A
103
104#define CREATE_MEMBER_CHECKER(member) \
93a37866
A
105 template <typename T> \
106 struct MemberCheck##member { \
107 struct Fallback { \
108 void member(...); \
109 }; \
110 struct Derived : T, Fallback { }; \
111 template <typename U, U> struct Check; \
112 typedef char Yes[2]; \
113 typedef char No[1]; \
114 template <typename U> \
115 static No &func(Check<void (Fallback::*)(...), &U::member>*); \
116 template <typename U> \
117 static Yes &func(...); \
118 enum { has = sizeof(func<Derived>(0)) == sizeof(Yes) }; \
119 }
6fe7ccc8
A
120
121#define HAS_MEMBER_NAMED(klass, name) (MemberCheck##name<klass>::has)
122
123#define CREATE_METHOD_TABLE(ClassName) { \
124 &ClassName::destroy, \
125 &ClassName::visitChildren, \
93a37866 126 &ClassName::copyBackingStore, \
6fe7ccc8
A
127 &ClassName::getCallData, \
128 &ClassName::getConstructData, \
129 &ClassName::put, \
130 &ClassName::putByIndex, \
131 &ClassName::deleteProperty, \
132 &ClassName::deletePropertyByIndex, \
133 &ClassName::getOwnPropertySlot, \
134 &ClassName::getOwnPropertySlotByIndex, \
81345200 135 &ClassName::toThis, \
6fe7ccc8
A
136 &ClassName::defaultValue, \
137 &ClassName::getOwnPropertyNames, \
93a37866 138 &ClassName::getOwnNonIndexPropertyNames, \
6fe7ccc8
A
139 &ClassName::getPropertyNames, \
140 &ClassName::className, \
93a37866 141 &ClassName::customHasInstance, \
6fe7ccc8 142 &ClassName::defineOwnProperty, \
81345200
A
143 &ClassName::slowDownAndWasteMemory, \
144 &ClassName::getTypedArrayImpl, \
145 &ClassName::dumpToStream \
6fe7ccc8
A
146 }, \
147 ClassName::TypedArrayStorageType
148
93a37866 149struct ClassInfo {
81345200 150 // A string denoting the class name. Example: "Window".
93a37866
A
151 const char* className;
152
81345200
A
153 // Pointer to the class information of the base class.
154 // nullptrif there is none.
93a37866 155 const ClassInfo* parentClass;
81345200
A
156
157 // Static hash-table of properties.
158 // For classes that can be used from multiple threads, it is accessed via a getter function
159 // that would typically return a pointer to a thread-specific value.
93a37866
A
160 const HashTable* propHashTable(ExecState* exec) const
161 {
162 if (classPropHashTableGetterFunction)
81345200
A
163 return &classPropHashTableGetterFunction(exec->vm());
164
165 return staticPropHashTable;
166 }
167
168 const HashTable* propHashTable(VM& vm) const
169 {
170 if (classPropHashTableGetterFunction)
171 return &classPropHashTableGetterFunction(vm);
172
93a37866
A
173 return staticPropHashTable;
174 }
81345200 175
93a37866
A
176 bool isSubClassOf(const ClassInfo* other) const
177 {
178 for (const ClassInfo* ci = this; ci; ci = ci->parentClass) {
179 if (ci == other)
180 return true;
6fe7ccc8 181 }
93a37866
A
182 return false;
183 }
184
185 bool hasStaticProperties() const
186 {
187 for (const ClassInfo* ci = this; ci; ci = ci->parentClass) {
188 if (ci->staticPropHashTable || ci->classPropHashTableGetterFunction)
189 return true;
6fe7ccc8 190 }
93a37866
A
191 return false;
192 }
9dae56ea 193
81345200
A
194 bool hasStaticSetterOrReadonlyProperties(VM&) const;
195
93a37866 196 const HashTable* staticPropHashTable;
81345200 197 typedef const HashTable& (*ClassPropHashTableGetterFunction)(VM&);
93a37866 198 const ClassPropHashTableGetterFunction classPropHashTableGetterFunction;
6fe7ccc8 199
93a37866 200 MethodTable methodTable;
6fe7ccc8 201
93a37866
A
202 TypedArrayType typedArrayStorageType;
203};
9dae56ea
A
204
205} // namespace JSC
206
207#endif // ClassInfo_h