Commit 9b985851 authored by peria's avatar peria Committed by Commit bot

Remove attribute filters from .tmpl files.

We rarely handle all attributes in a loop.
Instead, we have filters to iterate only on accessors,
on data type attributes, so on.
It is very confusing to have all attributes in a
variable in .py and filter them in .tmpl files.

This CL applies such filters in pre-process in .py
and uses more descriptive names in template contexts.
It keeps 'attributes' for some usages, which are
to be replaced.

This is a refactoring in template engine, so it
does not change generated code.

BUG=650150

Review-Url: https://codereview.chromium.org/2568403002
Cr-Commit-Position: refs/heads/master@{#438099}
parent ef1d2966
......@@ -12,7 +12,6 @@ import re
import sys
from idl_types import set_ancestors, IdlType
from v8_attributes import attribute_filters
from v8_globals import includes
from v8_interface import constant_filters
from v8_types import set_component_dirs
......@@ -89,7 +88,6 @@ def initialize_jinja_env(cache_dir):
'runtime_enabled': runtime_enabled_if,
'secure_context': secure_context_if,
'unique_by': unique_by})
jinja_env.filters.update(attribute_filters())
jinja_env.filters.update(constant_filters())
jinja_env.filters.update(method_filters())
return jinja_env
......
......@@ -228,7 +228,7 @@ def attribute_context(interface, attribute, interfaces):
return context
def filter_has_accessor_configuration(attributes):
def filter_accessors(attributes):
return [attribute for attribute in attributes if
not (attribute['exposed_test'] or
attribute['secure_context_test'] or
......@@ -238,26 +238,25 @@ def filter_has_accessor_configuration(attributes):
attribute['should_be_exposed_to_script']]
def filter_has_data_attribute_configuration(attributes):
return [attribute for attribute in attributes if
not (attribute['exposed_test'] or
def is_data_attribute(attribute):
return (not (attribute['exposed_test'] or
attribute['secure_context_test'] or
attribute['origin_trial_enabled_function'] or
attribute['runtime_enabled_function']) and
attribute['is_data_type_property'] and
attribute['should_be_exposed_to_script']]
attribute['should_be_exposed_to_script'])
def is_lazy_data_attribute(attribute):
return attribute['constructor_type'] and not attribute['needs_constructor_getter_callback']
def filter_has_attribute_configuration(attributes):
return [attribute for attribute in filter_has_data_attribute_configuration(attributes) if not is_lazy_data_attribute(attribute)]
def filter_data_attributes(attributes):
return [attribute for attribute in attributes if is_data_attribute(attribute) and not is_lazy_data_attribute(attribute)]
def filter_has_lazy_data_attribute_configuration(attributes):
return [attribute for attribute in filter_has_data_attribute_configuration(attributes) if is_lazy_data_attribute(attribute)]
def filter_lazy_data_attributes(attributes):
return [attribute for attribute in attributes if is_data_attribute(attribute) and is_lazy_data_attribute(attribute)]
def filter_origin_trial_enabled(attributes):
......@@ -266,21 +265,13 @@ def filter_origin_trial_enabled(attributes):
not attribute['exposed_test']]
def filter_purely_runtime_enabled(attributes):
def filter_runtime_enabled(attributes):
return [attribute for attribute in attributes if
not (attribute['exposed_test'] or
attribute['secure_context_test']) and
attribute['runtime_feature_name']]
def attribute_filters():
return {'has_accessor_configuration': filter_has_accessor_configuration,
'has_attribute_configuration': filter_has_attribute_configuration,
'has_lazy_data_attribute_configuration': filter_has_lazy_data_attribute_configuration,
'origin_trial_enabled_attributes': filter_origin_trial_enabled,
'purely_runtime_enabled_attributes': filter_purely_runtime_enabled}
################################################################################
# Getter
################################################################################
......
......@@ -371,6 +371,12 @@ def interface_context(interface, interfaces):
context.update({
'attributes': attributes,
# Elements in attributes are broken in following members.
'accessors': v8_attributes.filter_accessors(attributes),
'data_attributes': v8_attributes.filter_data_attributes(attributes),
'lazy_data_attributes': v8_attributes.filter_lazy_data_attributes(attributes),
'origin_trial_attributes': v8_attributes.filter_origin_trial_enabled(attributes),
'runtime_enabled_attributes': v8_attributes.filter_runtime_enabled(attributes),
})
# Methods
......
......@@ -13,7 +13,7 @@ namespace blink {
{% if has_event_constructor %}
class Dictionary;
{% endif %}
{% if attributes|origin_trial_enabled_attributes %}
{% if origin_trial_attributes %}
class ScriptState;
{% endif %}
{% if named_constructor %}
......
......@@ -312,7 +312,7 @@ void crossOriginIndexedGetter(uint32_t index, const v8::PropertyCallbackInfo<v8:
{##############################################################################}
{% block install_attributes %}
{% from 'attributes.cpp.tmpl' import attribute_configuration with context %}
{% if attributes | has_attribute_configuration %}
{% 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)
......@@ -320,8 +320,8 @@ void crossOriginIndexedGetter(uint32_t index, const v8::PropertyCallbackInfo<v8:
#pragma clang diagnostic ignored "-Wglobal-constructors"
#endif
const V8DOMConfiguration::AttributeConfiguration {{v8_class}}Attributes[] = {
{% for attribute in attributes | has_attribute_configuration %}
{{attribute_configuration(attribute)}},
{% for data_attribute in data_attributes %}
{{attribute_configuration(data_attribute)}},
{% endfor %}
};
#if defined(COMPONENT_BUILD) && defined(WIN32) && COMPILER(CLANG)
......@@ -333,7 +333,7 @@ const V8DOMConfiguration::AttributeConfiguration {{v8_class}}Attributes[] = {
{##############################################################################}
{% block install_lazy_data_attributes %}
{% from 'attributes.cpp.tmpl' import attribute_configuration with context %}
{% if attributes | has_lazy_data_attribute_configuration %}
{% 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)
......@@ -341,8 +341,8 @@ const V8DOMConfiguration::AttributeConfiguration {{v8_class}}Attributes[] = {
#pragma clang diagnostic ignored "-Wglobal-constructors"
#endif
const V8DOMConfiguration::AttributeConfiguration {{v8_class}}LazyDataAttributes[] = {
{% for attribute in attributes | has_lazy_data_attribute_configuration %}
{{attribute_configuration(attribute)}},
{% for data_attribute in lazy_data_attributes %}
{{attribute_configuration(data_attribute)}},
{% endfor %}
};
#if defined(COMPONENT_BUILD) && defined(WIN32) && COMPILER(CLANG)
......@@ -354,10 +354,10 @@ const V8DOMConfiguration::AttributeConfiguration {{v8_class}}LazyDataAttributes[
{##############################################################################}
{% block install_accessors %}
{% from 'attributes.cpp.tmpl' import attribute_configuration with context %}
{% if attributes | has_accessor_configuration %}
{% if accessors %}
const V8DOMConfiguration::AccessorConfiguration {{v8_class}}Accessors[] = {
{% for attribute in attributes | has_accessor_configuration %}
{{attribute_configuration(attribute)}},
{% for accessor in accessors %}
{{attribute_configuration(accessor)}},
{% endfor %}
};
......@@ -433,13 +433,13 @@ static void install{{v8_class}}Template(v8::Isolate* isolate, const DOMWrapperWo
{% if constants %}
{{install_constants() | indent(2)}}
{% endif %}
{% if attributes | has_attribute_configuration %}
{% if data_attributes %}
V8DOMConfiguration::installAttributes(isolate, world, instanceTemplate, prototypeTemplate, {{'%sAttributes' % v8_class}}, {{'WTF_ARRAY_LENGTH(%sAttributes)' % v8_class}});
{% endif %}
{% if attributes | has_lazy_data_attribute_configuration %}
{% if lazy_data_attributes %}
V8DOMConfiguration::installLazyDataAttributes(isolate, world, instanceTemplate, prototypeTemplate, {{'%sLazyDataAttributes' % v8_class}}, {{'WTF_ARRAY_LENGTH(%sLazyDataAttributes)' % v8_class}});
{% endif %}
{% if attributes | has_accessor_configuration %}
{% 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) %}
......@@ -456,7 +456,7 @@ static void install{{v8_class}}Template(v8::Isolate* isolate, const DOMWrapperWo
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 group in attributes | purely_runtime_enabled_attributes | groupby('runtime_feature_name') %}
{% for group in runtime_enabled_attributes | groupby('runtime_feature_name') %}
if ({{group.list[0].runtime_enabled_function}}()) {
{% for attribute in group.list | unique_by('name') | sort %}
{% if attribute.is_data_type_property %}
......
......@@ -10,7 +10,7 @@
namespace blink {
{% if attributes|origin_trial_enabled_attributes %}
{% if origin_trial_attributes %}
class ScriptState;
{% endif %}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment