Commit 8f665179 authored by Hitoshi Yoshida's avatar Hitoshi Yoshida Committed by Commit Bot

bindings: Cleanup v8_context_snapshot_external_references

Templates and scripts to generate v8_context_snapshot_external_references
have some dead code because of historical reasons.
This CL clean up them to reduce the generate process and the generated code.
As a result, the number of entries in the table becomes 1741 from 1766,
and 3 includes are removed.

In detail, this CL does following changes.
- Avoids checking interfaces that are not exposed to Window
- Removes unused white list
- Removes unnecessary check
- Removes unused template parameter
- Renames internal const variable from snake_case to kCamelCase.


Bug: None
Change-Id: If7c439d7b1085ef8c03cfb72b37343e3989feaeb
Reviewed-on: https://chromium-review.googlesource.com/c/1354724
Commit-Queue: Hitoshi Yoshida <peria@chromium.org>
Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612082}
parent 5b778247
......@@ -23,18 +23,11 @@ INCLUDES = frozenset([
'third_party/blink/renderer/bindings/core/v8/v8_html_document.h',
'third_party/blink/renderer/bindings/core/v8/v8_initializer.h',
'third_party/blink/renderer/bindings/core/v8/v8_window.h',
'third_party/blink/renderer/platform/bindings/dom_wrapper_world.h',
'third_party/blink/renderer/platform/bindings/v8_object_constructor.h',
'third_party/blink/renderer/platform/bindings/v8_per_isolate_data.h',
'third_party/blink/renderer/platform/bindings/v8_private_property.h',
'v8/include/v8.h'])
TEMPLATE_FILE = 'external_reference_table.cc.tmpl'
WHITE_LIST_INTERFACES = frozenset([
'DOMMatrix', # crbug.com/733481
])
SNAPSHOTTED_INTERFACES = frozenset([
'Window',
'EventTarget',
......@@ -119,7 +112,7 @@ class InterfaceTemplateContextBuilder(object):
return {
'attributes': attributes,
'exported': '%s_EXPORT ' % component.upper(),
'component': component,
'has_origin_safe_method_setter': has_origin_safe_method_setter,
'has_constructor_callback': has_constructor_callback,
'has_cross_origin_named_getter': has_cross_origin_named_getter,
......@@ -131,17 +124,14 @@ class InterfaceTemplateContextBuilder(object):
'indexed_property_setter': v8_interface.property_setter(interface.indexed_property_setter, interface),
'indexed_property_deleter': v8_interface.property_deleter(interface.indexed_property_deleter),
'internal_namespace': v8_interface.internal_namespace(interface),
'is_array_buffer_or_view': interface.idl_type.is_array_buffer_or_view,
'is_callback': interface.is_callback,
'is_partial': interface.is_partial,
'is_snapshotted': interface in SNAPSHOTTED_INTERFACES,
'methods': methods,
'name': name,
'named_constructor': v8_interface.named_constructor_context(interface),
'named_property_getter': named_property_getter,
'named_property_setter': v8_interface.property_setter(interface.named_property_setter, interface),
'named_property_deleter': v8_interface.property_deleter(interface.named_property_deleter),
'v8_name': v8_utilities.v8_class_name_or_partial(interface),
'v8_class': v8_utilities.v8_class_name_or_partial(interface),
}
......@@ -171,14 +161,15 @@ class ExternalReferenceTableGenerator(object):
# in V8 context snapshot, so we can skip them.
def _process_interface(self, interface, component, interfaces):
def has_impl(interface):
if interface.name in WHITE_LIST_INTERFACES:
return True
# Non legacy callback interface does not provide V8 callbacks.
if interface.is_callback:
return len(interface.constants) > 0
if 'RuntimeEnabled' in interface.extended_attributes:
return False
return True
if 'Exposed' not in interface.extended_attributes:
return True
return any(exposure.exposed == 'Window' and exposure.runtime_enabled is None
for exposure in interface.extended_attributes['Exposed'])
if not has_impl(interface):
return
......@@ -193,7 +184,7 @@ class ExternalReferenceTableGenerator(object):
return
include_file = 'third_party/blink/renderer/bindings/%s/v8/%s.h' % (
component, utilities.to_snake_case(context['v8_name']))
component, utilities.to_snake_case(context['v8_class']))
self._include_files.add(include_file)
# Gathers all interface-dependent information and returns as a Jinja template context.
......
......@@ -12,115 +12,109 @@
namespace blink {
{# We use forward declaration instead of include for faster compile time here. #}
// We use forward declaration instead of include for faster compile time here.
{% for interface in interfaces %}
{% if interface.has_constructor_callback %}
namespace {{interface.internal_namespace}} {
{{interface.exported}}void ConstructorCallback(const v8::FunctionCallbackInfo<v8::Value>&);
{{interface.component|upper}}_EXPORT void ConstructorCallback(const v8::FunctionCallbackInfo<v8::Value>&);
} // namespace {{interface.internal_namespace}}
{% endif %}
{% endfor %}
const intptr_t* {{class}}::GetTable() {
static const intptr_t reference_table[] = {
static const intptr_t kReferenceTable[] = {
#if defined(USE_V8_CONTEXT_SNAPSHOT)
// Android is sensitive on its APK size, and this table improves it.
// So we drop the table entries until the V8 context snapshot feature
// is released on Android.
{% for interface in interfaces %}
{% if not interface.is_array_buffer_or_view %}
{% set v8_class = interface.v8_name %}
{% set v8_class = interface.v8_class %}
{# Attributes #}
{%- for attribute in interface.attributes %}
{%- for world_suffix in attribute.world_suffixes %}
{% if not attribute.constructor_type %}
{% if not attribute.constructor_type %}
reinterpret_cast<intptr_t>({{v8_class}}::{{attribute.camel_case_name}}AttributeGetterCallback{{world_suffix}}),
{% else %}
{% else %}
reinterpret_cast<intptr_t>({{v8_class}}::{{attribute.camel_case_name}}ConstructorGetterCallback{{world_suffix}}),
{% endif %}
{% if attribute.has_setter %}
{% endif %}
{% if attribute.has_setter %}
reinterpret_cast<intptr_t>({{v8_class}}::{{attribute.camel_case_name}}AttributeSetterCallback{{world_suffix}}),
{% endif %}
{% endif %}
{%- endfor %}{# world_suffix #}
{%- endfor %}{# attributes #}
{# Methods / Operations #}
{% for method in interface.methods %}
{%- for world_suffix in method.world_suffixes %}
{% if not method.overload_index or method.overloads %}
{% if (method.overloads and method.overloads.visible and
(not method.overloads.has_partial_overloads or not interface.is_partial)) or
(not method.overloads and method.visible) %}
{# TODO(bashi): Remove this 'if' condition when crbug.com/630986 is fixed. #}
{% if not interface.is_callback %}
{% for method in interface.methods %}
{%- for world_suffix in method.world_suffixes %}
{% if not method.overload_index or method.overloads %}
{% if (method.overloads and method.overloads.visible and
(not method.overloads.has_partial_overloads or not interface.is_partial)) or
(not method.overloads and method.visible) %}
reinterpret_cast<intptr_t>({{v8_class}}::{{method.camel_case_name}}MethodCallback{{world_suffix}}),
{% endif %}
{% endif %}
{% endif %}{# overload(_index) #}
{% if method.is_cross_origin and method.visible %}
{% endif %}
{% endif %}
{% if method.is_cross_origin and method.visible and not method.overloads %}
reinterpret_cast<intptr_t>({{v8_class}}::{{method.camel_case_name}}OriginSafeMethodGetterCallback{{world_suffix}}),
{% endif%}
{% endfor %}
{% endfor %}{# method #}
{% if interface.has_origin_safe_method_setter %}
{% endif%}
{% endfor %}
{% endfor %}{# method #}
{% if interface.has_origin_safe_method_setter %}
reinterpret_cast<intptr_t>({{v8_class}}::{{interface.name}}OriginSafeMethodSetterCallback),
{% endif %}
{% if interface.has_cross_origin_named_getter %}
{% endif %}
{% if interface.has_cross_origin_named_getter %}
reinterpret_cast<intptr_t>({{v8_class}}::CrossOriginNamedGetter),
{% endif %}
{% if interface.has_cross_origin_named_setter %}
{% endif %}
{% if interface.has_cross_origin_named_setter %}
reinterpret_cast<intptr_t>({{v8_class}}::CrossOriginNamedSetter),
{% endif %}
{% if interface.has_cross_origin_named_enumerator %}
{% endif %}
{% if interface.has_cross_origin_named_enumerator %}
reinterpret_cast<intptr_t>({{v8_class}}::CrossOriginNamedEnumerator),
{% endif %}
{% if interface.has_cross_origin_indexed_getter %}
{% endif %}
{% if interface.has_cross_origin_indexed_getter %}
reinterpret_cast<intptr_t>({{v8_class}}::CrossOriginIndexedGetter),
{% endif %}
{% if interface.has_security_check %}
{% endif %}
{% if interface.has_security_check %}
reinterpret_cast<intptr_t>({{v8_class}}::SecurityCheck),
reinterpret_cast<intptr_t>(&{{v8_class}}::wrapper_type_info),
{% endif %}
{# Other properties #}
{% if interface.has_constructor_callback %}
{% if interface.has_constructor_callback %}
reinterpret_cast<intptr_t>({{interface.internal_namespace}}::ConstructorCallback),
{% endif %}
{% if interface.named_property_getter %}
{% endif %}
{% if interface.named_property_getter %}
reinterpret_cast<intptr_t>({{v8_class}}::NamedPropertyGetterCallback),
{% endif %}
{%- if interface.named_property_setter %}
{% endif %}
{% if interface.named_property_setter %}
reinterpret_cast<intptr_t>({{v8_class}}::NamedPropertySetterCallback),
{% endif %}
{%- if interface.named_property_deleter %}
{% endif %}
{% if interface.named_property_deleter %}
reinterpret_cast<intptr_t>({{v8_class}}::NamedPropertyDeleterCallback),
{% endif %}
{%- if interface.named_property_getter and interface.named_property_getter.is_enumerable %}
{% endif %}
{% if interface.named_property_getter and interface.named_property_getter.is_enumerable %}
reinterpret_cast<intptr_t>({{v8_class}}::NamedPropertyQueryCallback),
reinterpret_cast<intptr_t>({{v8_class}}::NamedPropertyEnumeratorCallback),
{% endif %}
{%- if interface.indexed_property_getter %}
{% endif %}
{% if interface.indexed_property_getter %}
reinterpret_cast<intptr_t>({{v8_class}}::IndexedPropertyGetterCallback),
reinterpret_cast<intptr_t>({{v8_class}}::IndexedPropertyDefinerCallback),
reinterpret_cast<intptr_t>({{v8_class}}::IndexedPropertyDescriptorCallback),
{% endif %}
{%- if interface.indexed_property_getter or interface.named_property_setter %}
{% endif %}
{% if interface.indexed_property_getter or interface.named_property_setter %}
reinterpret_cast<intptr_t>({{v8_class}}::IndexedPropertySetterCallback),
{% endif %}
{%- if interface.indexed_property_deleter %}
{% endif %}
{% if interface.indexed_property_deleter %}
reinterpret_cast<intptr_t>({{v8_class}}::IndexedPropertyDeleterCallback),
{% endif %}
{% endif %}
{% if interface.has_security_check_function %}
reinterpret_cast<intptr_t>({{v8_class}}::SecurityCheck),
{%- endif %}
{% endif %}{# not is_array_buffer_or_view #}
{% endif %}
{% endfor %}{# interfaces #}
reinterpret_cast<intptr_t>(V8ObjectConstructor::IsValidConstructorMode),
#endif // USE_V8_CONTEXT_SNAPSHOT
0 // terminate with a null
};
return reference_table;
return kReferenceTable;
}
} // namespace blink
......
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