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