1// Copyright 2014 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5// This file has been auto-generated by {{code_generator}}. DO NOT MODIFY! 6 7#ifndef {{v8_class}}_h 8#define {{v8_class}}_h 9 10{% filter conditional(conditional_string) %} 11{% for filename in header_includes %} 12#include "{{filename}}" 13{% endfor %} 14 15namespace blink { 16 17{% if has_event_constructor %} 18class Dictionary; 19{% endif %} 20{% if named_constructor %} 21class {{v8_class}}Constructor { 22public: 23 static v8::Handle<v8::FunctionTemplate> domTemplate(v8::Isolate*); 24 static const WrapperTypeInfo wrapperTypeInfo; 25}; 26 27{% endif %} 28class {{v8_class}} { 29public: 30 {% if has_private_script %} 31 class PrivateScript { 32 public: 33 {% for method in methods if method.is_implemented_in_private_script %} 34 static bool {{method.name}}Method({{method.argument_declarations_for_private_script | join(', ')}}); 35 {% endfor %} 36 {% for attribute in attributes if attribute.is_implemented_in_private_script %} 37 static bool {{attribute.name}}AttributeGetter(LocalFrame* frame, {{cpp_class}}* holderImpl, {{attribute.cpp_type}}* result); 38 {% if not attribute.is_read_only %} 39 static bool {{attribute.name}}AttributeSetter(LocalFrame* frame, {{cpp_class}}* holderImpl, {{attribute.argument_cpp_type}} cppValue); 40 {% endif %} 41 {% endfor %} 42 }; 43 44 {% endif %} 45 static bool hasInstance(v8::Handle<v8::Value>, v8::Isolate*); 46 static v8::Handle<v8::Object> findInstanceInPrototypeChain(v8::Handle<v8::Value>, v8::Isolate*); 47 static v8::Handle<v8::FunctionTemplate> domTemplate(v8::Isolate*); 48 static {{cpp_class}}* toImpl(v8::Handle<v8::Object> object) 49 { 50 return toImpl(blink::toScriptWrappableBase(object)); 51 } 52 static {{cpp_class}}* toImplWithTypeCheck(v8::Isolate*, v8::Handle<v8::Value>); 53 static const WrapperTypeInfo wrapperTypeInfo; 54 static void refObject(ScriptWrappableBase* internalPointer); 55 static void derefObject(ScriptWrappableBase* internalPointer); 56 static WrapperPersistentNode* createPersistentHandle(ScriptWrappableBase* internalPointer); 57 {% if has_visit_dom_wrapper %} 58 static void visitDOMWrapper(ScriptWrappableBase* internalPointer, const v8::Persistent<v8::Object>&, v8::Isolate*); 59 {% endif %} 60 {% if is_active_dom_object %} 61 static ActiveDOMObject* toActiveDOMObject(v8::Handle<v8::Object>); 62 {% endif %} 63 {% if is_event_target %} 64 static EventTarget* toEventTarget(v8::Handle<v8::Object>); 65 {% endif %} 66 {% if interface_name == 'Window' %} 67 static v8::Handle<v8::ObjectTemplate> getShadowObjectTemplate(v8::Isolate*); 68 {% endif %} 69 {% for method in methods %} 70 {% if method.is_custom %} 71 {% filter conditional(method.conditional_string) %} 72 static void {{method.name}}MethodCustom(const v8::FunctionCallbackInfo<v8::Value>&); 73 {% endfilter %} 74 {% endif %} 75 {% endfor %} 76 {% if constructors or has_custom_constructor or has_event_constructor %} 77 static void constructorCallback(const v8::FunctionCallbackInfo<v8::Value>&); 78 {% endif %} 79 {% if has_custom_constructor %} 80 static void constructorCustom(const v8::FunctionCallbackInfo<v8::Value>&); 81 {% endif %} 82 {% for attribute in attributes %} 83 {% if attribute.has_custom_getter %}{# FIXME: and not attribute.implemented_by #} 84 {% filter conditional(attribute.conditional_string) %} 85 static void {{attribute.name}}AttributeGetterCustom(const v8::PropertyCallbackInfo<v8::Value>&); 86 {% endfilter %} 87 {% endif %} 88 {% if attribute.has_custom_setter %}{# FIXME: and not attribute.implemented_by #} 89 {% filter conditional(attribute.conditional_string) %} 90 static void {{attribute.name}}AttributeSetterCustom(v8::Local<v8::Value>, const v8::PropertyCallbackInfo<void>&); 91 {% endfilter %} 92 {% endif %} 93 {% endfor %} 94 {# Custom special operations #} 95 {% if indexed_property_getter and indexed_property_getter.is_custom %} 96 static void indexedPropertyGetterCustom(uint32_t, const v8::PropertyCallbackInfo<v8::Value>&); 97 {% endif %} 98 {% if indexed_property_setter and indexed_property_setter.is_custom %} 99 static void indexedPropertySetterCustom(uint32_t, v8::Local<v8::Value>, const v8::PropertyCallbackInfo<v8::Value>&); 100 {% endif %} 101 {% if indexed_property_deleter and indexed_property_deleter.is_custom %} 102 static void indexedPropertyDeleterCustom(uint32_t, const v8::PropertyCallbackInfo<v8::Boolean>&); 103 {% endif %} 104 {% if named_property_getter and named_property_getter.is_custom %} 105 static void namedPropertyGetterCustom(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Value>&); 106 {% endif %} 107 {% if named_property_setter and named_property_setter.is_custom %} 108 static void namedPropertySetterCustom(v8::Local<v8::String>, v8::Local<v8::Value>, const v8::PropertyCallbackInfo<v8::Value>&); 109 {% endif %} 110 {% if named_property_getter and 111 named_property_getter.is_custom_property_query %} 112 static void namedPropertyQueryCustom(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Integer>&); 113 {% endif %} 114 {% if named_property_deleter and named_property_deleter.is_custom %} 115 static void namedPropertyDeleterCustom(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Boolean>&); 116 {% endif %} 117 {% if named_property_getter and 118 named_property_getter.is_custom_property_enumerator %} 119 static void namedPropertyEnumeratorCustom(const v8::PropertyCallbackInfo<v8::Array>&); 120 {% endif %} 121 {# END custom special operations #} 122 {% if has_custom_legacy_call_as_function %} 123 static void legacyCallCustom(const v8::FunctionCallbackInfo<v8::Value>&); 124 {% endif %} 125 {# Custom internal fields #} 126 {% set custom_internal_field_counter = 0 %} 127 {% if is_event_target and not is_node %} 128 {# Event listeners on DOM nodes are explicitly supported in the GC controller. #} 129 static const int eventListenerCacheIndex = v8DefaultWrapperInternalFieldCount + {{custom_internal_field_counter}}; 130 {% set custom_internal_field_counter = custom_internal_field_counter + 1 %} 131 {% endif %} 132 {# persistentHandleIndex must be the last field, if it is present. 133 Detailed explanation: https://codereview.chromium.org/139173012 134 FIXME: Remove this internal field, and share one field for either: 135 * a persistent handle (if the object is in oilpan) or 136 * a C++ pointer to the DOM object (if the object is not in oilpan) #} 137 {% if gc_type == 'GarbageCollectedObject' %} 138 static const int persistentHandleIndex = v8DefaultWrapperInternalFieldCount + {{custom_internal_field_counter}}; 139 static const int internalFieldCount = v8DefaultWrapperInternalFieldCount + {{custom_internal_field_counter}} + 1; 140 {% elif gc_type == 'WillBeGarbageCollectedObject' %} 141#if ENABLE(OILPAN) 142 static const int persistentHandleIndex = v8DefaultWrapperInternalFieldCount + {{custom_internal_field_counter}}; 143 static const int internalFieldCount = v8DefaultWrapperInternalFieldCount + {{custom_internal_field_counter}} + 1; 144#else 145 static const int internalFieldCount = v8DefaultWrapperInternalFieldCount + {{custom_internal_field_counter}}; 146#endif 147 {% elif gc_type == 'RefCountedObject' %} 148 static const int internalFieldCount = v8DefaultWrapperInternalFieldCount + {{custom_internal_field_counter}}; 149 {% endif %} 150 {# End custom internal fields #} 151 static inline ScriptWrappableBase* toScriptWrappableBase({{cpp_class}}* impl) 152 { 153 return impl->toScriptWrappableBase(); 154 } 155 156 static inline {{cpp_class}}* toImpl(ScriptWrappableBase* internalPointer) 157 { 158 return internalPointer->toImpl<{{cpp_class}}>(); 159 } 160 {% if interface_name == 'Window' %} 161 static bool namedSecurityCheckCustom(v8::Local<v8::Object> host, v8::Local<v8::Value> key, v8::AccessType, v8::Local<v8::Value> data); 162 static bool indexedSecurityCheckCustom(v8::Local<v8::Object> host, uint32_t index, v8::AccessType, v8::Local<v8::Value> data); 163 {% endif %} 164 static void installConditionallyEnabledProperties(v8::Handle<v8::Object>, v8::Isolate*){% if has_conditional_attributes %}; 165 {% else %} { } 166 {% endif %} 167 static void installConditionallyEnabledMethods(v8::Handle<v8::Object>, v8::Isolate*){% if conditionally_enabled_methods %}; 168 {% else %} { } 169 {% endif %} 170 171private: 172 {% if not has_custom_to_v8 and not is_script_wrappable %} 173 friend v8::Handle<v8::Object> wrap({{cpp_class}}*, v8::Handle<v8::Object> creationContext, v8::Isolate*); 174 static v8::Handle<v8::Object> createWrapper({{pass_cpp_type}}, v8::Handle<v8::Object> creationContext, v8::Isolate*); 175 {% endif %} 176}; 177 178{% if has_custom_to_v8 %} 179class {{cpp_class}}; 180v8::Handle<v8::Value> toV8({{cpp_class}}*, v8::Handle<v8::Object> creationContext, v8::Isolate*); 181 182template<class CallbackInfo> 183inline void v8SetReturnValue(const CallbackInfo& callbackInfo, {{cpp_class}}* impl) 184{ 185 v8SetReturnValue(callbackInfo, toV8(impl, callbackInfo.Holder(), callbackInfo.GetIsolate())); 186} 187 188template<class CallbackInfo> 189inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo, {{cpp_class}}* impl) 190{ 191 v8SetReturnValue(callbackInfo, toV8(impl, callbackInfo.Holder(), callbackInfo.GetIsolate())); 192} 193 194template<class CallbackInfo, class Wrappable> 195inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo, {{cpp_class}}* impl, Wrappable*) 196{ 197 v8SetReturnValue(callbackInfo, toV8(impl, callbackInfo.Holder(), callbackInfo.GetIsolate())); 198} 199{% else %}{# has_custom_to_v8 #} 200{% if is_script_wrappable %} 201inline v8::Handle<v8::Object> wrap({{cpp_class}}* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) 202{ 203 return impl->wrap(creationContext, isolate); 204} 205{% else %} 206v8::Handle<v8::Object> wrap({{cpp_class}}* impl, v8::Handle<v8::Object> creationContext, v8::Isolate*); 207{% endif %} 208 209inline v8::Handle<v8::Value> toV8({{cpp_class}}* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) 210{ 211 if (UNLIKELY(!impl)) 212 return v8::Null(isolate); 213 v8::Handle<v8::Value> wrapper = DOMDataStore::getWrapper<{{v8_class}}>(impl, isolate); 214 if (!wrapper.IsEmpty()) 215 return wrapper; 216 217{% if is_script_wrappable %} 218 return impl->wrap(creationContext, isolate); 219{% else %} 220 return wrap(impl, creationContext, isolate); 221{% endif %} 222} 223 224template<typename CallbackInfo> 225inline void v8SetReturnValue(const CallbackInfo& callbackInfo, {{cpp_class}}* impl) 226{ 227 if (UNLIKELY(!impl)) { 228 v8SetReturnValueNull(callbackInfo); 229 return; 230 } 231 if (DOMDataStore::setReturnValueFromWrapper<{{v8_class}}>(callbackInfo.GetReturnValue(), impl)) 232 return; 233 v8::Handle<v8::Object> wrapper = wrap(impl, callbackInfo.Holder(), callbackInfo.GetIsolate()); 234 v8SetReturnValue(callbackInfo, wrapper); 235} 236 237template<typename CallbackInfo> 238inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo, {{cpp_class}}* impl) 239{ 240 ASSERT(DOMWrapperWorld::current(callbackInfo.GetIsolate()).isMainWorld()); 241 if (UNLIKELY(!impl)) { 242 v8SetReturnValueNull(callbackInfo); 243 return; 244 } 245 if (DOMDataStore::setReturnValueFromWrapperForMainWorld<{{v8_class}}>(callbackInfo.GetReturnValue(), impl)) 246 return; 247 v8::Handle<v8::Value> wrapper = wrap(impl, callbackInfo.Holder(), callbackInfo.GetIsolate()); 248 v8SetReturnValue(callbackInfo, wrapper); 249} 250 251template<class CallbackInfo, class Wrappable> 252inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo, {{cpp_class}}* impl, Wrappable* wrappable) 253{ 254 if (UNLIKELY(!impl)) { 255 v8SetReturnValueNull(callbackInfo); 256 return; 257 } 258 if (DOMDataStore::setReturnValueFromWrapperFast<{{v8_class}}>(callbackInfo.GetReturnValue(), impl, callbackInfo.Holder(), wrappable)) 259 return; 260 v8::Handle<v8::Object> wrapper = wrap(impl, callbackInfo.Holder(), callbackInfo.GetIsolate()); 261 v8SetReturnValue(callbackInfo, wrapper); 262} 263{% endif %}{# has_custom_to_v8 #} 264 265inline v8::Handle<v8::Value> toV8({{pass_cpp_type}} impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) 266{ 267 return toV8(impl.get(), creationContext, isolate); 268} 269 270template<class CallbackInfo> 271inline void v8SetReturnValue(const CallbackInfo& callbackInfo, {{pass_cpp_type}} impl) 272{ 273 v8SetReturnValue(callbackInfo, impl.get()); 274} 275 276template<class CallbackInfo> 277inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo, {{pass_cpp_type}} impl) 278{ 279 v8SetReturnValueForMainWorld(callbackInfo, impl.get()); 280} 281 282template<class CallbackInfo, class Wrappable> 283inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo, {{pass_cpp_type}} impl, Wrappable* wrappable) 284{ 285 v8SetReturnValueFast(callbackInfo, impl.get(), wrappable); 286} 287 288{% if has_event_constructor %} 289bool initialize{{cpp_class}}({{cpp_class}}Init&, const Dictionary&, ExceptionState&, const v8::FunctionCallbackInfo<v8::Value>& info, const String& = ""); 290 291{% endif %} 292} // namespace blink 293{% endfilter %} 294#endif // {{v8_class}}_h 295