| {% 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 'nullptr' %} |
| {% set parent_wrapper_type_info = '&V8%s::wrapperTypeInfo' % parent_interface |
| if parent_interface else 'nullptr' %} |
| {% set active_scriptwrappable_inheritance = |
| 'kInheritFromActiveScriptWrappable' |
| if active_scriptwrappable else |
| 'kNotInheritFromActiveScriptWrappable' %} |
| |
| {% 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) && defined(__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, |
| {{prepare_prototype_and_interface_object_func or 'nullptr'}}, |
| "{{interface_name}}", |
| {{parent_wrapper_type_info}}, |
| WrapperTypeInfo::kWrapperTypeObjectPrototype, |
| WrapperTypeInfo::{{wrapper_class_id}}, |
| WrapperTypeInfo::{{active_scriptwrappable_inheritance}}, |
| WrapperTypeInfo::{{lifetime}}, |
| }; |
| #if defined(COMPONENT_BUILD) && defined(WIN32) && defined(__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 |
| // platform/bindings/ScriptWrappable.h. |
| const WrapperTypeInfo& {{cpp_class}}::wrapper_type_info_ = {{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 %} |
| |
| {##############################################################################} |
| {# Attributes #} |
| {% from 'attributes.cpp.tmpl' import attribute_getter, |
| attribute_setter, |
| with context %} |
| {% for attribute in attributes %} |
| {% 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 attribute.has_setter and not attribute.has_custom_setter %} |
| {{attribute_setter(attribute, world_suffix)}} |
| {% endif %} |
| {% endfor %} |
| {% endfor %} |
| {##############################################################################} |
| {# Methods #} |
| {% from 'methods.cpp.tmpl' import generate_method, overload_resolution_method, |
| 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 method.is_cross_origin and method.visible %} |
| {{origin_safe_method_getter(method, world_suffix)}} |
| {% endif %} |
| {% endfor %} |
| {% endfor %} |
| {% if iterator_method %} |
| {{generate_method(iterator_method)}} |
| {% endif %} |
| {% block origin_safe_method_setter %}{% endblock %} |
| {# Constructors #} |
| {% for constructor in constructors %} |
| {{generate_constructor(constructor)}} |
| {% endfor %} |
| {% block overloaded_constructor %}{% endblock %} |
| {# Special operations (methods) #} |
| {% block named_property_getter %}{% endblock %} |
| {% block named_property_setter %}{% endblock %} |
| {% block named_property_deleter %}{% endblock %} |
| {% block named_property_query %}{% endblock %} |
| {% block named_property_enumerator %}{% endblock %} |
| {% block indexed_property_getter %}{% endblock %} |
| {% block indexed_property_descriptor %}{% endblock %} |
| {% block indexed_property_setter %}{% endblock %} |
| {% block indexed_property_deleter %}{% endblock %} |
| {##############################################################################} |
| {% if has_access_check_callbacks and not is_partial and 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 %} |
| {% if attribute.has_custom_getter %} |
| {{v8_class}}::{{attribute.name}}AttributeGetterCustom, |
| {% else %} |
| &{{cpp_class}}V8Internal::{{attribute.name}}AttributeGetter, |
| {% endif %} |
| {% 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 %} |
| {##############################################################################} |
| } // namespace {{cpp_class_or_partial}}V8Internal |
| |
| {# 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_callback, attribute_setter_callback, |
| attribute_cached_property_key with context %} |
| {% for attribute in attributes %} |
| {% if attribute.is_cached_accessor %} |
| {{attribute_cached_property_key(attribute)}} |
| {% endif %} |
| {% for world_suffix in attribute.world_suffixes %} |
| {% 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 %} |
| {{attribute_setter_callback(attribute, world_suffix)}} |
| {% endif %} |
| {% endfor %} |
| {% endfor %} |
| |
| {# Methods #} |
| {% from 'methods.cpp.tmpl' import origin_safe_method_getter_callback, |
| method_callback with context %} |
| {% for method in methods %} |
| {% for world_suffix in method.world_suffixes %} |
| {% 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_callback(method, world_suffix)}} |
| {% endif %} |
| {% endfor %} |
| {% endfor %} |
| {% if iterator_method %} |
| {{method_callback(iterator_method)}} |
| {% endif %} |
| {% block origin_safe_method_setter_callback %}{% endblock %} |
| {# Special operations (methods) #} |
| {% block named_property_getter_callback %}{% endblock %} |
| {% block named_property_setter_callback %}{% endblock %} |
| {% block named_property_deleter_callback %}{% endblock %} |
| {% block named_property_query_callback %}{% endblock %} |
| {% block named_property_enumerator_callback %}{% endblock %} |
| {% block indexed_property_getter_callback %}{% endblock %} |
| {% block indexed_property_descriptor_callback %}{% endblock %} |
| {% block indexed_property_setter_callback %}{% endblock %} |
| {% block indexed_property_deleter_callback %}{% endblock %} |
| {% block indexed_property_definer_callback %}{% endblock %} |
| |
| {% if has_access_check_callbacks and not is_partial %} |
| bool {{v8_class_or_partial}}::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(accessingContext), targetWindow, BindingSecurity::ErrorReportOption::kDoNotReport); |
| {% elif interface_name == 'Location' %} |
| {{cpp_class}}* impl = {{v8_class}}::toImpl(accessedObject); |
| return BindingSecurity::ShouldAllowAccessTo(ToLocalDOMWindow(accessingContext), impl, BindingSecurity::ErrorReportOption::kDoNotReport); |
| {% else %} |
| #error "Unexpected security check for interface {{interface_name}}" |
| {% endif %} |
| } |
| |
| {% if has_cross_origin_named_getter %} |
| void {{v8_class_or_partial}}::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 : {{cpp_class_or_partial}}V8Internal::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}}::wrapperTypeInfo, |
| info.Holder()); |
| {% endif %} |
| } |
| {% endif %} |
| |
| {% if has_cross_origin_named_setter %} |
| void {{v8_class_or_partial}}::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 : {{cpp_class_or_partial}}V8Internal::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}}::wrapperTypeInfo, |
| info.Holder()); |
| } |
| {% endif %} |
| |
| {% if has_cross_origin_named_enumerator %} |
| void {{v8_class_or_partial}}::crossOriginNamedEnumerator(const v8::PropertyCallbackInfo<v8::Array>& info) { |
| Vector<String> names; |
| for (const auto& attribute : {{cpp_class_or_partial}}V8Internal::kCrossOriginAttributeTable) |
| names.push_back(attribute.name); |
| |
| // Use the current context as the creation context, as a cross-origin access |
| // may involve an object that does not have a creation context. |
| V8SetReturnValue(info, |
| ToV8(names, info.GetIsolate()->GetCurrentContext()->Global(), |
| info.GetIsolate()).As<v8::Array>()); |
| } |
| {% endif %} |
| |
| {% if has_cross_origin_indexed_getter %} |
| void {{v8_class_or_partial}}::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 %}{# has_access_check_callbacks #} |
| |
| {% 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) && defined(__clang__) |
| #pragma clang diagnostic push |
| #pragma clang diagnostic ignored "-Wglobal-constructors" |
| #endif |
| static const V8DOMConfiguration::AttributeConfiguration {{v8_class}}Attributes[] = { |
| {% for data_attribute in data_attributes %} |
| {{attribute_configuration(data_attribute) | indent(4)}}, |
| {% endfor %} |
| }; |
| #if defined(COMPONENT_BUILD) && defined(WIN32) && defined(__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) && defined(__clang__) |
| #pragma clang diagnostic push |
| #pragma clang diagnostic ignored "-Wglobal-constructors" |
| #endif |
| static const V8DOMConfiguration::AttributeConfiguration {{v8_class}}LazyDataAttributes[] = { |
| {% for data_attribute in lazy_data_attributes %} |
| {{attribute_configuration(data_attribute) | indent(4)}}, |
| {% endfor %} |
| }; |
| #if defined(COMPONENT_BUILD) && defined(WIN32) && defined(__clang__) |
| #pragma clang diagnostic pop |
| #endif |
| |
| {% endif %} |
| {% endblock %} |
| {##############################################################################} |
| {% block install_accessors %} |
| {% from 'attributes.cpp.tmpl' import accessor_configuration with context %} |
| {% if accessors %} |
| static const V8DOMConfiguration::AccessorConfiguration {{v8_class}}Accessors[] = { |
| {% for accessor in accessors %} |
| {{accessor_configuration(accessor) | indent(4)}}, |
| {% endfor %} |
| }; |
| |
| {% endif %} |
| {% endblock %} |
| {##############################################################################} |
| {% block install_methods %} |
| {% from 'methods.cpp.tmpl' import method_configuration with context %} |
| {% if methods | has_method_configuration(is_partial) %} |
| static const V8DOMConfiguration::MethodConfiguration {{v8_class}}Methods[] = { |
| {% for method in methods | has_method_configuration(is_partial) %} |
| {{method_configuration(method) | indent(4)}}, |
| {% 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, |
| method_configuration with context %} |
| {% from 'attributes.cpp.tmpl' import accessor_configuration, |
| attribute_configuration, |
| with context %} |
| {% from 'constants.cpp.tmpl' import install_constants, |
| constant_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.interface_name, {{parent_interface_template}}, {{v8_class}}::internalFieldCount); |
| {% if constructors or has_custom_constructor or has_html_constructor %} |
| interfaceTemplate->SetCallHandler({{v8_class}}::constructorCallback); |
| interfaceTemplate->SetLength({{interface_length}}); |
| {% endif %} |
| {% endif %}{# is_partial #} |
| |
| {% if runtime_enabled_feature_name and not context_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 IDL 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 = '%s::crossOriginNamedGetter' % v8_class_or_partial if has_cross_origin_named_getter else 'nullptr' %} |
| {% set cross_origin_named_setter = '%s::crossOriginNamedSetter' % v8_class_or_partial if has_cross_origin_named_setter else 'nullptr' %} |
| {% set cross_origin_named_enumerator = '%s::crossOriginNamedEnumerator' % v8_class_or_partial if has_cross_origin_named_enumerator else 'nullptr' %} |
| {% set cross_origin_indexed_getter = '%s::crossOriginIndexedGetter' % v8_class_or_partial if has_cross_origin_indexed_getter else 'nullptr' %} |
| instanceTemplate->SetAccessCheckCallbackAndHandler( |
| {{v8_class_or_partial}}::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 %} |
| |
| {% 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); |
| {% if iterable %} |
| {% if is_global %} |
| #error "iterable<V> on [Global] and [PrimaryGlobal] is currently unsupported." |
| {% endif %} |
| // For value iterators, the properties below must originally be set to the corresponding ones in %ArrayPrototype%. |
| // See https://heycam.github.io/webidl/#es-iterators. |
| prototypeTemplate->SetIntrinsicDataProperty(V8AtomicString(isolate, "entries"), v8::kArrayProto_entries); |
| prototypeTemplate->SetIntrinsicDataProperty(V8AtomicString(isolate, "forEach"), v8::kArrayProto_forEach); |
| prototypeTemplate->SetIntrinsicDataProperty(V8AtomicString(isolate, "keys"), v8::kArrayProto_keys); |
| prototypeTemplate->SetIntrinsicDataProperty(V8AtomicString(isolate, "values"), v8::kArrayProto_values); |
| {% endif %} |
| {% endif %} |
| |
| {% if iterator_method and not iterator_method.runtime_enabled_feature_name %} |
| {% filter exposed(iterator_method.exposed_test) %} |
| {% set symbol_alias = '"%s"' % iterator_method_alias |
| if iterator_method_alias else 'nullptr' %} |
| // Iterator (@@iterator) |
| static const V8DOMConfiguration::SymbolKeyedMethodConfiguration |
| symbolKeyedIteratorConfiguration = { |
| v8::Symbol::GetIterator, |
| {{symbol_alias}}, |
| {{v8_class_or_partial}}::iteratorMethodCallback, |
| 0, |
| v8::DontEnum, |
| V8DOMConfiguration::kOnPrototype, |
| V8DOMConfiguration::kCheckHolder, |
| V8DOMConfiguration::kDoNotCheckAccess |
| }; |
| V8DOMConfiguration::InstallMethod(isolate, world, prototypeTemplate, signature, symbolKeyedIteratorConfiguration); |
| {% endfilter %} |
| {% endif %} |
| |
| {% if interface_name == 'Iterator' %} |
| // The WebIDL spec says when an interface has pair iterators the iterators it |
| // returns must be instances of the "default iterator object" whose |
| // [[Prototype]] points to an "iterator prototype object" whose |
| // [[Prototype]], on its turn, points to %IteratorPrototype%. next() must be |
| // implemented in the "iterator prototype object", while %IteratorPrototype% |
| // provides @@iterator. |
| // References: |
| // https://heycam.github.io/webidl/#es-default-iterator-object |
| // https://heycam.github.io/webidl/#es-iterator-prototype-object |
| // |
| // The iterators we return from interfaces that have pair interators adhere |
| // to the above by: |
| // - Adding the "next()" property to its prototype object. |
| // - Making the prototype object inherit from %IteratorPrototype% with the |
| // hack below, which creates another function template with no prototype |
| // and sets the "prototype" property of its function object. |
| // When |interfaceTemplate|'s function object is created, its |
| // prototype.__proto__ will point to the value of the "prototype" property |
| // of |intrinsicIteratorPrototypeInterfaceTemplate|, which is exactly what |
| // we want. |
| // |
| // Finally, creating a FunctionTemplate here might look expensive since they |
| // have the same lifetime as their context, but: |
| // - |interfaceTemplate| is cached in V8PerIsolateData, so we create only one |
| // FunctionTemplate per interface. |
| // - There is only one Iterator interface that creates this FunctionTemplate, |
| // so there is no need to reuse this FunctionTemplate and register it in |
| // V8PerIsolateData. |
| v8::Local<v8::FunctionTemplate> intrinsicIteratorPrototypeInterfaceTemplate = |
| v8::FunctionTemplate::New(isolate); |
| intrinsicIteratorPrototypeInterfaceTemplate->RemovePrototype(); |
| intrinsicIteratorPrototypeInterfaceTemplate->SetIntrinsicDataProperty( |
| V8AtomicString(isolate, "prototype"), v8::kIteratorPrototype); |
| interfaceTemplate->Inherit(intrinsicIteratorPrototypeInterfaceTemplate); |
| {% endif %} |
| |
| {% if interface_name == 'DOMException' %} |
| // The WebIDL spec states that DOMException objects have a few peculiarities. |
| // One of them is similar to what it mandates for Iterator objects when it |
| // comes to the inheritance chain. Instead of |
| // DOMException -> prototype -> %ObjectPrototype% |
| // we have |
| // DOMException -> prototype -> %ErrorPrototype% -> %ObjectPrototype% |
| // so that DOMException objects "inherit" toString() and a few properties |
| // from %ErrorPrototype%. |
| // See https://heycam.github.io/webidl/#es-DOMException-specialness. |
| // |
| // We achieve this with the same hack we use for Iterators: create a new |
| // function template with no prototype, set its "prototype" property to |
| // %ErrorPrototype% and make |interfaceTemplate| inherit from it. When |
| // |interfaceTemplate| is instantiated, its prototype.__proto__ will point to |
| // |intrinsicErrorPrototypeInterfaceTemplate|'s "prototype" property. |
| v8::Local<v8::FunctionTemplate> intrinsicErrorPrototypeInterfaceTemplate = |
| v8::FunctionTemplate::New(isolate); |
| intrinsicErrorPrototypeInterfaceTemplate->RemovePrototype(); |
| intrinsicErrorPrototypeInterfaceTemplate->SetIntrinsicDataProperty( |
| V8AtomicString(isolate, "prototype"), v8::kErrorPrototype); |
| interfaceTemplate->Inherit(intrinsicErrorPrototypeInterfaceTemplate); |
| {% 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 %} |
| |
| // Custom signature |
| {% 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 not feature_name %} |
| {% if method.is_cross_origin %} |
| {{install_origin_safe_method(method, 'instanceTemplate', 'prototypeTemplate') | indent(2)}} |
| {% else %} |
| {{install_custom_signature(method, 'instanceTemplate', 'prototypeTemplate', 'interfaceTemplate', 'signature') | indent(2)}} |
| {% endif %} |
| {% endif %} |
| {% endfilter %} |
| {% endfor %} |
| {% if not has_partial_interface %} |
| |
| {{v8_class_or_partial}}::InstallRuntimeEnabledFeaturesOnTemplate( |
| isolate, world, interfaceTemplate); |
| {% endif %} |
| } |
| |
| void {{v8_class_or_partial}}::InstallRuntimeEnabledFeaturesOnTemplate( |
| v8::Isolate* isolate, |
| const DOMWrapperWorld& world, |
| v8::Local<v8::FunctionTemplate> interface_template) { |
| {% if runtime_enabled_feature_name and not context_enabled_feature_name %} |
| if (!{{runtime_enabled_feature_name | runtime_enabled_function}}) { |
| return; |
| } |
| {% endif %} |
| |
| {% if is_partial %} |
| {{v8_class}}::InstallRuntimeEnabledFeaturesOnTemplate(isolate, world, interface_template); |
| {% endif %} |
| |
| v8::Local<v8::Signature> signature = v8::Signature::New(isolate, interface_template); |
| ALLOW_UNUSED_LOCAL(signature); |
| v8::Local<v8::ObjectTemplate> instance_template = interface_template->InstanceTemplate(); |
| ALLOW_UNUSED_LOCAL(instance_template); |
| v8::Local<v8::ObjectTemplate> prototype_template = interface_template->PrototypeTemplate(); |
| ALLOW_UNUSED_LOCAL(prototype_template); |
| |
| // Register IDL constants, attributes and operations. |
| {% for feature_name, constants_list in constants | selectattr('runtime_enabled_feature_name') | groupby('runtime_enabled_feature_name') %} |
| {% filter runtime_enabled(feature_name) %} |
| static const V8DOMConfiguration::ConstantConfiguration constant_configurations[] = { |
| {% for constant in constants_list %} |
| {{constant_configuration(constant) | indent(6)}}, |
| {% endfor %} |
| }; |
| V8DOMConfiguration::InstallConstants( |
| isolate, interface_template, prototype_template, |
| constant_configurations, WTF_ARRAY_LENGTH(constant_configurations)); |
| {% endfilter %} |
| {% endfor %} |
| |
| {% for feature_name, attribute_list in runtime_enabled_attributes | selectattr('is_data_type_property') | groupby('runtime_enabled_feature_name') %} |
| {% filter runtime_enabled(feature_name) %} |
| static const V8DOMConfiguration::AttributeConfiguration attribute_configurations[] = { |
| {% for attribute in attribute_list | sort %} |
| {{attribute_configuration(attribute) | indent(6)}}, |
| {% endfor %} |
| }; |
| V8DOMConfiguration::InstallAttributes( |
| isolate, world, instance_template, prototype_template, |
| attribute_configurations, WTF_ARRAY_LENGTH(attribute_configurations)); |
| {% endfilter %} |
| {% endfor %} |
| |
| {% for feature_name, attribute_list in runtime_enabled_attributes | selectattr('is_data_type_property', 'equalto', False) | groupby('runtime_enabled_feature_name') %} |
| {% filter runtime_enabled(feature_name) %} |
| static const V8DOMConfiguration::AccessorConfiguration accessor_configurations[] = { |
| {% for attribute in attribute_list | sort %} |
| {{accessor_configuration(attribute) | indent(6)}}, |
| {% endfor %} |
| }; |
| V8DOMConfiguration::InstallAccessors( |
| isolate, world, instance_template, prototype_template, interface_template, |
| signature, accessor_configurations, |
| WTF_ARRAY_LENGTH(accessor_configurations)); |
| {% 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) %} |
| {% set symbol_alias = '"%s"' % iterator_method_alias |
| if iterator_method_alias else 'nullptr' %} |
| // Iterator (@@iterator) |
| static const V8DOMConfiguration::SymbolKeyedMethodConfiguration |
| symbol_keyed_iterator_configuration = { |
| v8::Symbol::GetIterator, |
| {{symbol_alias}}, |
| {{v8_class_or_partial}}::iteratorMethodCallback, |
| 0, |
| v8::DontEnum, |
| V8DOMConfiguration::kOnPrototype, |
| V8DOMConfiguration::kCheckHolder, |
| V8DOMConfiguration::kDoNotCheckAccess |
| }; |
| V8DOMConfiguration::InstallMethod( |
| isolate, world, prototype_template, signature, |
| symbol_keyed_iterator_configuration); |
| {% endfilter %} |
| {% endfilter %} |
| {% endif %} |
| |
| // Custom signature |
| {% 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 %} |
| {{install_origin_safe_method(method, 'instance_template', 'prototype_template') | indent(2)}} |
| {% else %} |
| {{install_custom_signature(method, 'instance_template', 'prototype_template', 'interface_template', 'signature') | indent(2)}} |
| {% endif %} |
| {% endfilter %} |
| {% endif %} |
| {% endfilter %} |
| {% endfor %} |
| } |
| |
| {% endif %}{# not is_array_buffer_or_view #} |
| {% endblock %} |
| {##############################################################################} |
| {% block install_runtime_enabled %} |
| {% if needs_runtime_enabled_installer %} |
| {% from 'attributes.cpp.tmpl' import accessor_configuration, |
| 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> interface_template = {{v8_class}}::wrapperTypeInfo.domTemplate(isolate, world); |
| v8::Local<v8::Signature> signature = v8::Signature::New(isolate, interface_template); |
| 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 | selectattr('is_data_type_property') | groupby('runtime_enabled_feature_name') %} |
| {% filter runtime_enabled(feature_name) %} |
| static const V8DOMConfiguration::AttributeConfiguration attribute_configurations[] = { |
| {% for attribute in attrs | sort %} |
| {{attribute_configuration(attribute) | indent(6)}}, |
| {% endfor %} |
| }; |
| V8DOMConfiguration::InstallAttributes(isolate, world, instance, prototype, |
| attribute_configurations, WTF_ARRAY_LENGTH(attribute_configurations)); |
| {% endfilter %} |
| {% endfor %} |
| |
| {% for feature_name, attrs in runtime_enabled_attributes | selectattr('is_data_type_property', 'equalto', False) | groupby('runtime_enabled_feature_name') %} |
| {% filter runtime_enabled(feature_name) %} |
| static const V8DOMConfiguration::AccessorConfiguration accessor_configurations[] = { |
| {% for attribute in attrs | sort %} |
| {{accessor_configuration(attribute) | indent(6)}}, |
| {% endfor %} |
| }; |
| V8DOMConfiguration::InstallAccessors(isolate, world, instance, prototype, |
| interface, signature, accessor_configurations, |
| WTF_ARRAY_LENGTH(accessor_configurations)); |
| {% endfilter %} |
| {% endfor %} |
| |
| {% if iterator_method and iterator_method.runtime_enabled_feature_name %} |
| #error "{{v8_class_or_partial}} should not have runtime enabled iterator (@@iterator)." |
| {% 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 accessor_configuration, |
| 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 optional_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 %} |
| {% if feature.needs_secure_context %} |
| ExecutionContext* executionContext = ToExecutionContext(isolate->GetCurrentContext()); |
| bool isSecureContext = (executionContext && executionContext->IsSecureContext()); |
| {% endif %}{# needs secure context #} |
| {# Origin-Trial-enabled attributes #} |
| {% for attribute in feature.attributes %} |
| {% filter secure_context(attribute.secure_context_test, 'isSecureContext') %} |
| {% if attribute.is_data_type_property %} |
| static const V8DOMConfiguration::AttributeConfiguration attribute{{attribute.name}}Configuration[] = { |
| {{attribute_configuration(attribute) | indent(2)}} |
| }; |
| for (const auto& attributeConfig : attribute{{attribute.name}}Configuration) |
| V8DOMConfiguration::InstallAttribute(isolate, world, instance, prototype, attributeConfig); |
| {% else %} |
| static const V8DOMConfiguration::AccessorConfiguration accessor{{attribute.name}}Configuration[] = { |
| {{accessor_configuration(attribute) | indent(2)}} |
| }; |
| for (const auto& accessorConfig : accessor{{attribute.name}}Configuration) |
| V8DOMConfiguration::InstallAccessor(isolate, world, instance, prototype, interface, signature, accessorConfig); |
| {% endif %} |
| {% endfilter %}{# secure_context #} |
| {% 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 %} |
| {% filter secure_context(method.secure_context_test, 'isSecureContext') %} |
| {% set method_name = method.name.title().replace('_', '') %} |
| static const V8DOMConfiguration::MethodConfiguration method{{method_name}}Configuration[] = { |
| {{method_configuration(method) | indent(2)}} |
| }; |
| for (const auto& methodConfig : method{{method_name}}Configuration) |
| V8DOMConfiguration::InstallMethod(isolate, world, instance, prototype, interface, signature, methodConfig); |
| {% endfilter %}{# secure_context #} |
| {% endfor %} |
| } |
| |
| void {{v8_class_or_partial}}::install{{feature.name}}(ScriptState* scriptState, v8::Local<v8::Object> instance) { |
| V8PerContextData* perContextData = scriptState->PerContextData(); |
| 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->GetIsolate(), 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 native_value_traits %}{% endblock %} |
| {##############################################################################} |
| {% block prepare_prototype_and_interface_object %} |
| {% from 'attributes.cpp.tmpl' import install_conditionally_enabled_attributes_on_prototype with context %} |
| {% from 'methods.cpp.tmpl' import install_conditionally_enabled_methods with context %} |
| {% if prepare_prototype_and_interface_object_func %} |
| void {{v8_class_or_partial}}::preparePrototypeAndInterfaceObject(v8::Local<v8::Context> context, const DOMWrapperWorld& world, v8::Local<v8::Object> prototypeObject, v8::Local<v8::Function> interfaceObject, v8::Local<v8::FunctionTemplate> interfaceTemplate) { |
| {% if is_partial %} |
| {{v8_class}}::preparePrototypeAndInterfaceObject(context, world, prototypeObject, interfaceObject, interfaceTemplate); |
| {% endif %} |
| |
| v8::Isolate* isolate = context->GetIsolate(); |
| {% if conditionally_enabled_attributes or conditionally_enabled_methods %} |
| v8::Local<v8::Signature> signature = v8::Signature::New(isolate, interfaceTemplate); |
| ExecutionContext* executionContext = ToExecutionContext(context); |
| DCHECK(executionContext); |
| {% if has_conditionally_enabled_secure_attributes or has_conditionally_enabled_secure_methods %} |
| bool isSecureContext = (executionContext && executionContext->IsSecureContext()); |
| {% endif %} |
| {% endif %} |
| |
| {% if unscopables %} |
| v8::Local<v8::Name> unscopablesSymbol(v8::Symbol::GetUnscopables(isolate)); |
| v8::Local<v8::Object> unscopables; |
| if (V8CallBoolean(prototypeObject->HasOwnProperty(context, unscopablesSymbol))) |
| unscopables = prototypeObject->Get(context, unscopablesSymbol).ToLocalChecked().As<v8::Object>(); |
| else |
| unscopables = v8::Object::New(isolate); |
| {% for name, runtime_enabled_feature_name in unscopables %} |
| {% filter runtime_enabled(runtime_enabled_feature_name) %} |
| unscopables->CreateDataProperty(context, V8AtomicString(isolate, "{{name}}"), v8::True(isolate)).FromJust(); |
| {% endfilter %} |
| {% endfor %} |
| prototypeObject->CreateDataProperty(context, unscopablesSymbol, unscopables).FromJust(); |
| {% endif %}{# unscopables #} |
| {% if conditionally_enabled_attributes %} |
| {{install_conditionally_enabled_attributes_on_prototype('isSecureContext') | indent(2)}} |
| {% endif %} |
| {% if conditionally_enabled_methods %} |
| {{install_conditionally_enabled_methods('isSecureContext') | indent(2)}} |
| {% endif %} |
| } |
| {% endif %} |
| |
| {% endblock %}{# prepare_prototype_and_interface_object #} |
| {##############################################################################} |
| {% block install_conditional_features_on_global %} |
| {% from 'attributes.cpp.tmpl' import install_conditionally_enabled_constructors with context %} |
| {% if has_install_conditional_features_on_global_func %} |
| void {{v8_class_or_partial}}::InstallConditionalFeaturesOnGlobal(v8::Local<v8::Context> context, const DOMWrapperWorld& world) { |
| {% if conditionally_enabled_attributes %} |
| v8::Isolate* isolate = context->GetIsolate(); |
| v8::Local<v8::Object> prototype_object; |
| v8::Local<v8::Object> instance = context->Global(); |
| ExecutionContext* executionContext = ToExecutionContext(context); |
| DCHECK(executionContext); |
| {% if has_conditionally_enabled_secure_attributes %} |
| bool isSecureContext = (executionContext && executionContext->IsSecureContext()); |
| {% endif %} |
| {% endif %}{# if conditionally_enabled_attributes #} |
| |
| {{install_conditionally_enabled_constructors('isSecureContext') | indent(2)}} |
| } |
| {% endif %} |
| |
| {% endblock %}{# install_conditional_features_on_global_func #} |
| {##############################################################################} |
| {% block partial_interface %}{% endblock %} |
| } // namespace blink |
| |
| {% endfilter %}{# format_blink_cpp_source_code #} |