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.
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.
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.
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.
26 #include "CallFrame.h"
27 #include "ConstructData.h"
36 typedef void (*VisitChildrenFunctionPtr)(JSCell*, SlotVisitor&);
37 VisitChildrenFunctionPtr visitChildren;
39 typedef CallType (*GetCallDataFunctionPtr)(JSCell*, CallData&);
40 GetCallDataFunctionPtr getCallData;
42 typedef ConstructType (*GetConstructDataFunctionPtr)(JSCell*, ConstructData&);
43 GetConstructDataFunctionPtr getConstructData;
45 typedef void (*PutFunctionPtr)(JSCell*, ExecState*, const Identifier& propertyName, JSValue, PutPropertySlot&);
48 typedef void (*PutByIndexFunctionPtr)(JSCell*, ExecState*, unsigned propertyName, JSValue);
49 PutByIndexFunctionPtr putByIndex;
51 typedef bool (*DeletePropertyFunctionPtr)(JSCell*, ExecState*, const Identifier&);
52 DeletePropertyFunctionPtr deleteProperty;
54 typedef bool (*DeletePropertyByIndexFunctionPtr)(JSCell*, ExecState*, unsigned);
55 DeletePropertyByIndexFunctionPtr deletePropertyByIndex;
57 typedef bool (*GetOwnPropertySlotFunctionPtr)(JSCell*, ExecState*, const Identifier&, PropertySlot&);
58 GetOwnPropertySlotFunctionPtr getOwnPropertySlot;
60 typedef bool (*GetOwnPropertySlotByIndexFunctionPtr)(JSCell*, ExecState*, unsigned, PropertySlot&);
61 GetOwnPropertySlotByIndexFunctionPtr getOwnPropertySlotByIndex;
63 typedef JSObject* (*ToThisObjectFunctionPtr)(JSCell*, ExecState*);
64 ToThisObjectFunctionPtr toThisObject;
66 typedef void (*DefineGetterFunctionPtr)(JSObject*, ExecState*, const Identifier&, JSObject*, unsigned);
67 DefineGetterFunctionPtr defineGetter;
69 typedef void (*DefineSetterFunctionPtr)(JSObject*, ExecState*, const Identifier&, JSObject*, unsigned);
70 DefineSetterFunctionPtr defineSetter;
72 typedef JSValue (*DefaultValueFunctionPtr)(const JSObject*, ExecState*, PreferredPrimitiveType);
73 DefaultValueFunctionPtr defaultValue;
75 typedef void (*GetOwnPropertyNamesFunctionPtr)(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode);
76 GetOwnPropertyNamesFunctionPtr getOwnPropertyNames;
78 typedef void (*GetPropertyNamesFunctionPtr)(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode);
79 GetPropertyNamesFunctionPtr getPropertyNames;
81 typedef UString (*ClassNameFunctionPtr)(const JSObject*);
82 ClassNameFunctionPtr className;
84 typedef bool (*HasInstanceFunctionPtr)(JSObject*, ExecState*, JSValue, JSValue);
85 HasInstanceFunctionPtr hasInstance;
87 typedef void (*PutWithAttributesFunctionPtr)(JSObject*, ExecState*, const Identifier& propertyName, JSValue, unsigned attributes);
88 PutWithAttributesFunctionPtr putWithAttributes;
90 typedef bool (*DefineOwnPropertyFunctionPtr)(JSObject*, ExecState*, const Identifier&, PropertyDescriptor&, bool);
91 DefineOwnPropertyFunctionPtr defineOwnProperty;
93 typedef bool (*GetOwnPropertyDescriptorFunctionPtr)(JSObject*, ExecState*, const Identifier&, PropertyDescriptor&);
94 GetOwnPropertyDescriptorFunctionPtr getOwnPropertyDescriptor;
97 #define CREATE_MEMBER_CHECKER(member) \
98 template <typename T> \
99 struct MemberCheck##member { \
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) }; \
114 #define HAS_MEMBER_NAMED(klass, name) (MemberCheck##name<klass>::has)
116 #define CREATE_METHOD_TABLE(ClassName) { \
117 &ClassName::visitChildren, \
118 &ClassName::getCallData, \
119 &ClassName::getConstructData, \
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, \
139 ClassName::TypedArrayStorageType
143 * A string denoting the class name. Example: "Window".
145 const char* className;
148 * Pointer to the class information of the base class.
149 * 0L if there is none.
151 const ClassInfo* parentClass;
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.
156 const HashTable* propHashTable(ExecState* exec) const
158 if (classPropHashTableGetterFunction)
159 return classPropHashTableGetterFunction(exec);
160 return staticPropHashTable;
163 bool isSubClassOf(const ClassInfo* other) const
165 for (const ClassInfo* ci = this; ci; ci = ci->parentClass) {
172 bool hasStaticProperties() const
174 for (const ClassInfo* ci = this; ci; ci = ci->parentClass) {
175 if (ci->staticPropHashTable || ci->classPropHashTableGetterFunction)
181 const HashTable* staticPropHashTable;
182 typedef const HashTable* (*ClassPropHashTableGetterFunction)(ExecState*);
183 const ClassPropHashTableGetterFunction classPropHashTableGetterFunction;
185 MethodTable methodTable;
189 TypedArrayType typedArrayStorageType;
194 #endif // ClassInfo_h