Index: bindings/scripts/v8_interface.py |
diff --git a/bindings/scripts/v8_interface.py b/bindings/scripts/v8_interface.py |
index 2980628681c62b4025f08fc8b5cb5640b7d32dea..bf63e615ecc04c01e1d8bd03ccb94309f6f42a58 100644 |
--- a/bindings/scripts/v8_interface.py |
+++ b/bindings/scripts/v8_interface.py |
@@ -46,7 +46,9 @@ import v8_methods |
import v8_types |
from v8_types import cpp_ptr_type, cpp_template_type |
import v8_utilities |
-from v8_utilities import capitalize, conditional_string, cpp_name, gc_type, has_extended_attribute_value, runtime_enabled_function_name |
+from v8_utilities import (capitalize, conditional_string, cpp_name, gc_type, |
+ has_extended_attribute_value, runtime_enabled_function_name, |
+ extended_attribute_value_as_list) |
INTERFACE_H_INCLUDES = frozenset([ |
@@ -101,6 +103,17 @@ def interface_context(interface): |
# [DependentLifetime] |
is_dependent_lifetime = 'DependentLifetime' in extended_attributes |
+ # [Iterable] |
+ iterator_method = None |
+ if 'Iterable' in extended_attributes: |
+ iterator_operation = IdlOperation(interface.idl_name) |
+ iterator_operation.name = 'iterator' |
+ iterator_operation.idl_type = IdlType('Iterator') |
+ iterator_operation.extended_attributes['RaisesException'] = None |
+ iterator_operation.extended_attributes['CallWith'] = 'ScriptState' |
+ iterator_method = v8_methods.method_context(interface, |
+ iterator_operation) |
+ |
# [MeasureAs] |
is_measure_as = 'MeasureAs' in extended_attributes |
if is_measure_as: |
@@ -126,9 +139,12 @@ def interface_context(interface): |
for set_wrapper_reference_to in set_wrapper_reference_to_list: |
set_wrapper_reference_to['idl_type'].add_includes_for_type() |
+ # [NotScriptWrappable] |
+ is_script_wrappable = 'NotScriptWrappable' not in extended_attributes |
+ |
# [SpecialWrapFor] |
if 'SpecialWrapFor' in extended_attributes: |
- special_wrap_for = extended_attributes['SpecialWrapFor'].split('|') |
+ special_wrap_for = extended_attribute_value_as_list(interface, 'SpecialWrapFor') |
else: |
special_wrap_for = [] |
for special_wrap_interface in special_wrap_for: |
@@ -142,10 +158,16 @@ def interface_context(interface): |
this_gc_type = gc_type(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), |
'gc_type': this_gc_type, |
+ # 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] |
@@ -160,6 +182,13 @@ def interface_context(interface): |
'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' |
+ if (has_visit_dom_wrapper or |
+ 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( |
@@ -170,11 +199,7 @@ def interface_context(interface): |
'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_configuration': 'WrapperConfiguration::Dependent' |
- if (has_visit_dom_wrapper or |
- is_active_dom_object or |
- is_dependent_lifetime) |
- else 'WrapperConfiguration::Independent', |
+ 'wrapper_class_id': wrapper_class_id, |
} |
# Constructors |
@@ -221,11 +246,31 @@ def interface_context(interface): |
'named_constructor': named_constructor, |
}) |
+ constants = [constant_context(constant) for constant in interface.constants] |
+ |
+ special_getter_constants = [] |
+ runtime_enabled_constants = [] |
+ constant_configuration_constants = [] |
+ |
+ for constant in constants: |
+ if constant['measure_as'] or constant['deprecate_as']: |
+ special_getter_constants.append(constant) |
+ continue |
+ if constant['runtime_enabled_function']: |
+ runtime_enabled_constants.append(constant) |
+ continue |
+ constant_configuration_constants.append(constant) |
+ |
# Constants |
context.update({ |
- 'constants': [constant_context(constant) |
- for constant in interface.constants], |
+ 'constant_configuration_constants': constant_configuration_constants, |
+ 'constants': constants, |
'do_not_check_constants': 'DoNotCheckConstants' in extended_attributes, |
+ 'has_constant_configuration': any( |
+ not constant['runtime_enabled_function'] |
+ for constant in constants), |
+ 'runtime_enabled_constants': runtime_enabled_constants, |
+ 'special_getter_constants': special_getter_constants, |
}) |
# Attributes |
@@ -339,22 +384,17 @@ def interface_context(interface): |
# [DeprecateAs], [Reflect], [RuntimeEnabled] |
def constant_context(constant): |
- # (Blink-only) string literals are unquoted in tokenizer, must be re-quoted |
- # in C++. |
- if constant.idl_type.name == 'String': |
- value = '"%s"' % constant.value |
- else: |
- value = constant.value |
- |
extended_attributes = constant.extended_attributes |
return { |
'cpp_class': extended_attributes.get('PartialInterfaceImplementedAs'), |
+ 'deprecate_as': v8_utilities.deprecate_as(constant), # [DeprecateAs] |
'idl_type': constant.idl_type.name, |
+ 'measure_as': v8_utilities.measure_as(constant), # [MeasureAs] |
'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, |
+ 'value': constant.value, |
} |
@@ -442,6 +482,13 @@ def overloads_context(overloads): |
raise ValueError('Overloads of %s have conflicting extended attribute %s' |
% (name, extended_attribute)) |
+ # Check and fail if overloads disagree about whether the return type |
+ # is a Promise or not. |
+ promise_overload_count = sum(1 for method in overloads if method.get('idl_type') == 'Promise') |
+ if promise_overload_count not in (0, len(overloads)): |
+ raise ValueError('Overloads of %s have conflicting Promise/non-Promise types' |
+ % (name)) |
+ |
return { |
'deprecate_all_as': common_value(overloads, 'deprecate_as'), # [DeprecateAs] |
'exposed_test_all': common_value(overloads, 'exposed_test'), # [Exposed] |
@@ -736,26 +783,26 @@ def resolution_tests_methods(effective_overloads): |
# • a sequence type |
# ... |
# • a dictionary |
- try: |
- # FIXME: IDL dictionary not implemented, so use Blink Dictionary |
- # http://crbug.com/321462 |
- 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.name == 'Dictionary')) |
+ # |
+ # FIXME: |
+ # We don't strictly follow the algorithm here. The algorithm says "remove |
+ # all other entries" if there is "one entry" matching, but we yield all |
+ # entries to support following constructors: |
+ # [constructor(sequence<DOMString> arg), constructor(Dictionary arg)] |
+ # interface I { ... } |
+ # (Need to check array types before objects because an array is an object) |
+ for idl_type, method in idl_types_methods: |
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: |
+ yield '%s->IsArray()' % cpp_value, method |
+ for idl_type, method in idl_types_methods: |
+ if idl_type.is_dictionary or idl_type.name == 'Dictionary': |
# 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 |
+ yield '%s->IsObject()' % cpp_value, method |
# (Check for exact type matches before performing automatic type conversion; |
# only needed if distinguishing between primitive types.) |
@@ -858,9 +905,6 @@ def sort_and_groupby(l, key=None): |
# [Constructor] |
def constructor_context(interface, constructor): |
- arguments_need_try_catch = any(v8_methods.argument_needs_try_catch(argument, return_promise=False) |
- for argument in constructor.arguments) |
- |
# [RaisesException=Constructor] |
is_constructor_raises_exception = \ |
interface.extended_attributes.get('RaisesException') == 'Constructor' |
@@ -868,7 +912,6 @@ def constructor_context(interface, constructor): |
return { |
'arguments': [v8_methods.argument_context(interface, constructor, argument, index) |
for index, argument in enumerate(constructor.arguments)], |
- 'arguments_need_try_catch': arguments_need_try_catch, |
'cpp_type': cpp_template_type( |
cpp_ptr_type('RefPtr', 'RawPtr', gc_type(interface)), |
cpp_name(interface)), |
@@ -878,7 +921,7 @@ def constructor_context(interface, constructor): |
is_constructor_raises_exception or |
any(argument for argument in constructor.arguments |
if argument.idl_type.name == 'SerializedScriptValue' or |
- argument.idl_type.may_raise_exception_on_conversion), |
+ argument.idl_type.v8_conversion_needs_exception_state), |
'is_call_with_document': |
# [ConstructorCallWith=Document] |
has_extended_attribute_value(interface, |
@@ -992,8 +1035,8 @@ def property_setter(setter): |
idl_type.is_wrapper_type, |
'idl_type': idl_type.base_type, |
'is_custom': 'Custom' in extended_attributes, |
- 'has_exception_state': is_raises_exception or |
- idl_type.is_integer_type, |
+ 'has_exception_state': (is_raises_exception or |
+ idl_type.v8_conversion_needs_exception_state), |
'is_raises_exception': is_raises_exception, |
'name': cpp_name(setter), |
'v8_value_to_local_cpp_value': idl_type.v8_value_to_local_cpp_value( |