| {% filter format_blink_cpp_source_code %} |
| |
| {% include 'copyright_block.txt' %} |
| #include "{{v8_class_or_partial}}.h" |
| |
| {% for filename in cpp_includes if filename != '%s.h' % cpp_class_or_partial %} |
| #include "{{filename}}" |
| {% endfor %} |
| |
| namespace blink { |
| {% set dom_template = '%s::domTemplate' % v8_class if not is_array_buffer_or_view else '0' %} |
| {% set visit_dom_wrapper = '%s::visitDOMWrapper' % v8_class |
| if has_visit_dom_wrapper else '0' %} |
| {% set has_prepare_prototype_and_interface_object = |
| unscopables or has_conditional_attributes_on_prototype or |
| methods | conditionally_exposed(is_partial) %} |
| {% set prepare_prototype_and_interface_object_func = |
| '%s::preparePrototypeAndInterfaceObject' % v8_class |
| if has_prepare_prototype_and_interface_object |
| else 'nullptr' %} |
| {% set parent_wrapper_type_info = '&V8%s::wrapperTypeInfo' % parent_interface |
| if parent_interface else '0' %} |
| {% set wrapper_type_prototype = 'WrapperTypeExceptionPrototype' if is_exception else |
| 'WrapperTypeObjectPrototype' %} |
| {% set active_scriptwrappable_inheritance = |
| 'InheritFromActiveScriptWrappable' |
| if active_scriptwrappable else |
| 'NotInheritFromActiveScriptWrappable' %} |
| |
| {% set wrapper_type_info_const = '' if has_partial_interface else 'const ' %} |
| {% if not is_partial %} |
| // Suppress warning: global constructors, because struct WrapperTypeInfo is trivial |
| // and does not depend on another global objects. |
| #if defined(COMPONENT_BUILD) && defined(WIN32) && COMPILER(CLANG) |
| #pragma clang diagnostic push |
| #pragma clang diagnostic ignored "-Wglobal-constructors" |
| #endif |
| {{wrapper_type_info_const}}WrapperTypeInfo {{v8_class}}::wrapperTypeInfo = { gin::kEmbedderBlink, {{dom_template}}, {{v8_class}}::trace, {{v8_class}}::traceWrappers, {{visit_dom_wrapper}}, {{prepare_prototype_and_interface_object_func}}, "{{interface_name}}", {{parent_wrapper_type_info}}, WrapperTypeInfo::{{wrapper_type_prototype}}, WrapperTypeInfo::{{wrapper_class_id}}, WrapperTypeInfo::{{active_scriptwrappable_inheritance}}, WrapperTypeInfo::{{event_target_inheritance}}, WrapperTypeInfo::{{lifetime}} }; |
| #if defined(COMPONENT_BUILD) && defined(WIN32) && COMPILER(CLANG) |
| #pragma clang diagnostic pop |
| #endif |
| |
| {% if not is_typed_array_type %} |
| // This static member must be declared by DEFINE_WRAPPERTYPEINFO in {{cpp_class}}.h. |
| // For details, see the comment of DEFINE_WRAPPERTYPEINFO in |
| // bindings/core/v8/ScriptWrappable.h. |
| const WrapperTypeInfo& {{cpp_class}}::s_wrapperTypeInfo = {{v8_class}}::wrapperTypeInfo; |
| {% endif %} |
| |
| {% if active_scriptwrappable %} |
| // [ActiveScriptWrappable] |
| static_assert( |
| std::is_base_of<ActiveScriptWrappableBase, {{cpp_class}}>::value, |
| "{{cpp_class}} does not inherit from ActiveScriptWrappable<>, but specifying " |
| "[ActiveScriptWrappable] extended attribute in the IDL file. " |
| "Be consistent."); |
| static_assert( |
| !std::is_same<decltype(&{{cpp_class}}::hasPendingActivity), |
| decltype(&ScriptWrappable::hasPendingActivity)>::value, |
| "{{cpp_class}} is not overriding hasPendingActivity(), but is specifying " |
| "[ActiveScriptWrappable] extended attribute in the IDL file. " |
| "Be consistent."); |
| {% else %} |
| // not [ActiveScriptWrappable] |
| static_assert( |
| !std::is_base_of<ActiveScriptWrappableBase, {{cpp_class}}>::value, |
| "{{cpp_class}} inherits from ActiveScriptWrappable<>, but is not specifying " |
| "[ActiveScriptWrappable] extended attribute in the IDL file. " |
| "Be consistent."); |
| static_assert( |
| std::is_same<decltype(&{{cpp_class}}::hasPendingActivity), |
| decltype(&ScriptWrappable::hasPendingActivity)>::value, |
| "{{cpp_class}} is overriding hasPendingActivity(), but is not specifying " |
| "[ActiveScriptWrappable] extended attribute in the IDL file. " |
| "Be consistent."); |
| {% endif %} |
| |
| {% endif %}{# not is_partial #} |
| {% if not is_array_buffer_or_view %} |
| namespace {{cpp_class_or_partial}}V8Internal { |
| {% if has_partial_interface %} |
| {% for method in methods if method.overloads and method.overloads.has_partial_overloads %} |
| static void (*{{method.name}}MethodForPartialInterface)(const v8::FunctionCallbackInfo<v8::Value>&) = 0; |
| {% endfor %} |
| {% endif %} |
| |
| {# Constants #} |
| {% from 'constants.cpp.tmpl' import constant_getter_callback |
| with context %} |
| {% for constant in constants | has_special_getter %} |
| {{constant_getter_callback(constant)}} |
| {% endfor %} |
| {# Attributes #} |
| {##############################################################################} |
| {% from 'attributes.cpp.tmpl' import constructor_getter_callback, |
| attribute_getter, attribute_getter_callback, |
| attribute_setter, attribute_setter_callback, |
| attribute_cache_property_callback, |
| with context %} |
| {% for attribute in attributes %} |
| {% if attribute.is_cached_accessor %} |
| {{attribute_cache_property_callback(attribute)}} |
| {% endif %} |
| {% for world_suffix in attribute.world_suffixes %} |
| {% if not attribute.has_custom_getter and not attribute.constructor_type %} |
| {{attribute_getter(attribute, world_suffix)}} |
| {% endif %} |
| {% if not attribute.constructor_type %} |
| {{attribute_getter_callback(attribute, world_suffix)}} |
| {% elif attribute.needs_constructor_getter_callback %} |
| {{constructor_getter_callback(attribute, world_suffix)}} |
| {% endif %} |
| {% if attribute.has_setter %} |
| {% if not attribute.has_custom_setter %} |
| {{attribute_setter(attribute, world_suffix)}} |
| {% endif %} |
| {{attribute_setter_callback(attribute, world_suffix)}} |
| {% endif %} |
| {% endfor %} |
| {% endfor %} |
| {##############################################################################} |
| {# Methods #} |
| {% from 'methods.cpp.tmpl' import generate_method, overload_resolution_method, |
| method_callback, origin_safe_method_getter, generate_constructor, |
| generate_post_message_impl, runtime_determined_length_method, |
| runtime_determined_maxarg_method |
| with context %} |
| {% for method in methods %} |
| {% for world_suffix in method.world_suffixes %} |
| {% if not method.is_custom and not method.is_post_message and method.visible %} |
| {{generate_method(method, world_suffix)}} |
| {% endif %} |
| {% if method.is_post_message and not is_partial %} |
| {{generate_post_message_impl(method)}} |
| {% endif %} |
| {% if method.overloads and method.overloads.visible %} |
| {% if method.overloads.runtime_determined_lengths %} |
| {{runtime_determined_length_method(method.overloads)}} |
| {% endif %} |
| {% if method.overloads.runtime_determined_maxargs %} |
| {{runtime_determined_maxarg_method(method.overloads)}} |
| {% endif %} |
| {{overload_resolution_method(method.overloads, world_suffix)}} |
| {% endif %} |
| {% if not method.overload_index or method.overloads %} |
| {# Document about the following condition: #} |
| {# https://docs.google.com/document/d/1qBC7Therp437Jbt_QYAtNYMZs6zQ_7_tnMkNUG_ACqs/edit?usp=sharing #} |
| {% if (method.overloads and method.overloads.visible and |
| (not method.overloads.has_partial_overloads or not is_partial)) or |
| (not method.overloads and method.visible) %} |
| {# A single callback is generated for overloaded methods #} |
| {# with considering partial overloads #} |
| {{method_callback(method, world_suffix)}} |
| {% endif %} |
| {% endif %} |
| {% if method.is_cross_origin and method.visible %} |
| {{origin_safe_method_getter(method, world_suffix)}} |
| {% endif %} |
| {% endfor %} |
| {% endfor %} |
| {% if iterator_method %} |
| {{generate_method(iterator_method)}} |
| {{method_callback(iterator_method)}} |
| {% endif %} |
| {% block origin_safe_method_setter %}{% endblock %} |
| {# Constructors #} |
| {% for constructor in constructors %} |
| {{generate_constructor(constructor)}} |
| {% endfor %} |
| {% block overloaded_constructor %}{% endblock %} |
| {% block event_constructor %}{% endblock %} |
| {# Special operations (methods) #} |
| {% block named_property_getter %}{% endblock %} |
| {% block named_property_getter_callback %}{% endblock %} |
| {% block named_property_setter %}{% endblock %} |
| {% block named_property_setter_callback %}{% endblock %} |
| {% block named_property_deleter %}{% endblock %} |
| {% block named_property_deleter_callback %}{% endblock %} |
| {% block named_property_query %}{% endblock %} |
| {% block named_property_query_callback %}{% endblock %} |
| {% block named_property_enumerator %}{% endblock %} |
| {% block named_property_enumerator_callback %}{% endblock %} |
| {% block indexed_property_getter %}{% endblock %} |
| {% block indexed_property_getter_callback %}{% endblock %} |
| {% block indexed_property_setter %}{% endblock %} |
| {% block indexed_property_setter_callback %}{% endblock %} |
| {% block indexed_property_deleter %}{% endblock %} |
| {% block indexed_property_deleter_callback %}{% endblock %} |
| {##############################################################################} |
| {% block security_check_functions %} |
| {% if has_access_check_callbacks and not is_partial %} |
| {{exported}}bool securityCheck(v8::Local<v8::Context> accessingContext, v8::Local<v8::Object> accessedObject, v8::Local<v8::Value> data) { |
| {% if interface_name == 'Window' %} |
| v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| v8::Local<v8::Object> window = V8Window::findInstanceInPrototypeChain(accessedObject, isolate); |
| if (window.IsEmpty()) |
| return false; // the frame is gone. |
| |
| const DOMWindow* targetWindow = V8Window::toImpl(window); |
| return BindingSecurity::shouldAllowAccessTo(toLocalDOMWindow(toDOMWindow(accessingContext)), targetWindow, BindingSecurity::ErrorReportOption::DoNotReport); |
| {% else %}{# if interface_name == 'Window' #} |
| {# Not 'Window' means it\'s Location. #} |
| {{cpp_class}}* impl = {{v8_class}}::toImpl(accessedObject); |
| return BindingSecurity::shouldAllowAccessTo(toLocalDOMWindow(toDOMWindow(accessingContext)), impl, BindingSecurity::ErrorReportOption::DoNotReport); |
| {% endif %}{# if interface_name == 'Window' #} |
| } |
| |
| {% if has_cross_origin_named_enumerator %} |
| static const struct { |
| using GetterCallback = void(*)(const v8::PropertyCallbackInfo<v8::Value>&); |
| using SetterCallback = void(*)(v8::Local<v8::Value>, const V8CrossOriginSetterInfo&); |
| |
| const char* const name; |
| const GetterCallback getter; |
| const SetterCallback setter; |
| } kCrossOriginAttributeTable[] = { |
| {##### Cross-origin attributes #####} |
| {% for attribute in attributes if attribute.has_cross_origin_getter or attribute.has_cross_origin_setter %} |
| { |
| "{{attribute.name}}", |
| {%+ if attribute.has_cross_origin_getter %}&{{cpp_class}}V8Internal::{{attribute.name}}AttributeGetter{% else %}nullptr{% endif %}, |
| {%+ if attribute.has_cross_origin_setter %}&{{cpp_class}}V8Internal::{{attribute.name}}AttributeSetter{% else %}nullptr{% endif %}, |
| }, |
| {% endfor %} |
| {##### Cross-origin methods #####} |
| {% for method in methods if method.is_cross_origin %} |
| {"{{method.name}}", &{{cpp_class}}V8Internal::{{method.name}}OriginSafeMethodGetter, nullptr}, |
| {% endfor %} |
| }; |
| {% endif %} |
| |
| {% if has_cross_origin_named_getter %} |
| {{exported}}void crossOriginNamedGetter(v8::Local<v8::Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
| if (!name->IsString()) |
| return; |
| const AtomicString& propertyName = toCoreAtomicString(name.As<v8::String>()); |
| |
| for (const auto& attribute : kCrossOriginAttributeTable) { |
| if (propertyName == attribute.name && attribute.getter) { |
| attribute.getter(info); |
| return; |
| } |
| } |
| |
| {% if named_property_getter and named_property_getter.is_cross_origin %} |
| {% if named_property_getter.is_custom %} |
| {{v8_class}}::namedPropertyGetterCustom(propertyName, info); |
| {% else %} |
| {{cpp_class}}V8Internal::namedPropertyGetter(propertyName, info); |
| {% endif %} |
| {% else %} |
| BindingSecurity::failedAccessCheckFor( |
| info.GetIsolate(), |
| {{v8_class}}::toImpl(info.Holder())->frame()); |
| {% endif %} |
| } |
| {% endif %} |
| |
| {% if has_cross_origin_named_setter %} |
| {{exported}}void crossOriginNamedSetter(v8::Local<v8::Name> name, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) { |
| if (!name->IsString()) |
| return; |
| const AtomicString& propertyName = toCoreAtomicString(name.As<v8::String>()); |
| |
| for (const auto& attribute : kCrossOriginAttributeTable) { |
| if (propertyName == attribute.name && attribute.setter) { |
| attribute.setter(value, V8CrossOriginSetterInfo(info.GetIsolate(), info.Holder())); |
| return; |
| } |
| } |
| |
| {# If there were no matches in the cross-origin attribute table, consider it |
| an access check failure: there are no custom named setters that are |
| accessible from a cross-origin context. #} |
| |
| BindingSecurity::failedAccessCheckFor( |
| info.GetIsolate(), |
| {{v8_class}}::toImpl(info.Holder())->frame()); |
| } |
| {% endif %} |
| |
| {% if has_cross_origin_named_enumerator %} |
| {{exported}}void crossOriginNamedEnumerator(const v8::PropertyCallbackInfo<v8::Array>& info) { |
| Vector<String> names; |
| for (const auto& attribute : kCrossOriginAttributeTable) |
| names.push_back(attribute.name); |
| |
| v8SetReturnValue( |
| info, |
| ToV8(names, info.Holder(), info.GetIsolate()).As<v8::Array>()); |
| } |
| {% endif %} |
| |
| {% if has_cross_origin_indexed_getter %} |
| {{exported}}void crossOriginIndexedGetter(uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info) { |
| {% if indexed_property_getter.is_custom %} |
| {{v8_class}}::indexedPropertyGetterCustom(index, info); |
| {% else %} |
| {{cpp_class}}V8Internal::indexedPropertyGetter(index, info); |
| {% endif %} |
| } |
| {% endif %} |
| |
| {% endif %} |
| {% endblock %} |
| {##############################################################################} |
| } // namespace {{cpp_class_or_partial}}V8Internal |
| |
| {% block visit_dom_wrapper %}{% endblock %} |
| {##############################################################################} |
| {% block install_attributes %} |
| {% from 'attributes.cpp.tmpl' import attribute_configuration with context %} |
| {% if data_attributes %} |
| // Suppress warning: global constructors, because AttributeConfiguration is trivial |
| // and does not depend on another global objects. |
| #if defined(COMPONENT_BUILD) && defined(WIN32) && COMPILER(CLANG) |
| #pragma clang diagnostic push |
| #pragma clang diagnostic ignored "-Wglobal-constructors" |
| #endif |
| const V8DOMConfiguration::AttributeConfiguration {{v8_class}}Attributes[] = { |
| {% for data_attribute in data_attributes %} |
| {{attribute_configuration(data_attribute)}}, |
| {% endfor %} |
| }; |
| #if defined(COMPONENT_BUILD) && defined(WIN32) && COMPILER(CLANG) |
| #pragma clang diagnostic pop |
| #endif |
| |
| {% endif %} |
| {% endblock %} |
| {##############################################################################} |
| {% block install_lazy_data_attributes %} |
| {% from 'attributes.cpp.tmpl' import attribute_configuration with context %} |
| {% if lazy_data_attributes %} |
| // Suppress warning: global constructors, because AttributeConfiguration is trivial |
| // and does not depend on another global objects. |
| #if defined(COMPONENT_BUILD) && defined(WIN32) && COMPILER(CLANG) |
| #pragma clang diagnostic push |
| #pragma clang diagnostic ignored "-Wglobal-constructors" |
| #endif |
| const V8DOMConfiguration::AttributeConfiguration {{v8_class}}LazyDataAttributes[] = { |
| {% for data_attribute in lazy_data_attributes %} |
| {{attribute_configuration(data_attribute)}}, |
| {% endfor %} |
| }; |
| #if defined(COMPONENT_BUILD) && defined(WIN32) && COMPILER(CLANG) |
| #pragma clang diagnostic pop |
| #endif |
| |
| {% endif %} |
| {% endblock %} |
| {##############################################################################} |
| {% block install_accessors %} |
| {% from 'attributes.cpp.tmpl' import attribute_configuration with context %} |
| {% if accessors %} |
| const V8DOMConfiguration::AccessorConfiguration {{v8_class}}Accessors[] = { |
| {% for accessor in accessors %} |
| {{attribute_configuration(accessor)}}, |
| {% endfor %} |
| }; |
| |
| {% endif %} |
| {% endblock %} |
| {##############################################################################} |
| {% block install_methods %} |
| {% from 'methods.cpp.tmpl' import method_configuration with context %} |
| {% if methods | has_method_configuration(is_partial) %} |
| const V8DOMConfiguration::MethodConfiguration {{v8_class}}Methods[] = { |
| {% for method in methods | has_method_configuration(is_partial) %} |
| {{method_configuration(method)}}, |
| {% endfor %} |
| }; |
| |
| {% endif %} |
| {% endblock %} |
| {% endif %}{# not is_array_buffer_or_view #} |
| {##############################################################################} |
| {% block named_constructor %}{% endblock %} |
| {% block constructor_callback %}{% endblock %} |
| {##############################################################################} |
| {% block install_dom_template %} |
| {% if not is_array_buffer_or_view %} |
| {% from 'methods.cpp.tmpl' import install_custom_signature with context %} |
| {% from 'attributes.cpp.tmpl' import attribute_configuration with context %} |
| {% from 'constants.cpp.tmpl' import install_constants with context %} |
| {% from 'methods.cpp.tmpl' import method_configuration with context %} |
| {% if has_partial_interface or is_partial %} |
| void {{v8_class_or_partial}}::install{{v8_class}}Template(v8::Isolate* isolate, const DOMWrapperWorld& world, v8::Local<v8::FunctionTemplate> interfaceTemplate) { |
| {% else %} |
| static void install{{v8_class}}Template(v8::Isolate* isolate, const DOMWrapperWorld& world, v8::Local<v8::FunctionTemplate> interfaceTemplate) { |
| {% endif %} |
| // Initialize the interface object's template. |
| {% if is_partial %} |
| {{v8_class}}::install{{v8_class}}Template(isolate, world, interfaceTemplate); |
| {% else %} |
| {% set parent_interface_template = |
| '%s::domTemplateForNamedPropertiesObject(isolate, world)' % v8_class |
| if has_named_properties_object else |
| 'V8%s::domTemplate(isolate, world)' % parent_interface |
| if parent_interface else |
| 'v8::Local<v8::FunctionTemplate>()' %} |
| V8DOMConfiguration::initializeDOMInterfaceTemplate(isolate, interfaceTemplate, {{v8_class}}::wrapperTypeInfo.interfaceName, {{parent_interface_template}}, {{v8_class}}::internalFieldCount); |
| {% if constructors or has_custom_constructor or has_event_constructor or has_html_constructor %} |
| interfaceTemplate->SetCallHandler({{v8_class}}::constructorCallback); |
| interfaceTemplate->SetLength({{interface_length}}); |
| {% endif %} |
| {% endif %}{# is_partial #} |
| |
| {% if runtime_enabled_feature_name %} |
| if (!{{runtime_enabled_feature_name | runtime_enabled_function}}) { |
| return; |
| } |
| {% endif %} |
| |
| v8::Local<v8::Signature> signature = v8::Signature::New(isolate, interfaceTemplate); |
| ALLOW_UNUSED_LOCAL(signature); |
| v8::Local<v8::ObjectTemplate> instanceTemplate = interfaceTemplate->InstanceTemplate(); |
| ALLOW_UNUSED_LOCAL(instanceTemplate); |
| v8::Local<v8::ObjectTemplate> prototypeTemplate = interfaceTemplate->PrototypeTemplate(); |
| ALLOW_UNUSED_LOCAL(prototypeTemplate); |
| |
| {% if interface_name == 'Window' and not is_partial %} |
| prototypeTemplate->SetInternalFieldCount(V8Window::internalFieldCount); |
| {% endif %} |
| |
| {% if is_immutable_prototype %} |
| // Global object prototype chain consists of Immutable Prototype Exotic Objects |
| prototypeTemplate->SetImmutableProto(); |
| {% endif %} |
| |
| {% if is_global %} |
| // Global objects are Immutable Prototype Exotic Objects |
| instanceTemplate->SetImmutableProto(); |
| {% endif %} |
| |
| // Register DOM constants, attributes and operations. |
| {% if constants %} |
| {{install_constants() | indent(2)}} |
| {% endif %} |
| {% if data_attributes %} |
| V8DOMConfiguration::installAttributes(isolate, world, instanceTemplate, prototypeTemplate, {{'%sAttributes' % v8_class}}, {{'WTF_ARRAY_LENGTH(%sAttributes)' % v8_class}}); |
| {% endif %} |
| {% if lazy_data_attributes %} |
| V8DOMConfiguration::installLazyDataAttributes(isolate, world, instanceTemplate, prototypeTemplate, {{'%sLazyDataAttributes' % v8_class}}, {{'WTF_ARRAY_LENGTH(%sLazyDataAttributes)' % v8_class}}); |
| {% endif %} |
| {% if accessors %} |
| V8DOMConfiguration::installAccessors(isolate, world, instanceTemplate, prototypeTemplate, interfaceTemplate, signature, {{'%sAccessors' % v8_class}}, {{'WTF_ARRAY_LENGTH(%sAccessors)' % v8_class}}); |
| {% endif %} |
| {% if methods | has_method_configuration(is_partial) %} |
| V8DOMConfiguration::installMethods(isolate, world, instanceTemplate, prototypeTemplate, interfaceTemplate, signature, {{'%sMethods' % v8_class}}, {{'WTF_ARRAY_LENGTH(%sMethods)' % v8_class}}); |
| {% endif %} |
| |
| {% if has_access_check_callbacks and not is_partial %} |
| // Cross-origin access check |
| {% set cross_origin_named_getter = '%sV8Internal::crossOriginNamedGetter' % cpp_class if has_cross_origin_named_getter else 'nullptr' %} |
| {% set cross_origin_named_setter = '%sV8Internal::crossOriginNamedSetter' % cpp_class if has_cross_origin_named_setter else 'nullptr' %} |
| {% set cross_origin_named_enumerator = '%sV8Internal::crossOriginNamedEnumerator' % cpp_class if has_cross_origin_named_enumerator else 'nullptr' %} |
| {% set cross_origin_indexed_getter = '%sV8Internal::crossOriginIndexedGetter' % cpp_class if has_cross_origin_indexed_getter else 'nullptr' %} |
| instanceTemplate->SetAccessCheckCallbackAndHandler({{cpp_class}}V8Internal::securityCheck, v8::NamedPropertyHandlerConfiguration({{cross_origin_named_getter}}, {{cross_origin_named_setter}}, nullptr, nullptr, {{cross_origin_named_enumerator}}), v8::IndexedPropertyHandlerConfiguration({{cross_origin_indexed_getter}}), v8::External::New(isolate, const_cast<WrapperTypeInfo*>(&{{v8_class}}::wrapperTypeInfo))); |
| {% endif %} |
| |
| {% for feature_name, attribute_list in runtime_enabled_attributes | groupby('runtime_enabled_feature_name') %} |
| {% filter runtime_enabled(feature_name) %} |
| {% for attribute in attribute_list | unique_by('name') | sort %} |
| {% if attribute.is_data_type_property %} |
| const V8DOMConfiguration::AttributeConfiguration attribute{{attribute.name}}Configuration = {{attribute_configuration(attribute)}}; |
| V8DOMConfiguration::installAttribute(isolate, world, instanceTemplate, prototypeTemplate, attribute{{attribute.name}}Configuration); |
| {% else %} |
| const V8DOMConfiguration::AccessorConfiguration accessor{{attribute.name}}Configuration = {{attribute_configuration(attribute)}}; |
| V8DOMConfiguration::installAccessor(isolate, world, instanceTemplate, prototypeTemplate, interfaceTemplate, signature, accessor{{attribute.name}}Configuration); |
| {% endif %} |
| {% endfor %} |
| {% endfilter %} |
| {% endfor %} |
| |
| {% if (indexed_property_getter or named_property_getter) and not is_partial %} |
| // Indexed properties |
| {{install_indexed_property_handler('instanceTemplate') | indent(2)}} |
| {% endif %} |
| {% if named_property_getter and not is_partial and not has_named_properties_object %} |
| // Named properties |
| {{install_named_property_handler('instanceTemplate') | indent(2)}} |
| {% endif %} |
| |
| {% if has_array_iterator and not is_partial %} |
| // Array iterator (@@iterator) |
| {%+ if is_global %}instanceTemplate{% else %}prototypeTemplate{% endif %}->SetIntrinsicDataProperty(v8::Symbol::GetIterator(isolate), v8::kArrayProto_values, v8::DontEnum); |
| {% endif %} |
| |
| {% if iterator_method %} |
| {% filter exposed(iterator_method.exposed_test) %} |
| {% filter runtime_enabled(iterator_method.runtime_enabled_feature_name) %} |
| // Iterator (@@iterator) |
| const V8DOMConfiguration::SymbolKeyedMethodConfiguration symbolKeyedIteratorConfiguration = { v8::Symbol::GetIterator, {{cpp_class_or_partial}}V8Internal::iteratorMethodCallback, 0, v8::DontEnum, V8DOMConfiguration::OnPrototype }; |
| V8DOMConfiguration::installMethod(isolate, world, prototypeTemplate, signature, symbolKeyedIteratorConfiguration); |
| {% endfilter %} |
| {% endfilter %} |
| {% endif %} |
| |
| {% if interface_name == 'Location' %} |
| // Symbol.toPrimitive |
| // Prevent author scripts to inject Symbol.toPrimitive property into location |
| // objects, also prevent the look-up of Symbol.toPrimitive through the |
| // prototype chain. |
| instanceTemplate->Set(v8::Symbol::GetToPrimitive(isolate), |
| v8::Undefined(isolate), |
| static_cast<v8::PropertyAttribute>( |
| v8::ReadOnly | v8::DontEnum | v8::DontDelete)); |
| {% endif %} |
| |
| {% if legacy_caller and not is_partial %} |
| instanceTemplate->SetCallAsFunctionHandler({{cpp_class_or_partial}}V8Internal::{{legacy_caller.name}}MethodCallback); |
| {% elif has_custom_legacy_call_as_function and not is_partial %} |
| instanceTemplate->SetCallAsFunctionHandler({{v8_class}}::legacyCallCustom); |
| {% endif %} |
| |
| {% if interface_name == 'HTMLAllCollection' and not is_partial %} |
| // Needed for legacy support of document.all |
| instanceTemplate->MarkAsUndetectable(); |
| {% endif %} |
| |
| {% if methods | custom_registration(is_partial) %} |
| {% for method in methods | custom_registration(is_partial) %} |
| {# install_custom_signature #} |
| {% filter exposed(method.overloads.exposed_test_all |
| if method.overloads else method.exposed_test) %} |
| {% filter runtime_enabled(method.overloads.runtime_enabled_all |
| if method.overloads else method.runtime_enabled_feature_name) %} |
| {% if method.is_cross_origin %} |
| {# TODO(dcheng): Currently, bindings must create a function object for each |
| realm as a hack to support the incumbent realm. Remove this when Blink |
| properly supports the incumbent realm. #} |
| {{install_origin_safe_method(method, '', 'instanceTemplate', 'prototypeTemplate') | indent(2)}} |
| {% else %} |
| {{install_custom_signature(method, 'instanceTemplate', 'prototypeTemplate', 'interfaceTemplate', 'signature') | indent(2)}} |
| {% endif %} |
| {% endfilter %} |
| {% endfilter %} |
| {% endfor %} |
| {% endif %} |
| } |
| |
| {% endif %}{# not is_array_buffer_or_view #} |
| {% endblock %} |
| {##############################################################################} |
| {% block install_runtime_enabled %} |
| {% if needs_runtime_enabled_installer %} |
| {% from 'attributes.cpp.tmpl' import attribute_configuration with context %} |
| {% from 'methods.cpp.tmpl' import install_custom_signature with context %} |
| void {{v8_class_or_partial}}::installRuntimeEnabledFeatures(v8::Isolate* isolate, const DOMWrapperWorld& world, v8::Local<v8::Object> instance, v8::Local<v8::Object> prototype, v8::Local<v8::Function> interface) { |
| {% if runtime_enabled_feature_name %} |
| #error "We don't expect a runtime enabled interface {{v8_class_or_partial}} to have installRuntimeEnabledFeatures()." |
| {% endif %} |
| |
| {% if is_partial %} |
| {{v8_class}}::installRuntimeEnabledFeatures(isolate, world, instance, prototype, interface); |
| {% endif %} |
| |
| v8::Local<v8::FunctionTemplate> interfaceTemplate = {{v8_class}}::wrapperTypeInfo.domTemplate(isolate, world); |
| v8::Local<v8::Signature> signature = v8::Signature::New(isolate, interfaceTemplate); |
| ALLOW_UNUSED_LOCAL(signature); |
| |
| {# TODO(peria): Generate code to install constants. It depends on runtime_enabled_feaure of this interface. #} |
| |
| {% for feature_name, attrs in runtime_enabled_attributes | groupby('runtime_enabled_feature_name') %} |
| {% filter runtime_enabled(feature_name) %} |
| {% for attribute in attrs | unique_by('name') | sort %} |
| {% if attribute.is_data_type_property %} |
| const V8DOMConfiguration::AttributeConfiguration attribute{{attribute.name}}Configuration = {{attribute_configuration(attribute)}}; |
| V8DOMConfiguration::installAttribute(isolate, world, instance, prototype, attribute{{attribute.name}}Configuration); |
| {% else %} |
| const V8DOMConfiguration::AccessorConfiguration accessor{{attribute.name}}Configuration = {{attribute_configuration(attribute)}}; |
| V8DOMConfiguration::installAccessor(isolate, world, instance, prototype, interface, signature, accessor{{attribute.name}}Configuration); |
| {% endif %} |
| {% endfor %} |
| {% endfilter %} |
| {% endfor %} |
| |
| {% if iterator_method and iterator_method.runtime_enabled_feature_name %} |
| {% filter exposed(iterator_method.exposed_test) %} |
| {% filter runtime_enabled(iterator_method.runtime_enabled_feature_name) %} |
| // Runtime enabled iterator (@@iterator) |
| #error "{{v8_class_or_partial}} should not have runtime enabled iterators." |
| {% endfilter %} |
| {% endfilter %} |
| {% endif %} |
| |
| {% if methods | custom_registration(is_partial) %} |
| {% for method in methods | custom_registration(is_partial) %} |
| {% filter exposed(method.overloads.exposed_test_all |
| if method.overloads else method.exposed_test) %} |
| {% set feature_name = (method.overloads.runtime_enabled_all |
| if method.overloads else method.runtime_enabled_feature_name) %} |
| {% if feature_name %} |
| {% filter runtime_enabled(feature_name) %} |
| {% if method.is_cross_origin %} |
| #error "{{v8_class_or_partial}} should not have runtime enabled and cross origin methods." |
| {% else %} |
| {{install_custom_signature(method, 'instance', 'prototype', 'interface', 'signature') | indent(2)}} |
| {% endif %} |
| {% endfilter %} |
| {% endif %} |
| {% endfilter %} |
| {% endfor %} |
| {% endif %} |
| } |
| |
| {% endif %}{# needs_runtime_enabled_installer #} |
| {% endblock %} |
| {##############################################################################} |
| {% block origin_trials %} |
| {% from 'attributes.cpp.tmpl' import attribute_configuration with context %} |
| {% from 'constants.cpp.tmpl' import constant_configuration with context %} |
| {% from 'methods.cpp.tmpl' import method_configuration with context %} |
| {% for feature in origin_trial_features %} |
| void {{v8_class_or_partial}}::install{{feature.name}}(v8::Isolate* isolate, const DOMWrapperWorld& world, v8::Local<v8::Object> instance, v8::Local<v8::Object> prototype, v8::Local<v8::Function> interface) { |
| {% if feature.attributes or feature.methods %} |
| v8::Local<v8::FunctionTemplate> interfaceTemplate = {{v8_class}}::wrapperTypeInfo.domTemplate(isolate, world); |
| v8::Local<v8::Signature> signature = v8::Signature::New(isolate, interfaceTemplate); |
| ALLOW_UNUSED_LOCAL(signature); |
| {% endif %} |
| {# Origin-Trial-enabled attributes #} |
| {% for attribute in feature.attributes %} |
| {% if attribute.is_data_type_property %} |
| const V8DOMConfiguration::AttributeConfiguration attribute{{attribute.name}}Configuration = {{attribute_configuration(attribute)}}; |
| V8DOMConfiguration::installAttribute(isolate, world, instance, prototype, attribute{{attribute.name}}Configuration); |
| {% else %} |
| const V8DOMConfiguration::AccessorConfiguration accessor{{attribute.name}}Configuration = {{attribute_configuration(attribute)}}; |
| V8DOMConfiguration::installAccessor(isolate, world, instance, prototype, interface, signature, accessor{{attribute.name}}Configuration); |
| {% endif %} |
| {% endfor %} |
| {# Origin-Trial-enabled constants #} |
| {% for constant in feature.constants %} |
| {% set constant_name = constant.name.title().replace('_', '') %} |
| const V8DOMConfiguration::ConstantConfiguration constant{{constant_name}}Configuration = {{constant_configuration(constant)}}; |
| V8DOMConfiguration::installConstant(isolate, interface, prototype, constant{{constant_name}}Configuration); |
| {% endfor %} |
| {# Origin-Trial-enabled methods (no overloads) #} |
| {% for method in feature.methods %} |
| {% set method_name = method.name.title().replace('_', '') %} |
| const V8DOMConfiguration::MethodConfiguration method{{method_name}}Configuration = {{method_configuration(method)}}; |
| V8DOMConfiguration::installMethod(isolate, world, instance, prototype, interface, signature, method{{method_name}}Configuration); |
| {% endfor %} |
| } |
| |
| void {{v8_class_or_partial}}::install{{feature.name}}(ScriptState* scriptState, v8::Local<v8::Object> instance) { |
| V8PerContextData* perContextData = V8PerContextData::from(scriptState->context()); |
| v8::Local<v8::Object> prototype = perContextData->prototypeForType(&{{v8_class}}::wrapperTypeInfo); |
| v8::Local<v8::Function> interface = perContextData->constructorForType(&{{v8_class}}::wrapperTypeInfo); |
| ALLOW_UNUSED_LOCAL(interface); |
| install{{feature.name}}(scriptState->isolate(), scriptState->world(), instance, prototype, interface); |
| } |
| {% if not feature.needs_instance %} |
| |
| void {{v8_class_or_partial}}::install{{feature.name}}(ScriptState* scriptState) { |
| install{{feature.name}}(scriptState, v8::Local<v8::Object>()); |
| } |
| {% endif %} |
| |
| {% endfor %}{# feature #} |
| {% endblock %} |
| {##############################################################################} |
| {% block get_dom_template %}{% endblock %} |
| {% block get_dom_template_for_named_properties_object %}{% endblock %} |
| {% block has_instance %}{% endblock %} |
| {% block to_impl %}{% endblock %} |
| {% block to_impl_with_type_check %}{% endblock %} |
| {##############################################################################} |
| {% block prepare_prototype_and_interface_object %}{% endblock %} |
| {##############################################################################} |
| {% block partial_interface %}{% endblock %} |
| } // namespace blink |
| |
| {% endfilter %}{# format_blink_cpp_source_code #} |