1{# http://www.chromium.org/blink/coding-style#TOC-License #}
2/*
3 * Copyright (C) 2013 Google Inc. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 *     * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *     * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
14 * distribution.
15 *     * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32{# FIXME: Rename to Python when switch #}
33// This file has been auto-generated by code_generator_v8.pm. DO NOT MODIFY!
34
35#ifndef {{v8_class}}_h
36#define {{v8_class}}_h
37
38{% filter conditional(conditional_string) %}
39{% for filename in header_includes %}
40#include "{{filename}}"
41{% endfor %}
42
43namespace WebCore {
44
45{% if has_event_constructor %}
46class Dictionary;
47{% endif %}
48{% if named_constructor %}
49class {{v8_class}}Constructor {
50public:
51    static v8::Handle<v8::FunctionTemplate> domTemplate(v8::Isolate*, WrapperWorldType);
52    static const WrapperTypeInfo wrapperTypeInfo;
53};
54
55{% endif %}
56class {{v8_class}} {
57public:
58    static bool hasInstance(v8::Handle<v8::Value>, v8::Isolate*, WrapperWorldType);
59    static bool hasInstanceInAnyWorld(v8::Handle<v8::Value>, v8::Isolate*);
60    static v8::Handle<v8::FunctionTemplate> domTemplate(v8::Isolate*, WrapperWorldType);
61    static {{cpp_class}}* toNative(v8::Handle<v8::Object> object)
62    {
63        return fromInternalPointer(object->GetAlignedPointerFromInternalField(v8DOMWrapperObjectIndex));
64    }
65    static void derefObject(void*);
66    static const WrapperTypeInfo wrapperTypeInfo;
67    {% if has_visit_dom_wrapper %}
68    static void visitDOMWrapper(void*, const v8::Persistent<v8::Object>&, v8::Isolate*);
69    {% endif %}
70    {% if is_active_dom_object %}
71    static ActiveDOMObject* toActiveDOMObject(v8::Handle<v8::Object>);
72    {% endif %}
73    {% if is_event_target %}
74    static EventTarget* toEventTarget(v8::Handle<v8::Object>);
75    {% endif %}
76    {% for method in methods if method.is_custom %}
77    {% filter conditional(method.conditional_string) %}
78    static void {{method.name}}MethodCustom(const v8::FunctionCallbackInfo<v8::Value>&);
79    {% endfilter %}
80    {% endfor %}
81    {% if constructors or has_custom_constructor or has_event_constructor %}
82    static void constructorCallback(const v8::FunctionCallbackInfo<v8::Value>&);
83    {% endif %}
84    {% if has_custom_constructor %}
85    static void constructorCustom(const v8::FunctionCallbackInfo<v8::Value>&);
86    {% endif %}
87    {% for attribute in attributes %}
88    {% if attribute.has_custom_getter %}{# FIXME: and not attribute.implemented_by #}
89    {% filter conditional(attribute.conditional_string) %}
90    static void {{attribute.name}}AttributeGetterCustom(const v8::PropertyCallbackInfo<v8::Value>&);
91    {% endfilter %}
92    {% endif %}
93    {% if attribute.has_custom_setter %}{# FIXME: and not attribute.implemented_by #}
94    {% filter conditional(attribute.conditional_string) %}
95    static void {{attribute.name}}AttributeSetterCustom(v8::Local<v8::Value>, const v8::PropertyCallbackInfo<void>&);
96    {% endfilter %}
97    {% endif %}
98    {% endfor %}
99    {% if has_custom_legacy_call_as_function %}
100    static void legacyCallCustom(const v8::FunctionCallbackInfo<v8::Value>&);
101    {% endif %}
102    {% set custom_internal_field_counter = 0 %}
103    {% if is_event_target and not is_node %}
104    {# Event listeners on DOM nodes are explicitly supported in the GC controller. #}
105    static const int eventListenerCacheIndex = v8DefaultWrapperInternalFieldCount + 0;
106    {% set custom_internal_field_counter = custom_internal_field_counter + 1 %}
107    {% endif %}
108    static const int internalFieldCount = v8DefaultWrapperInternalFieldCount + {{custom_internal_field_counter}};
109    static inline void* toInternalPointer({{cpp_class}}* impl)
110    {
111        {% if parent_interface %}
112        return V8{{parent_interface}}::toInternalPointer(impl);
113        {% else %}
114        return impl;
115        {% endif %}
116    }
117
118    static inline {{cpp_class}}* fromInternalPointer(void* object)
119    {
120        {% if parent_interface %}
121        return static_cast<{{cpp_class}}*>(V8{{parent_interface}}::fromInternalPointer(object));
122        {% else %}
123        return static_cast<{{cpp_class}}*>(object);
124        {% endif %}
125    }
126    static void installPerContextEnabledProperties(v8::Handle<v8::Object>, {{cpp_class}}*, v8::Isolate*){% if has_per_context_enabled_attributes %};
127    {% else %} { }
128    {% endif %}
129    static void installPerContextEnabledMethods(v8::Handle<v8::Object>, v8::Isolate*){% if has_per_context_enabled_attributes %};
130    {% else %} { }
131    {% endif %}
132
133private:
134    {% if not has_custom_to_v8 %}
135    friend v8::Handle<v8::Object> wrap({{cpp_class}}*, v8::Handle<v8::Object> creationContext, v8::Isolate*);
136    static v8::Handle<v8::Object> createWrapper(PassRefPtr<{{cpp_class}}>, v8::Handle<v8::Object> creationContext, v8::Isolate*);
137    {% endif %}
138};
139
140template<>
141class WrapperTypeTraits<{{cpp_class}} > {
142public:
143    static const WrapperTypeInfo* wrapperTypeInfo() { return &{{v8_class}}::wrapperTypeInfo; }
144};
145
146{% if has_custom_to_v8 %}
147class {{cpp_class}};
148v8::Handle<v8::Value> toV8({{cpp_class}}*, v8::Handle<v8::Object> creationContext, v8::Isolate*);
149
150template<class CallbackInfo>
151inline void v8SetReturnValue(const CallbackInfo& callbackInfo, {{cpp_class}}* impl)
152{
153    v8SetReturnValue(callbackInfo, toV8(impl, callbackInfo.Holder(), callbackInfo.GetIsolate()));
154}
155
156template<class CallbackInfo>
157inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo, {{cpp_class}}* impl)
158{
159     v8SetReturnValue(callbackInfo, toV8(impl, callbackInfo.Holder(), callbackInfo.GetIsolate()));
160}
161
162template<class CallbackInfo, class Wrappable>
163inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo, {{cpp_class}}* impl, Wrappable*)
164{
165     v8SetReturnValue(callbackInfo, toV8(impl, callbackInfo.Holder(), callbackInfo.GetIsolate()));
166}
167{% else %}{# has_custom_to_v8 #}
168{% if has_custom_wrap or special_wrap_for %}
169v8::Handle<v8::Object> wrap({{cpp_class}}* impl, v8::Handle<v8::Object> creationContext, v8::Isolate*);
170{% else %}
171inline v8::Handle<v8::Object> wrap({{cpp_class}}* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
172{
173    ASSERT(impl);
174    ASSERT(!DOMDataStore::containsWrapper<{{v8_class}}>(impl, isolate));
175    return {{v8_class}}::createWrapper(impl, creationContext, isolate);
176}
177{% endif %}
178
179inline v8::Handle<v8::Value> toV8({{cpp_class}}* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
180{
181    if (UNLIKELY(!impl))
182        return v8::Null(isolate);
183    v8::Handle<v8::Value> wrapper = DOMDataStore::getWrapper<{{v8_class}}>(impl, isolate);
184    if (!wrapper.IsEmpty())
185        return wrapper;
186    return wrap(impl, creationContext, isolate);
187}
188
189template<typename CallbackInfo>
190inline void v8SetReturnValue(const CallbackInfo& callbackInfo, {{cpp_class}}* impl)
191{
192    if (UNLIKELY(!impl)) {
193        v8SetReturnValueNull(callbackInfo);
194        return;
195    }
196    if (DOMDataStore::setReturnValueFromWrapper<{{v8_class}}>(callbackInfo.GetReturnValue(), impl))
197        return;
198    v8::Handle<v8::Object> wrapper = wrap(impl, callbackInfo.Holder(), callbackInfo.GetIsolate());
199    v8SetReturnValue(callbackInfo, wrapper);
200}
201
202template<typename CallbackInfo>
203inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo, {{cpp_class}}* impl)
204{
205    ASSERT(worldType(callbackInfo.GetIsolate()) == MainWorld);
206    if (UNLIKELY(!impl)) {
207        v8SetReturnValueNull(callbackInfo);
208        return;
209    }
210    if (DOMDataStore::setReturnValueFromWrapperForMainWorld<{{v8_class}}>(callbackInfo.GetReturnValue(), impl))
211        return;
212    v8::Handle<v8::Value> wrapper = wrap(impl, callbackInfo.Holder(), callbackInfo.GetIsolate());
213    v8SetReturnValue(callbackInfo, wrapper);
214}
215
216template<class CallbackInfo, class Wrappable>
217inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo, {{cpp_class}}* impl, Wrappable* wrappable)
218{
219    if (UNLIKELY(!impl)) {
220        v8SetReturnValueNull(callbackInfo);
221        return;
222    }
223    if (DOMDataStore::setReturnValueFromWrapperFast<{{v8_class}}>(callbackInfo.GetReturnValue(), impl, callbackInfo.Holder(), wrappable))
224        return;
225    v8::Handle<v8::Object> wrapper = wrap(impl, callbackInfo.Holder(), callbackInfo.GetIsolate());
226    v8SetReturnValue(callbackInfo, wrapper);
227}
228{% endif %}{# has_custom_to_v8 #}
229
230inline v8::Handle<v8::Value> toV8(PassRefPtr<{{cpp_class}} > impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
231{
232    return toV8(impl.get(), creationContext, isolate);
233}
234
235template<class CallbackInfo>
236inline void v8SetReturnValue(const CallbackInfo& callbackInfo, PassRefPtr<{{cpp_class}} > impl)
237{
238    v8SetReturnValue(callbackInfo, impl.get());
239}
240
241template<class CallbackInfo>
242inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo, PassRefPtr<{{cpp_class}} > impl)
243{
244    v8SetReturnValueForMainWorld(callbackInfo, impl.get());
245}
246
247template<class CallbackInfo, class Wrappable>
248inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo, PassRefPtr<{{cpp_class}} > impl, Wrappable* wrappable)
249{
250    v8SetReturnValueFast(callbackInfo, impl.get(), wrappable);
251}
252
253{% if has_event_constructor %}
254bool initialize{{cpp_class}}({{cpp_class}}Init&, const Dictionary&, ExceptionState&, const String& = "");
255
256{% endif %}
257}
258{% endfilter %}
259#endif // {{v8_class}}_h
260