Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(348)

Unified Diff: sky/engine/bindings2/scripts/v8_interface.py

Issue 914413004: Add a new bindings2/scripts directory for Dart bindings (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Remove idlrenderer.py it's not used Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/engine/bindings2/scripts/v8_globals.py ('k') | sky/engine/bindings2/scripts/v8_methods.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/engine/bindings2/scripts/v8_interface.py
diff --git a/sky/engine/bindings/scripts/v8_interface.py b/sky/engine/bindings2/scripts/v8_interface.py
similarity index 74%
copy from sky/engine/bindings/scripts/v8_interface.py
copy to sky/engine/bindings2/scripts/v8_interface.py
index 60c2ad621ab4625c283af1ae2eb0fd6aa872c98f..45787cfe9539ce1170b854fbbbf7bc3a4aa92a2c 100644
--- a/sky/engine/bindings/scripts/v8_interface.py
+++ b/sky/engine/bindings2/scripts/v8_interface.py
@@ -46,26 +46,19 @@ import v8_methods
import v8_types
from v8_types import cpp_template_type
import v8_utilities
-from v8_utilities import (capitalize, conditional_string, cpp_name,
- has_extended_attribute_value, runtime_enabled_function_name,
+from v8_utilities import (capitalize, cpp_name,
+ has_extended_attribute_value,
extended_attribute_value_as_list)
INTERFACE_H_INCLUDES = frozenset([
- 'bindings/core/v8/ScriptWrappable.h',
- 'bindings/core/v8/V8Binding.h',
- 'bindings/core/v8/V8DOMWrapper.h',
- 'bindings/core/v8/WrapperTypeInfo.h',
'platform/heap/Handle.h',
])
+
INTERFACE_CPP_INCLUDES = frozenset([
- 'bindings/core/v8/ExceptionState.h',
- 'bindings/core/v8/V8DOMConfiguration.h',
- 'bindings/core/v8/V8HiddenValue.h',
- 'bindings/core/v8/V8ObjectConstructor.h',
+ 'sky/engine/bindings2/exception_state.h',
'core/dom/Document.h',
- 'platform/RuntimeEnabledFeatures.h',
- 'platform/TraceEvent.h',
+ 'base/trace_event/trace_event.h',
'wtf/GetPtr.h',
'wtf/RefPtr.h',
])
@@ -81,20 +74,9 @@ def interface_context(interface):
header_includes.update(v8_types.includes_for_interface(parent_interface))
extended_attributes = interface.extended_attributes
- is_document = inherits_interface(interface.name, 'Document')
- if is_document:
- includes.update(['bindings/core/v8/ScriptController.h',
- 'bindings/core/v8/WindowProxy.h',
- 'core/frame/LocalFrame.h'])
-
# [ActiveDOMObject]
is_active_dom_object = 'ActiveDOMObject' in extended_attributes
- # [CheckSecurity]
- is_check_security = 'CheckSecurity' in extended_attributes
- if is_check_security:
- includes.add('bindings/core/v8/BindingSecurity.h')
-
# [DependentLifetime]
is_dependent_lifetime = 'DependentLifetime' in extended_attributes
@@ -109,14 +91,10 @@ def interface_context(interface):
iterator_method = v8_methods.method_context(interface,
iterator_operation)
- # [MeasureAs]
- is_measure_as = 'MeasureAs' in extended_attributes
-
# [SetWrapperReferenceFrom]
reachable_node_function = extended_attributes.get('SetWrapperReferenceFrom')
if reachable_node_function:
- includes.update(['bindings/core/v8/V8GCController.h',
- 'core/dom/Element.h'])
+ includes.update(['core/dom/Element.h'])
# [SetWrapperReferenceTo]
set_wrapper_reference_to_list = [{
@@ -127,7 +105,6 @@ def interface_context(interface):
# Raw pointers faster though, and NodeFilter hacky anyway.
'cpp_type': argument.idl_type.implemented_as + '*',
'idl_type': argument.idl_type,
- 'v8_type': v8_types.v8_type(argument.idl_type.name),
} for argument in extended_attributes.get('SetWrapperReferenceTo', [])]
for set_wrapper_reference_to in set_wrapper_reference_to_list:
set_wrapper_reference_to['idl_type'].add_includes_for_type()
@@ -152,25 +129,14 @@ def interface_context(interface):
wrapper_class_id = ('NodeClassId' if inherits_interface(interface.name, 'Node') else 'ObjectClassId')
context = {
- 'conditional_string': conditional_string(interface), # [Conditional]
'cpp_class': cpp_name(interface),
- # FIXME: Remove 'EventTarget' special handling, http://crbug.com/383699
- 'has_access_check_callbacks': (is_check_security and
- interface.name != 'Window' and
- interface.name != 'EventTarget'),
- 'has_custom_legacy_call_as_function': has_extended_attribute_value(interface, 'Custom', 'LegacyCallAsFunction'), # [Custom=LegacyCallAsFunction]
- 'has_custom_to_v8': has_extended_attribute_value(interface, 'Custom', 'ToV8'), # [Custom=ToV8]
'has_custom_wrap': has_extended_attribute_value(interface, 'Custom', 'Wrap'), # [Custom=Wrap]
'has_visit_dom_wrapper': has_visit_dom_wrapper,
'header_includes': header_includes,
'interface_name': interface.name,
'is_active_dom_object': is_active_dom_object,
- 'is_check_security': is_check_security,
'is_dependent_lifetime': is_dependent_lifetime,
- 'is_document': is_document,
- 'is_event_target': inherits_interface(interface.name, 'EventTarget'),
'is_exception': interface.is_exception,
- 'is_node': inherits_interface(interface.name, 'Node'),
'is_script_wrappable': is_script_wrappable,
'iterator_method': iterator_method,
'lifetime': 'Dependent'
@@ -178,16 +144,10 @@ def interface_context(interface):
is_active_dom_object or
is_dependent_lifetime)
else 'Independent',
- 'measure_as': v8_utilities.measure_as(interface), # [MeasureAs]
'parent_interface': parent_interface,
- 'pass_cpp_type': cpp_template_type(
- 'PassRefPtr',
- cpp_name(interface)),
'reachable_node_function': reachable_node_function,
- 'runtime_enabled_function': runtime_enabled_function_name(interface), # [RuntimeEnabled]
'set_wrapper_reference_to_list': set_wrapper_reference_to_list,
'special_wrap_for': special_wrap_for,
- 'v8_class': v8_utilities.v8_class_name(interface),
'wrapper_class_id': wrapper_class_id,
}
@@ -211,17 +171,12 @@ def interface_context(interface):
has_event_constructor = 'EventConstructor' in extended_attributes
any_type_attributes = [attribute for attribute in interface.attributes
if attribute.idl_type.name == 'Any']
- if has_event_constructor:
- includes.add('bindings/core/v8/Dictionary.h')
- if any_type_attributes:
- includes.add('bindings/core/v8/SerializedScriptValue.h')
# [NamedConstructor]
named_constructor = named_constructor_context(interface)
if (constructors or custom_constructors or has_event_constructor or
named_constructor):
- includes.add('bindings/core/v8/V8ObjectConstructor.h')
includes.add('core/frame/LocalDOMWindow.h')
context.update({
@@ -240,10 +195,7 @@ def interface_context(interface):
# Constants
context.update({
'constants': constants,
- 'do_not_check_constants': 'DoNotCheckConstants' in extended_attributes,
- 'has_constant_configuration': any(
- not constant['runtime_enabled_function']
- for constant in constants),
+ 'has_constant_configuration': True,
})
# Attributes
@@ -251,13 +203,6 @@ def interface_context(interface):
for attribute in interface.attributes]
context.update({
'attributes': attributes,
- 'has_accessors': any(attribute['is_expose_js_accessors'] and attribute['should_be_exposed_to_script'] for attribute in attributes),
- 'has_attribute_configuration': any(
- not (attribute['is_expose_js_accessors'] or
- attribute['is_static'] or
- attribute['runtime_enabled_function'])
- and attribute['should_be_exposed_to_script']
- for attribute in attributes),
'has_conditional_attributes': any(attribute['exposed_test'] for attribute in attributes),
'has_constructor_attributes': any(attribute['constructor_type'] for attribute in attributes),
'has_replaceable_attributes': any(attribute['is_replaceable'] for attribute in attributes),
@@ -294,21 +239,18 @@ def interface_context(interface):
if 'overloads' in method:
overloads = method['overloads']
conditionally_exposed_function = overloads['exposed_test_all']
- runtime_enabled_function = overloads['runtime_enabled_function_all']
has_custom_registration = overloads['has_custom_registration_all']
else:
conditionally_exposed_function = method['exposed_test']
- runtime_enabled_function = method['runtime_enabled_function']
has_custom_registration = method['has_custom_registration']
if conditionally_exposed_function:
conditionally_enabled_methods.append(method)
continue
- if runtime_enabled_function or has_custom_registration:
+ if has_custom_registration:
custom_registration_methods.append(method)
continue
- if method['should_be_exposed_to_script']:
- method_configuration_methods.append(method)
+ method_configuration_methods.append(method)
for method in methods:
# The value of the Function object’s “length” property is a Number
@@ -328,11 +270,6 @@ def interface_context(interface):
context.update({
'conditionally_enabled_methods': conditionally_enabled_methods,
'custom_registration_methods': custom_registration_methods,
- 'has_origin_safe_method_setter': any(
- method['is_check_security_for_frame'] and not method['is_read_only']
- for method in methods),
- 'has_private_script': any(attribute['is_implemented_in_private_script'] for attribute in attributes) or
- any(method['is_implemented_in_private_script'] for method in methods),
'method_configuration_methods': method_configuration_methods,
'methods': methods,
})
@@ -350,7 +287,7 @@ def interface_context(interface):
return context
-# [DeprecateAs], [Reflect], [RuntimeEnabled]
+# [DeprecateAs], [Reflect]
def constant_context(constant):
# (Blink-only) string literals are unquoted in tokenizer, must be re-quoted
# in C++.
@@ -366,7 +303,6 @@ def constant_context(constant):
'name': constant.name,
# FIXME: use 'reflected_name' as correct 'name'
'reflected_name': extended_attributes.get('Reflect', constant.name),
- 'runtime_enabled_function': runtime_enabled_function_name(constant),
'value': value,
}
@@ -437,10 +373,6 @@ def overloads_context(overloads):
# controlled by the same runtime enabled feature, in which case there would
# be no function object at all if it is not enabled.
shortest_overloads = effective_overloads_by_length[0][1]
- if (all(method.get('runtime_enabled_function')
- for method, _, _ in shortest_overloads) and
- not common_value(overloads, 'runtime_enabled_function')):
- raise ValueError('Function.length of %s depends on runtime enabled features' % name)
# Check and fail if overloads disagree on any of the extended attributes
# that affect how the method should be registered.
@@ -463,16 +395,12 @@ def overloads_context(overloads):
% (name))
return {
- 'deprecate_all_as': common_value(overloads, 'deprecate_as'), # [DeprecateAs]
'exposed_test_all': common_value(overloads, 'exposed_test'), # [Exposed]
'has_custom_registration_all': common_value(overloads, 'has_custom_registration'),
- 'length_tests_methods': length_tests_methods(effective_overloads_by_length),
# 1. Let maxarg be the length of the longest type list of the
# entries in S.
'maxarg': lengths[-1],
- 'measure_all_as': common_value(overloads, 'measure_as'), # [MeasureAs]
'minarg': lengths[0],
- 'runtime_enabled_function_all': common_value(overloads, 'runtime_enabled_function'), # [RuntimeEnabled]
'valid_arities': lengths
# Only need to report valid arities if there is a gap in the
# sequence of possible lengths, otherwise invalid length means
@@ -651,177 +579,6 @@ def distinguishing_argument_index(entries):
return index
-def length_tests_methods(effective_overloads_by_length):
- """Returns sorted list of resolution tests and associated methods, by length.
-
- This builds the main data structure for the overload resolution loop.
- For a given argument length, bindings test argument at distinguishing
- argument index, in order given by spec: if it is compatible with
- (optionality or) type required by an overloaded method, resolve to that
- method.
-
- Returns:
- [(length, [(test, method)])]
- """
- return [(length, list(resolution_tests_methods(effective_overloads)))
- for length, effective_overloads in effective_overloads_by_length]
-
-
-def resolution_tests_methods(effective_overloads):
- """Yields resolution test and associated method, in resolution order, for effective overloads of a given length.
-
- This is the heart of the resolution algorithm.
- http://heycam.github.io/webidl/#dfn-overload-resolution-algorithm
-
- Note that a given method can be listed multiple times, with different tests!
- This is to handle implicit type conversion.
-
- Returns:
- [(test, method)]
- """
- methods = [effective_overload[0]
- for effective_overload in effective_overloads]
- if len(methods) == 1:
- # If only one method with a given length, no test needed
- yield 'true', methods[0]
- return
-
- # 6. If there is more than one entry in S, then set d to be the
- # distinguishing argument index for the entries of S.
- index = distinguishing_argument_index(effective_overloads)
- # (7-9 are for handling |undefined| values for optional arguments before
- # the distinguishing argument (as “missing”), so you can specify only some
- # optional arguments. We don’t support this, so we skip these steps.)
- # 10. If i = d, then:
- # (d is the distinguishing argument index)
- # 1. Let V be argi.
- # Note: This is the argument that will be used to resolve which
- # overload is selected.
- cpp_value = 'info[%s]' % index
-
- # Extract argument and IDL type to simplify accessing these in each loop.
- arguments = [method['arguments'][index] for method in methods]
- arguments_methods = zip(arguments, methods)
- idl_types = [argument['idl_type_object'] for argument in arguments]
- idl_types_methods = zip(idl_types, methods)
-
- # We can’t do a single loop through all methods or simply sort them, because
- # a method may be listed in multiple steps of the resolution algorithm, and
- # which test to apply differs depending on the step.
- #
- # Instead, we need to go through all methods at each step, either finding
- # first match (if only one test is allowed) or filtering to matches (if
- # multiple tests are allowed), and generating an appropriate tests.
-
- # 2. If V is undefined, and there is an entry in S whose list of
- # optionality values has “optional” at index i, then remove from S all
- # other entries.
- try:
- method = next(method for argument, method in arguments_methods
- if argument['is_optional'])
- test = '%s->IsUndefined()' % cpp_value
- yield test, method
- except StopIteration:
- pass
-
- # 3. Otherwise: if V is null or undefined, and there is an entry in S that
- # has one of the following types at position i of its type list,
- # • a nullable type
- try:
- method = next(method for idl_type, method in idl_types_methods
- if idl_type.is_nullable)
- test = 'isUndefinedOrNull(%s)' % cpp_value
- yield test, method
- except StopIteration:
- pass
-
- # 4. Otherwise: if V is a platform object – but not a platform array
- # object – and there is an entry in S that has one of the following
- # types at position i of its type list,
- # • an interface type that V implements
- # (Unlike most of these tests, this can return multiple methods, since we
- # test if it implements an interface. Thus we need a for loop, not a next.)
- # (We distinguish wrapper types from built-in interface types.)
- for idl_type, method in ((idl_type, method)
- for idl_type, method in idl_types_methods
- if idl_type.is_wrapper_type):
- test = 'V8{idl_type}::hasInstance({cpp_value}, info.GetIsolate())'.format(idl_type=idl_type.base_type, cpp_value=cpp_value)
- yield test, method
-
- # 8. Otherwise: if V is any kind of object except for a native Date object,
- # a native RegExp object, and there is an entry in S that has one of the
- # following types at position i of its type list,
- # • an array type
- # • a sequence type
- # ...
- # • a dictionary
- try:
- idl_type, method = next((idl_type, method)
- for idl_type, method in idl_types_methods
- if (idl_type.native_array_element_type or
- idl_type.is_dictionary or
- idl_type.name == 'Dictionary'))
- if idl_type.native_array_element_type:
- # (We test for Array instead of generic Object to type-check.)
- # FIXME: test for Object during resolution, then have type check for
- # Array in overloaded method: http://crbug.com/262383
- test = '%s->IsArray()' % cpp_value
- else:
- # FIXME: should be '{1}->IsObject() && !{1}->IsDate() && !{1}->IsRegExp()'.format(cpp_value)
- # FIXME: the IsDate and IsRegExp checks can be skipped if we've
- # already generated tests for them.
- test = '%s->IsObject()' % cpp_value
- yield test, method
- except StopIteration:
- pass
-
- # (Check for exact type matches before performing automatic type conversion;
- # only needed if distinguishing between primitive types.)
- if len([idl_type.is_primitive_type for idl_type in idl_types]) > 1:
- # (Only needed if match in step 11, otherwise redundant.)
- if any(idl_type.is_string_type or idl_type.is_enum
- for idl_type in idl_types):
- # 10. Otherwise: if V is a Number value, and there is an entry in S
- # that has one of the following types at position i of its type
- # list,
- # • a numeric type
- try:
- method = next(method for idl_type, method in idl_types_methods
- if idl_type.is_numeric_type)
- test = '%s->IsNumber()' % cpp_value
- yield test, method
- except StopIteration:
- pass
-
- # (Perform automatic type conversion, in order. If any of these match,
- # that’s the end, and no other tests are needed.) To keep this code simple,
- # we rely on the C++ compiler's dead code elimination to deal with the
- # redundancy if both cases below trigger.
-
- # 11. Otherwise: if there is an entry in S that has one of the following
- # types at position i of its type list,
- # • DOMString
- # • ByteString
- # • ScalarValueString [a DOMString typedef, per definition.]
- # • an enumeration type
- try:
- method = next(method for idl_type, method in idl_types_methods
- if idl_type.is_string_type or idl_type.is_enum)
- yield 'true', method
- except StopIteration:
- pass
-
- # 12. Otherwise: if there is an entry in S that has one of the following
- # types at position i of its type list,
- # • a numeric type
- try:
- method = next(method for idl_type, method in idl_types_methods
- if idl_type.is_numeric_type)
- yield 'true', method
- except StopIteration:
- pass
-
-
################################################################################
# Utility functions
################################################################################
@@ -996,7 +753,6 @@ def property_getter(getter, cpp_arguments):
'is_raises_exception': is_raises_exception,
'name': cpp_name(getter),
'union_arguments': union_arguments,
- 'v8_set_return_value': idl_type.v8_set_return_value('result', extended_attributes=extended_attributes, script_wrappable='impl', release=idl_type.release),
}
@@ -1014,8 +770,6 @@ def property_setter(setter):
idl_type.is_integer_type,
'is_raises_exception': is_raises_exception,
'name': cpp_name(setter),
- 'v8_value_to_local_cpp_value': idl_type.v8_value_to_local_cpp_value(
- extended_attributes, 'v8Value', 'propertyValue'),
}
« no previous file with comments | « sky/engine/bindings2/scripts/v8_globals.py ('k') | sky/engine/bindings2/scripts/v8_methods.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698