aafe1ea701a9fc6d1eaa53e6cf671acc7569579a
[WebKit.git] / WebCore / bindings / v8 / custom / V8CustomBinding.h
1 /*
2  * Copyright (C) 2009 Google Inc. All rights reserved.
3  * 
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  * 
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  * 
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30  
31 #ifndef V8CustomBinding_h
32 #define V8CustomBinding_h
33
34 #include "V8Index.h"
35 #include <v8.h>
36
37 #define INDEXED_PROPERTY_GETTER(NAME) \
38     v8::Handle<v8::Value> V8Custom::v8##NAME##IndexedPropertyGetter( \
39         uint32_t index, const v8::AccessorInfo& info)
40
41 #define INDEXED_PROPERTY_SETTER(NAME) \
42     v8::Handle<v8::Value> V8Custom::v8##NAME##IndexedPropertySetter( \
43         uint32_t index, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
44
45 #define INDEXED_PROPERTY_DELETER(NAME) \
46     v8::Handle<v8::Boolean> V8Custom::v8##NAME##IndexedPropertyDeleter( \
47         uint32_t index, const v8::AccessorInfo& info)
48
49 #define NAMED_PROPERTY_GETTER(NAME) \
50     v8::Handle<v8::Value> V8Custom::v8##NAME##NamedPropertyGetter( \
51         v8::Local<v8::String> name, const v8::AccessorInfo& info)
52
53 #define NAMED_PROPERTY_SETTER(NAME) \
54     v8::Handle<v8::Value> V8Custom::v8##NAME##NamedPropertySetter( \
55         v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
56
57 #define NAMED_PROPERTY_DELETER(NAME) \
58     v8::Handle<v8::Boolean> V8Custom::v8##NAME##NamedPropertyDeleter( \
59         v8::Local<v8::String> name, const v8::AccessorInfo& info)
60
61 namespace WebCore {
62     class V8Custom {
63     public:
64         // Constants.
65         static const int kDOMWrapperTypeIndex = 0;
66         static const int kDOMWrapperObjectIndex = 1;
67         static const int kDefaultWrapperInternalFieldCount = 2;
68
69         static const int kNPObjectInternalFieldCount = kDefaultWrapperInternalFieldCount + 0;
70
71         static const int kNodeEventListenerCacheIndex = kDefaultWrapperInternalFieldCount + 0;
72         static const int kNodeMinimumInternalFieldCount = kDefaultWrapperInternalFieldCount + 1;
73
74         static const int kDocumentImplementationIndex = kNodeMinimumInternalFieldCount + 0;
75         static const int kDocumentMinimumInternalFieldCount = kNodeMinimumInternalFieldCount + 1;
76
77         static const int kHTMLDocumentMarkerIndex = kDocumentMinimumInternalFieldCount + 0;
78         static const int kHTMLDocumentShadowIndex = kDocumentMinimumInternalFieldCount + 1;
79         static const int kHTMLDocumentInternalFieldCount = kDocumentMinimumInternalFieldCount + 2;
80
81         static const int kXMLHttpRequestCacheIndex = kDefaultWrapperInternalFieldCount + 0;
82         static const int kXMLHttpRequestInternalFieldCount = kDefaultWrapperInternalFieldCount + 1;
83
84         static const int kMessageChannelPort1Index = kDefaultWrapperInternalFieldCount + 0;
85         static const int kMessageChannelPort2Index = kDefaultWrapperInternalFieldCount + 1;
86         static const int kMessageChannelInternalFieldCount = kDefaultWrapperInternalFieldCount + 2;
87
88         static const int kMessagePortRequestCacheIndex = kDefaultWrapperInternalFieldCount + 0;
89         static const int kMessagePortInternalFieldCount = kDefaultWrapperInternalFieldCount + 1;
90
91 #if ENABLE(WORKERS)
92         static const int kAbstractWorkerRequestCacheIndex = kDefaultWrapperInternalFieldCount + 0;
93         static const int kAbstractWorkerInternalFieldCount = kDefaultWrapperInternalFieldCount + 1;
94
95         static const int kWorkerRequestCacheIndex = kAbstractWorkerInternalFieldCount + 0;
96         static const int kWorkerInternalFieldCount = kAbstractWorkerInternalFieldCount + 1;
97
98         static const int kWorkerContextRequestCacheIndex = kDefaultWrapperInternalFieldCount + 0;
99         static const int kWorkerContextMinimumInternalFieldCount = kDefaultWrapperInternalFieldCount + 1;
100
101         static const int kDedicatedWorkerContextRequestCacheIndex = kWorkerContextMinimumInternalFieldCount + 0;
102         static const int kDedicatedWorkerContextInternalFieldCount = kWorkerContextMinimumInternalFieldCount + 1;
103 #endif
104
105 #if ENABLE(SHARED_WORKERS)
106         static const int kSharedWorkerRequestCacheIndex = kAbstractWorkerInternalFieldCount + 0;
107         static const int kSharedWorkerInternalFieldCount = kAbstractWorkerInternalFieldCount + 1;
108
109         static const int kSharedWorkerContextRequestCacheIndex = kWorkerContextMinimumInternalFieldCount + 0;
110         static const int kSharedWorkerContextInternalFieldCount = kWorkerContextMinimumInternalFieldCount + 1;
111 #endif
112
113 #if ENABLE(NOTIFICATIONS)
114         static const int kNotificationRequestCacheIndex = kDefaultWrapperInternalFieldCount + 0;
115         static const int kNotificationInternalFieldCount = kDefaultWrapperInternalFieldCount + 1;
116 #endif
117
118 #if ENABLE(SVG)
119         static const int kSVGElementInstanceEventListenerCacheIndex = kDefaultWrapperInternalFieldCount + 0;
120         static const int kSVGElementInstanceInternalFieldCount = kDefaultWrapperInternalFieldCount + 1;
121 #endif
122
123         static const int kDOMWindowConsoleIndex = kDefaultWrapperInternalFieldCount + 0;
124         static const int kDOMWindowHistoryIndex = kDefaultWrapperInternalFieldCount + 1;
125         static const int kDOMWindowLocationbarIndex = kDefaultWrapperInternalFieldCount + 2;
126         static const int kDOMWindowMenubarIndex = kDefaultWrapperInternalFieldCount + 3;
127         static const int kDOMWindowNavigatorIndex = kDefaultWrapperInternalFieldCount + 4;
128         static const int kDOMWindowPersonalbarIndex = kDefaultWrapperInternalFieldCount + 5;
129         static const int kDOMWindowScreenIndex = kDefaultWrapperInternalFieldCount + 6;
130         static const int kDOMWindowScrollbarsIndex = kDefaultWrapperInternalFieldCount + 7;
131         static const int kDOMWindowSelectionIndex = kDefaultWrapperInternalFieldCount + 8;
132         static const int kDOMWindowStatusbarIndex = kDefaultWrapperInternalFieldCount + 9;
133         static const int kDOMWindowToolbarIndex = kDefaultWrapperInternalFieldCount + 10;
134         static const int kDOMWindowLocationIndex = kDefaultWrapperInternalFieldCount + 11;
135         static const int kDOMWindowDOMSelectionIndex = kDefaultWrapperInternalFieldCount + 12;
136         static const int kDOMWindowEventListenerCacheIndex = kDefaultWrapperInternalFieldCount + 13;
137         static const int kDOMWindowEnteredIsolatedWorldIndex = kDefaultWrapperInternalFieldCount + 14;
138         static const int kDOMWindowInternalFieldCount = kDefaultWrapperInternalFieldCount + 15;
139
140         static const int kStyleSheetOwnerNodeIndex = kDefaultWrapperInternalFieldCount + 0;
141         static const int kStyleSheetInternalFieldCount = kDefaultWrapperInternalFieldCount + 1;
142         static const int kNamedNodeMapOwnerNodeIndex = kDefaultWrapperInternalFieldCount + 0;
143         static const int kNamedNodeMapInternalFieldCount = kDefaultWrapperInternalFieldCount + 1;
144
145 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
146         static const int kDOMApplicationCacheCacheIndex = kDefaultWrapperInternalFieldCount + 0;
147         static const int kDOMApplicationCacheFieldCount = kDefaultWrapperInternalFieldCount + 1;
148 #endif
149
150 #if ENABLE(WEB_SOCKETS)
151         static const int kWebSocketCacheIndex = kDefaultWrapperInternalFieldCount + 0;
152         static const int kWebSocketInternalFieldCount = kDefaultWrapperInternalFieldCount + 1;
153 #endif
154
155 #define DECLARE_NAMED_PROPERTY_GETTER(NAME)  \
156     static v8::Handle<v8::Value> v8##NAME##NamedPropertyGetter( \
157         v8::Local<v8::String> name, const v8::AccessorInfo& info)
158
159 #define DECLARE_NAMED_PROPERTY_SETTER(NAME) \
160     static v8::Handle<v8::Value> v8##NAME##NamedPropertySetter( \
161         v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
162
163 #define DECLARE_NAMED_PROPERTY_DELETER(NAME) \
164     static v8::Handle<v8::Boolean> v8##NAME##NamedPropertyDeleter( \
165         v8::Local<v8::String> name, const v8::AccessorInfo& info)
166
167 #define USE_NAMED_PROPERTY_GETTER(NAME) V8Custom::v8##NAME##NamedPropertyGetter
168
169 #define USE_NAMED_PROPERTY_SETTER(NAME) V8Custom::v8##NAME##NamedPropertySetter
170
171 #define USE_NAMED_PROPERTY_DELETER(NAME) V8Custom::v8##NAME##NamedPropertyDeleter
172
173 #define DECLARE_INDEXED_PROPERTY_GETTER(NAME) \
174     static v8::Handle<v8::Value> v8##NAME##IndexedPropertyGetter( \
175         uint32_t index, const v8::AccessorInfo& info)
176
177 #define DECLARE_INDEXED_PROPERTY_SETTER(NAME) \
178     static v8::Handle<v8::Value> v8##NAME##IndexedPropertySetter( \
179         uint32_t index, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
180
181 #define DECLARE_INDEXED_PROPERTY_DELETER(NAME) \
182     static v8::Handle<v8::Boolean> v8##NAME##IndexedPropertyDeleter( \
183         uint32_t index, const v8::AccessorInfo& info)
184
185 #define USE_INDEXED_PROPERTY_GETTER(NAME) V8Custom::v8##NAME##IndexedPropertyGetter
186
187 #define USE_INDEXED_PROPERTY_SETTER(NAME) V8Custom::v8##NAME##IndexedPropertySetter
188
189 #define USE_INDEXED_PROPERTY_DELETER(NAME) V8Custom::v8##NAME##IndexedPropertyDeleter
190
191 #define DECLARE_CALLBACK(NAME) static v8::Handle<v8::Value> v8##NAME##Callback(const v8::Arguments& args)
192
193 #define USE_CALLBACK(NAME) V8Custom::v8##NAME##Callback
194
195         DECLARE_NAMED_PROPERTY_GETTER(HTMLDocument);
196         DECLARE_NAMED_PROPERTY_DELETER(HTMLDocument);
197
198         DECLARE_CALLBACK(DOMParserConstructor);
199         DECLARE_CALLBACK(HTMLAudioElementConstructor);
200         DECLARE_CALLBACK(HTMLImageElementConstructor);
201         DECLARE_CALLBACK(HTMLOptionElementConstructor);
202         DECLARE_CALLBACK(MessageChannelConstructor);
203         DECLARE_CALLBACK(WebKitCSSMatrixConstructor);
204         DECLARE_CALLBACK(WebKitPointConstructor);
205         DECLARE_CALLBACK(XMLHttpRequestConstructor);
206         DECLARE_CALLBACK(XMLSerializerConstructor);
207         DECLARE_CALLBACK(XPathEvaluatorConstructor);
208         DECLARE_CALLBACK(XSLTProcessorConstructor);
209
210 #if ENABLE(3D_CANVAS)
211         DECLARE_CALLBACK(WebGLArrayBufferConstructor);
212         DECLARE_CALLBACK(WebGLByteArrayConstructor);
213         DECLARE_CALLBACK(WebGLFloatArrayConstructor);
214         DECLARE_CALLBACK(WebGLIntArrayConstructor);
215         DECLARE_CALLBACK(WebGLShortArrayConstructor);
216         DECLARE_CALLBACK(WebGLUnsignedByteArrayConstructor);
217         DECLARE_CALLBACK(WebGLUnsignedIntArrayConstructor);
218         DECLARE_CALLBACK(WebGLUnsignedShortArrayConstructor);
219 #endif
220
221         DECLARE_NAMED_PROPERTY_GETTER(DOMWindow);
222         DECLARE_INDEXED_PROPERTY_GETTER(DOMWindow);
223
224         DECLARE_NAMED_PROPERTY_GETTER(HTMLFrameSetElement);
225         DECLARE_NAMED_PROPERTY_GETTER(HTMLFormElement);
226         DECLARE_NAMED_PROPERTY_GETTER(NodeList);
227         DECLARE_NAMED_PROPERTY_GETTER(NamedNodeMap);
228         DECLARE_NAMED_PROPERTY_GETTER(CSSStyleDeclaration);
229         DECLARE_NAMED_PROPERTY_SETTER(CSSStyleDeclaration);
230         DECLARE_NAMED_PROPERTY_GETTER(HTMLAppletElement);
231         DECLARE_NAMED_PROPERTY_SETTER(HTMLAppletElement);
232         DECLARE_NAMED_PROPERTY_GETTER(HTMLEmbedElement);
233         DECLARE_NAMED_PROPERTY_SETTER(HTMLEmbedElement);
234         DECLARE_NAMED_PROPERTY_GETTER(HTMLObjectElement);
235         DECLARE_NAMED_PROPERTY_SETTER(HTMLObjectElement);
236         DECLARE_INDEXED_PROPERTY_GETTER(HTMLAppletElement);
237         DECLARE_INDEXED_PROPERTY_SETTER(HTMLAppletElement);
238         DECLARE_INDEXED_PROPERTY_GETTER(HTMLEmbedElement);
239         DECLARE_INDEXED_PROPERTY_SETTER(HTMLEmbedElement);
240         DECLARE_INDEXED_PROPERTY_GETTER(HTMLObjectElement);
241         DECLARE_INDEXED_PROPERTY_SETTER(HTMLObjectElement);
242
243         DECLARE_NAMED_PROPERTY_GETTER(StyleSheetList);
244         DECLARE_INDEXED_PROPERTY_GETTER(NamedNodeMap);
245         DECLARE_INDEXED_PROPERTY_GETTER(HTMLFormElement);
246         DECLARE_INDEXED_PROPERTY_GETTER(HTMLOptionsCollection);
247         DECLARE_INDEXED_PROPERTY_SETTER(HTMLOptionsCollection);
248         DECLARE_NAMED_PROPERTY_GETTER(HTMLSelectElement);
249         DECLARE_INDEXED_PROPERTY_GETTER(HTMLSelectElement);
250         DECLARE_INDEXED_PROPERTY_SETTER(HTMLSelectElement);
251         DECLARE_NAMED_PROPERTY_GETTER(HTMLAllCollection);
252         DECLARE_NAMED_PROPERTY_GETTER(HTMLCollection);
253
254 #if ENABLE(3D_CANVAS)
255         DECLARE_INDEXED_PROPERTY_GETTER(WebGLByteArray);
256         DECLARE_INDEXED_PROPERTY_SETTER(WebGLByteArray);
257
258         DECLARE_INDEXED_PROPERTY_GETTER(WebGLFloatArray);
259         DECLARE_INDEXED_PROPERTY_SETTER(WebGLFloatArray);
260
261         DECLARE_INDEXED_PROPERTY_GETTER(WebGLIntArray);
262         DECLARE_INDEXED_PROPERTY_SETTER(WebGLIntArray);
263
264         DECLARE_INDEXED_PROPERTY_GETTER(WebGLShortArray);
265         DECLARE_INDEXED_PROPERTY_SETTER(WebGLShortArray);
266
267         DECLARE_INDEXED_PROPERTY_GETTER(WebGLUnsignedByteArray);
268         DECLARE_INDEXED_PROPERTY_SETTER(WebGLUnsignedByteArray);
269
270         DECLARE_INDEXED_PROPERTY_GETTER(WebGLUnsignedIntArray);
271         DECLARE_INDEXED_PROPERTY_SETTER(WebGLUnsignedIntArray);
272
273         DECLARE_INDEXED_PROPERTY_GETTER(WebGLUnsignedShortArray);
274         DECLARE_INDEXED_PROPERTY_SETTER(WebGLUnsignedShortArray);
275 #endif
276
277 #if ENABLE(DATAGRID)
278         DECLARE_NAMED_PROPERTY_GETTER(DataGridColumnList);
279 #endif
280
281 #if ENABLE(DOM_STORAGE)
282         DECLARE_INDEXED_PROPERTY_GETTER(Storage);
283         DECLARE_INDEXED_PROPERTY_SETTER(Storage);
284         DECLARE_INDEXED_PROPERTY_DELETER(Storage);
285         DECLARE_NAMED_PROPERTY_GETTER(Storage);
286         DECLARE_NAMED_PROPERTY_SETTER(Storage);
287         DECLARE_NAMED_PROPERTY_DELETER(Storage);
288         static v8::Handle<v8::Array> v8StorageNamedPropertyEnumerator(const v8::AccessorInfo& info);
289 #endif
290
291 #if ENABLE(WORKERS)
292         DECLARE_CALLBACK(WorkerConstructor);
293 #endif
294
295 #if ENABLE(SHARED_WORKERS)
296         DECLARE_CALLBACK(SharedWorkerConstructor);
297 #endif
298
299 #if ENABLE(WEB_SOCKETS)
300         DECLARE_CALLBACK(WebSocketConstructor);
301 #endif
302
303 #undef DECLARE_NAMED_PROPERTY_GETTER
304 #undef DECLARE_NAMED_PROPERTY_SETTER
305 #undef DECLARE_NAMED_PROPERTY_DELETER
306
307 #undef DECLARE_INDEXED_PROPERTY_GETTER
308 #undef DECLARE_INDEXED_PROPERTY_SETTER
309 #undef DECLARE_INDEXED_PROPERTY_DELETER
310
311 #undef DECLARE_CALLBACK
312     };
313
314 } // namespace WebCore
315
316 #endif // V8CustomBinding_h