1 {# http://www.chromium.org/blink/coding-style#TOC-License #}
3 * Copyright (C) 2013 Google Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
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
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.
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.
32 {# FIXME: Rename to Python when switch #}
33 // This file has been auto-generated by code_generator_v8.pm. DO NOT MODIFY!
35 #ifndef {{v8_class}}_h
36 #define {{v8_class}}_h
38 {% filter conditional(conditional_string) %}
39 {% for filename in header_includes %}
40 #include "{{filename}}"
45 {% if has_event_constructor %}
48 {% if named_constructor %}
49 class {{v8_class}}Constructor {
51 static v8::Handle<v8::FunctionTemplate> domTemplate(v8::Isolate*, WrapperWorldType);
52 static const WrapperTypeInfo wrapperTypeInfo;
58 static bool hasInstance(v8::Handle<v8::Value>, v8::Isolate*);
59 static v8::Handle<v8::FunctionTemplate> domTemplate(v8::Isolate*, WrapperWorldType);
60 static {{cpp_class}}* toNative(v8::Handle<v8::Object> object)
62 return fromInternalPointer(object->GetAlignedPointerFromInternalField(v8DOMWrapperObjectIndex));
64 static const WrapperTypeInfo wrapperTypeInfo;
65 static void derefObject(void*);
66 {% if has_visit_dom_wrapper %}
67 static void visitDOMWrapper(void*, const v8::Persistent<v8::Object>&, v8::Isolate*);
69 {% if is_active_dom_object %}
70 static ActiveDOMObject* toActiveDOMObject(v8::Handle<v8::Object>);
72 {% if is_event_target %}
73 static EventTarget* toEventTarget(v8::Handle<v8::Object>);
75 {% if interface_name == 'Window' %}
76 static v8::Handle<v8::ObjectTemplate> getShadowObjectTemplate(v8::Isolate*, WrapperWorldType);
78 {% for method in methods if method.is_custom %}
79 {% filter conditional(method.conditional_string) %}
80 static void {{method.name}}MethodCustom(const v8::FunctionCallbackInfo<v8::Value>&);
83 {% if constructors or has_custom_constructor or has_event_constructor %}
84 static void constructorCallback(const v8::FunctionCallbackInfo<v8::Value>&);
86 {% if has_custom_constructor %}
87 static void constructorCustom(const v8::FunctionCallbackInfo<v8::Value>&);
89 {% for attribute in attributes %}
90 {% if attribute.has_custom_getter %}{# FIXME: and not attribute.implemented_by #}
91 {% filter conditional(attribute.conditional_string) %}
92 static void {{attribute.name}}AttributeGetterCustom(const v8::PropertyCallbackInfo<v8::Value>&);
95 {% if attribute.has_custom_setter %}{# FIXME: and not attribute.implemented_by #}
96 {% filter conditional(attribute.conditional_string) %}
97 static void {{attribute.name}}AttributeSetterCustom(v8::Local<v8::Value>, const v8::PropertyCallbackInfo<void>&);
101 {# Custom special operations #}
102 {% if indexed_property_getter and indexed_property_getter.is_custom %}
103 static void indexedPropertyGetterCustom(uint32_t, const v8::PropertyCallbackInfo<v8::Value>&);
105 {% if indexed_property_setter and indexed_property_setter.is_custom %}
106 static void indexedPropertySetterCustom(uint32_t, v8::Local<v8::Value>, const v8::PropertyCallbackInfo<v8::Value>&);
108 {% if indexed_property_deleter and indexed_property_deleter.is_custom %}
109 static void indexedPropertyDeleterCustom(uint32_t, const v8::PropertyCallbackInfo<v8::Boolean>&);
111 {% if named_property_getter and named_property_getter.is_custom %}
112 static void namedPropertyGetterCustom(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>&);
114 {% if named_property_setter and named_property_setter.is_custom %}
115 static void namedPropertySetterCustom(v8::Local<v8::String>, v8::Local<v8::Value>, const v8::PropertyCallbackInfo<v8::Value>&);
117 {% if named_property_getter and
118 named_property_getter.is_custom_property_query %}
119 static void namedPropertyQueryCustom(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Integer>&);
121 {% if named_property_deleter and named_property_deleter.is_custom %}
122 static void namedPropertyDeleterCustom(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Boolean>&);
124 {% if named_property_getter and
125 named_property_getter.is_custom_property_enumerator %}
126 static void namedPropertyEnumeratorCustom(const v8::PropertyCallbackInfo<v8::Array>&);
128 {# END custom special operations #}
129 {% if has_custom_legacy_call_as_function %}
130 static void legacyCallCustom(const v8::FunctionCallbackInfo<v8::Value>&);
132 {# Custom internal fields #}
133 {% set custom_internal_field_counter = 0 %}
134 {% if is_event_target and not is_node %}
135 {# Event listeners on DOM nodes are explicitly supported in the GC controller. #}
136 static const int eventListenerCacheIndex = v8DefaultWrapperInternalFieldCount + {{custom_internal_field_counter}};
137 {% set custom_internal_field_counter = custom_internal_field_counter + 1 %}
139 {# persistentHandleIndex must be the last field, if it is present.
140 Detailed explanation: https://codereview.chromium.org/139173012
141 FIXME: Remove this internal field, and share one field for either:
142 * a persistent handle (if the object is in oilpan) or
143 * a C++ pointer to the DOM object (if the object is not in oilpan) #}
144 {% if is_will_be_garbage_collected %}
145 static const int persistentHandleIndex = v8DefaultWrapperInternalFieldCount + {{custom_internal_field_counter}};
146 {% set custom_internal_field_counter = custom_internal_field_counter + 1 %}
148 static const int internalFieldCount = v8DefaultWrapperInternalFieldCount + {{custom_internal_field_counter}};
149 {# End custom internal fields #}
150 static inline void* toInternalPointer({{cpp_class}}* impl)
152 {% if parent_interface %}
153 return V8{{parent_interface}}::toInternalPointer(impl);
159 static inline {{cpp_class}}* fromInternalPointer(void* object)
161 {% if parent_interface %}
162 return static_cast<{{cpp_class}}*>(V8{{parent_interface}}::fromInternalPointer(object));
164 return static_cast<{{cpp_class}}*>(object);
167 {% if interface_name == 'Window' %}
168 static bool namedSecurityCheckCustom(v8::Local<v8::Object> host, v8::Local<v8::Value> key, v8::AccessType, v8::Local<v8::Value> data);
169 static bool indexedSecurityCheckCustom(v8::Local<v8::Object> host, uint32_t index, v8::AccessType, v8::Local<v8::Value> data);
171 static void installPerContextEnabledProperties(v8::Handle<v8::Object>, {{cpp_class}}*, v8::Isolate*){% if has_per_context_enabled_attributes %};
174 static void installPerContextEnabledMethods(v8::Handle<v8::Object>, v8::Isolate*){% if has_per_context_enabled_methods %};
177 {# Element wrappers #}
178 {% if interface_name == 'HTMLElement' %}
179 friend v8::Handle<v8::Object> createV8HTMLWrapper(HTMLElement*, v8::Handle<v8::Object> creationContext, v8::Isolate*);
180 friend v8::Handle<v8::Object> createV8HTMLDirectWrapper(HTMLElement*, v8::Handle<v8::Object> creationContext, v8::Isolate*);
181 {% elif interface_name == 'HTMLUnknownElement' %}
182 friend v8::Handle<v8::Object> createV8HTMLFallbackWrapper(HTMLUnknownElement*, v8::Handle<v8::Object> creationContext, v8::Isolate*);
183 {% elif interface_name == 'Element' %}
184 // This is a performance optimization hack. See V8Element::wrap.
185 friend v8::Handle<v8::Object> wrap(Node*, v8::Handle<v8::Object> creationContext, v8::Isolate*);
189 {% if not has_custom_to_v8 %}
190 friend v8::Handle<v8::Object> wrap({{cpp_class}}*, v8::Handle<v8::Object> creationContext, v8::Isolate*);
191 static v8::Handle<v8::Object> createWrapper({{pass_ref_ptr}}<{{cpp_class}}>, v8::Handle<v8::Object> creationContext, v8::Isolate*);
196 class WrapperTypeTraits<{{cpp_class}} > {
198 static const WrapperTypeInfo* wrapperTypeInfo() { return &{{v8_class}}::wrapperTypeInfo; }
201 {% if has_custom_to_v8 %}
203 v8::Handle<v8::Value> toV8({{cpp_class}}*, v8::Handle<v8::Object> creationContext, v8::Isolate*);
205 template<class CallbackInfo>
206 inline void v8SetReturnValue(const CallbackInfo& callbackInfo, {{cpp_class}}* impl)
208 v8SetReturnValue(callbackInfo, toV8(impl, callbackInfo.Holder(), callbackInfo.GetIsolate()));
211 template<class CallbackInfo>
212 inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo, {{cpp_class}}* impl)
214 v8SetReturnValue(callbackInfo, toV8(impl, callbackInfo.Holder(), callbackInfo.GetIsolate()));
217 template<class CallbackInfo, class Wrappable>
218 inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo, {{cpp_class}}* impl, Wrappable*)
220 v8SetReturnValue(callbackInfo, toV8(impl, callbackInfo.Holder(), callbackInfo.GetIsolate()));
222 {% else %}{# has_custom_to_v8 #}
223 {% if has_custom_wrap or special_wrap_for or is_document %}
224 v8::Handle<v8::Object> wrap({{cpp_class}}* impl, v8::Handle<v8::Object> creationContext, v8::Isolate*);
226 inline v8::Handle<v8::Object> wrap({{cpp_class}}* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
229 ASSERT(!DOMDataStore::containsWrapper<{{v8_class}}>(impl, isolate));
230 return {{v8_class}}::createWrapper(impl, creationContext, isolate);
234 inline v8::Handle<v8::Value> toV8({{cpp_class}}* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
237 return v8::Null(isolate);
238 v8::Handle<v8::Value> wrapper = DOMDataStore::getWrapper<{{v8_class}}>(impl, isolate);
239 if (!wrapper.IsEmpty())
241 return wrap(impl, creationContext, isolate);
244 template<typename CallbackInfo>
245 inline void v8SetReturnValue(const CallbackInfo& callbackInfo, {{cpp_class}}* impl)
247 if (UNLIKELY(!impl)) {
248 v8SetReturnValueNull(callbackInfo);
251 if (DOMDataStore::setReturnValueFromWrapper<{{v8_class}}>(callbackInfo.GetReturnValue(), impl))
253 v8::Handle<v8::Object> wrapper = wrap(impl, callbackInfo.Holder(), callbackInfo.GetIsolate());
254 v8SetReturnValue(callbackInfo, wrapper);
257 template<typename CallbackInfo>
258 inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo, {{cpp_class}}* impl)
260 ASSERT(worldType(callbackInfo.GetIsolate()) == MainWorld);
261 if (UNLIKELY(!impl)) {
262 v8SetReturnValueNull(callbackInfo);
265 if (DOMDataStore::setReturnValueFromWrapperForMainWorld<{{v8_class}}>(callbackInfo.GetReturnValue(), impl))
267 v8::Handle<v8::Value> wrapper = wrap(impl, callbackInfo.Holder(), callbackInfo.GetIsolate());
268 v8SetReturnValue(callbackInfo, wrapper);
271 template<class CallbackInfo, class Wrappable>
272 inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo, {{cpp_class}}* impl, Wrappable* wrappable)
274 if (UNLIKELY(!impl)) {
275 v8SetReturnValueNull(callbackInfo);
278 if (DOMDataStore::setReturnValueFromWrapperFast<{{v8_class}}>(callbackInfo.GetReturnValue(), impl, callbackInfo.Holder(), wrappable))
280 v8::Handle<v8::Object> wrapper = wrap(impl, callbackInfo.Holder(), callbackInfo.GetIsolate());
281 v8SetReturnValue(callbackInfo, wrapper);
283 {% endif %}{# has_custom_to_v8 #}
285 inline v8::Handle<v8::Value> toV8({{pass_ref_ptr}}<{{cpp_class}}> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
287 return toV8(impl.get(), creationContext, isolate);
290 template<class CallbackInfo>
291 inline void v8SetReturnValue(const CallbackInfo& callbackInfo, {{pass_ref_ptr}}<{{cpp_class}}> impl)
293 v8SetReturnValue(callbackInfo, impl.get());
296 template<class CallbackInfo>
297 inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo, {{pass_ref_ptr}}<{{cpp_class}}> impl)
299 v8SetReturnValueForMainWorld(callbackInfo, impl.get());
302 template<class CallbackInfo, class Wrappable>
303 inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo, {{pass_ref_ptr}}<{{cpp_class}}> impl, Wrappable* wrappable)
305 v8SetReturnValueFast(callbackInfo, impl.get(), wrappable);
308 {% if has_event_constructor %}
309 bool initialize{{cpp_class}}({{cpp_class}}Init&, const Dictionary&, ExceptionState&, const v8::FunctionCallbackInfo<v8::Value>& info, const String& = "");
314 #endif // {{v8_class}}_h