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