def attribute_context(interface, attribute): # Call v8's implementation. context = v8_attributes.attribute_context(interface, attribute) extended_attributes = attribute.extended_attributes # Augment's Dart's information to context. idl_type = attribute.idl_type base_idl_type = idl_type.base_type # TODO(terry): Work around for DOMString[] base should be IDLTypeArray if base_idl_type == None: # Returns Array or Sequence. base_idl_type = idl_type.inner_name # [Custom] has_custom_getter = ('Custom' in extended_attributes and extended_attributes['Custom'] in [None, 'Getter']) has_custom_setter = (not attribute.is_read_only and (('Custom' in extended_attributes and extended_attributes['Custom'] in [None, 'Setter']))) is_call_with_script_state = DartUtilities.has_extended_attribute_value(attribute, 'CallWith', 'ScriptState') is_auto_scope = not 'DartNoAutoScope' in extended_attributes context.update({ 'has_custom_getter': has_custom_getter, 'has_custom_setter': has_custom_setter, 'is_auto_scope': is_auto_scope, # Used internally (outside of templates). 'is_call_with_script_state': is_call_with_script_state, 'auto_scope': DartUtilities.bool_to_cpp(is_auto_scope), 'dart_type': dart_types.idl_type_to_dart_type(idl_type), }) if v8_attributes.is_constructor_attribute(attribute): v8_attributes.constructor_getter_context(interface, attribute, context) return context if not v8_attributes.has_custom_getter(attribute): getter_context(interface, attribute, context) if (not attribute.is_read_only): # FIXME: We did not previously support the PutForwards attribute, so I am # disabling it here for now to get things compiling. # We may wish to revisit this. # if (not has_custom_setter(attribute) and # (not attribute.is_read_only or 'PutForwards' in extended_attributes)): setter_context(interface, attribute, context) native_entry_getter = \ DartUtilities.generate_native_entry( interface.name, attribute.name, 'Getter', attribute.is_static, 0) native_entry_setter = \ DartUtilities.generate_native_entry( interface.name, attribute.name, 'Setter', attribute.is_static, 1) context.update({ 'native_entry_getter': native_entry_getter, 'native_entry_setter': native_entry_setter, }) return context
def interface_context(interface): includes.clear() includes.update(INTERFACE_CPP_INCLUDES) header_includes = set(INTERFACE_H_INCLUDES) parent_interface = interface.parent if parent_interface: header_includes.update(v8_types.includes_for_interface(parent_interface)) extended_attributes = interface.extended_attributes # [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 # [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: includes.add('core/frame/UseCounter.h') # [SetWrapperReferenceFrom] reachable_node_function = extended_attributes.get('SetWrapperReferenceFrom') if reachable_node_function: includes.update(['bindings/core/v8/V8GCController.h', 'core/dom/Element.h']) # [SetWrapperReferenceTo] set_wrapper_reference_to_list = [{ 'name': argument.name, # FIXME: properly should be: # 'cpp_type': argument.idl_type.cpp_type_args(raw_type=True), # (if type is non-wrapper type like NodeFilter, normally RefPtr) # 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() # [NotScriptWrappable] is_script_wrappable = 'NotScriptWrappable' not in extended_attributes # [Custom=Wrap], [SetWrapperReferenceFrom] has_visit_dom_wrapper = ( has_extended_attribute_value(interface, 'Custom', 'VisitDOMWrapper') or reachable_node_function or set_wrapper_reference_to_list) 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] '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_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( cpp_ptr_type('PassRefPtr', 'RawPtr', this_gc_type), 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, 'v8_class': v8_utilities.v8_class_name(interface), 'wrapper_class_id': wrapper_class_id, } # Constructors constructors = [constructor_context(interface, constructor) for constructor in interface.constructors # FIXME: shouldn't put named constructors with constructors # (currently needed for Perl compatibility) # Handle named constructors separately if constructor.name == 'Constructor'] if len(constructors) > 1: context['constructor_overloads'] = overloads_context(constructors) # [CustomConstructor] custom_constructors = [{ # Only needed for computing interface length 'number_of_required_arguments': number_of_required_arguments(constructor), } for constructor in interface.custom_constructors] # [EventConstructor] 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({ 'any_type_attributes': any_type_attributes, 'constructors': constructors, 'has_custom_constructor': bool(custom_constructors), 'has_event_constructor': has_event_constructor, 'interface_length': interface_length(interface, constructors + custom_constructors), 'is_constructor_raises_exception': extended_attributes.get('RaisesException') == 'Constructor', # [RaisesException=Constructor] '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({ '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 attributes = [v8_attributes.attribute_context(interface, attribute) 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'] or attribute['per_context_enabled_function']) and attribute['should_be_exposed_to_script'] for attribute in attributes), 'has_conditional_attributes': any(attribute['per_context_enabled_function'] or 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), }) # Methods methods = [v8_methods.method_context(interface, method) for method in interface.operations if method.name] # Skip anonymous special operations (methods) compute_method_overloads_context(methods) # Stringifier if interface.stringifier: stringifier = interface.stringifier method = IdlOperation(interface.idl_name) method.name = 'toString' method.idl_type = IdlType('DOMString') method.extended_attributes.update(stringifier.extended_attributes) if stringifier.attribute: method.extended_attributes['ImplementedAs'] = stringifier.attribute.name elif stringifier.operation: method.extended_attributes['ImplementedAs'] = stringifier.operation.name methods.append(v8_methods.method_context(interface, method)) conditionally_enabled_methods = [] custom_registration_methods = [] method_configuration_methods = [] for method in methods: # Skip all but one method in each set of overloaded methods. if 'overload_index' in method and 'overloads' not in method: continue if 'overloads' in method: overloads = method['overloads'] per_context_enabled_function = overloads['per_context_enabled_function_all'] conditionally_exposed_function = overloads['exposed_test_all'] runtime_enabled_function = overloads['runtime_enabled_function_all'] has_custom_registration = overloads['has_custom_registration_all'] else: per_context_enabled_function = method['per_context_enabled_function'] conditionally_exposed_function = method['exposed_test'] runtime_enabled_function = method['runtime_enabled_function'] has_custom_registration = method['has_custom_registration'] if per_context_enabled_function or conditionally_exposed_function: conditionally_enabled_methods.append(method) continue if runtime_enabled_function or has_custom_registration: custom_registration_methods.append(method) continue if method['should_be_exposed_to_script']: method_configuration_methods.append(method) for method in methods: # The value of the Function object’s “length” property is a Number # determined as follows: # 1. Let S be the effective overload set for regular operations (if the # operation is a regular operation) or for static operations (if the # operation is a static operation) with identifier id on interface I and # with argument count 0. # 2. Return the length of the shortest argument list of the entries in S. # FIXME: This calculation doesn't take into account whether runtime # enabled overloads are actually enabled, so length may be incorrect. # E.g., [RuntimeEnabled=Foo] void f(); void f(long x); # should have length 1 if Foo is not enabled, but length 0 if it is. method['length'] = (method['overloads']['minarg'] if 'overloads' in method else method['number_of_required_arguments']) 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, }) context.update({ 'indexed_property_getter': indexed_property_getter(interface), 'indexed_property_setter': indexed_property_setter(interface), 'indexed_property_deleter': indexed_property_deleter(interface), 'is_override_builtins': 'OverrideBuiltins' in extended_attributes, 'named_property_getter': named_property_getter(interface), 'named_property_setter': named_property_setter(interface), 'named_property_deleter': named_property_deleter(interface), }) return context
def interface_context(interface): includes.clear() includes.update(INTERFACE_CPP_INCLUDES) header_includes = set(INTERFACE_H_INCLUDES) parent_interface = interface.parent if parent_interface: header_includes.update(v8_types.includes_for_interface(parent_interface)) extended_attributes = interface.extended_attributes # [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) # [SetWrapperReferenceFrom] reachable_node_function = extended_attributes.get('SetWrapperReferenceFrom') if reachable_node_function: includes.update(['core/dom/Element.h']) # [SetWrapperReferenceTo] set_wrapper_reference_to_list = [{ 'name': argument.name, # FIXME: properly should be: # 'cpp_type': argument.idl_type.cpp_type_args(raw_type=True), # (if type is non-wrapper type like NodeFilter, normally RefPtr) # Raw pointers faster though, and NodeFilter hacky anyway. 'cpp_type': argument.idl_type.implemented_as + '*', 'idl_type': argument.idl_type, } 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() # [NotScriptWrappable] is_script_wrappable = 'NotScriptWrappable' not in extended_attributes # [SpecialWrapFor] if 'SpecialWrapFor' in extended_attributes: special_wrap_for = extended_attribute_value_as_list(interface, 'SpecialWrapFor') else: special_wrap_for = [] for special_wrap_interface in special_wrap_for: v8_types.add_includes_for_interface(special_wrap_interface) # [Custom=Wrap], [SetWrapperReferenceFrom] has_visit_dom_wrapper = ( has_extended_attribute_value(interface, 'Custom', 'VisitDOMWrapper') or reachable_node_function or set_wrapper_reference_to_list) wrapper_class_id = ('NodeClassId' if inherits_interface(interface.name, 'Node') else 'ObjectClassId') context = { 'cpp_class': cpp_name(interface), '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_dependent_lifetime': is_dependent_lifetime, 'is_exception': interface.is_exception, 'is_script_wrappable': is_script_wrappable, 'iterator_method': iterator_method, 'lifetime': 'Dependent' if (has_visit_dom_wrapper or is_dependent_lifetime) else 'Independent', 'parent_interface': parent_interface, 'reachable_node_function': reachable_node_function, 'set_wrapper_reference_to_list': set_wrapper_reference_to_list, 'special_wrap_for': special_wrap_for, 'wrapper_class_id': wrapper_class_id, } # Constructors constructors = [constructor_context(interface, constructor) for constructor in interface.constructors # FIXME: shouldn't put named constructors with constructors # (currently needed for Perl compatibility) # Handle named constructors separately if constructor.name == 'Constructor'] if len(constructors) > 1: context['constructor_overloads'] = overloads_context(constructors) # [CustomConstructor] custom_constructors = [{ # Only needed for computing interface length 'number_of_required_arguments': number_of_required_arguments(constructor), } for constructor in interface.custom_constructors] # [EventConstructor] has_event_constructor = 'EventConstructor' in extended_attributes any_type_attributes = [attribute for attribute in interface.attributes if attribute.idl_type.name == 'Any'] # [NamedConstructor] named_constructor = named_constructor_context(interface) if (constructors or custom_constructors or has_event_constructor or named_constructor): includes.add('core/frame/LocalDOMWindow.h') context.update({ 'any_type_attributes': any_type_attributes, 'constructors': constructors, 'has_custom_constructor': bool(custom_constructors), 'has_event_constructor': has_event_constructor, 'interface_length': interface_length(interface, constructors + custom_constructors), 'is_constructor_raises_exception': extended_attributes.get('RaisesException') == 'Constructor', # [RaisesException=Constructor] 'named_constructor': named_constructor, }) constants = [constant_context(constant) for constant in interface.constants] # Constants context.update({ 'constants': constants, 'has_constant_configuration': True, }) # Attributes attributes = [v8_attributes.attribute_context(interface, attribute) for attribute in interface.attributes] context.update({ 'attributes': 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), }) # Methods methods = [v8_methods.method_context(interface, method) for method in interface.operations if method.name] # Skip anonymous special operations (methods) compute_method_overloads_context(methods) # Stringifier if interface.stringifier: stringifier = interface.stringifier method = IdlOperation(interface.idl_name) method.name = 'toString' method.idl_type = IdlType('DOMString') method.extended_attributes.update(stringifier.extended_attributes) if stringifier.attribute: method.extended_attributes['ImplementedAs'] = stringifier.attribute.name elif stringifier.operation: method.extended_attributes['ImplementedAs'] = stringifier.operation.name methods.append(v8_methods.method_context(interface, method)) conditionally_enabled_methods = [] custom_registration_methods = [] method_configuration_methods = [] for method in methods: # Skip all but one method in each set of overloaded methods. if 'overload_index' in method and 'overloads' not in method: continue if 'overloads' in method: overloads = method['overloads'] conditionally_exposed_function = overloads['exposed_test_all'] has_custom_registration = overloads['has_custom_registration_all'] else: conditionally_exposed_function = method['exposed_test'] has_custom_registration = method['has_custom_registration'] if conditionally_exposed_function: conditionally_enabled_methods.append(method) continue if has_custom_registration: custom_registration_methods.append(method) continue method_configuration_methods.append(method) for method in methods: # The value of the Function object’s “length” property is a Number # determined as follows: # 1. Let S be the effective overload set for regular operations (if the # operation is a regular operation) or for static operations (if the # operation is a static operation) with identifier id on interface I and # with argument count 0. # 2. Return the length of the shortest argument list of the entries in S. # FIXME: This calculation doesn't take into account whether runtime # enabled overloads are actually enabled, so length may be incorrect. # E.g., [RuntimeEnabled=Foo] void f(); void f(long x); # should have length 1 if Foo is not enabled, but length 0 if it is. method['length'] = (method['overloads']['minarg'] if 'overloads' in method else method['number_of_required_arguments']) context.update({ 'conditionally_enabled_methods': conditionally_enabled_methods, 'custom_registration_methods': custom_registration_methods, 'method_configuration_methods': method_configuration_methods, 'methods': methods, }) context.update({ 'indexed_property_getter': indexed_property_getter(interface), 'indexed_property_setter': indexed_property_setter(interface), 'indexed_property_deleter': indexed_property_deleter(interface), 'is_override_builtins': 'OverrideBuiltins' in extended_attributes, 'named_property_getter': named_property_getter(interface), 'named_property_setter': named_property_setter(interface), 'named_property_deleter': named_property_deleter(interface), }) return context
def interface_context(interface): includes.clear() includes.update(INTERFACE_CPP_INCLUDES) header_includes = set(INTERFACE_H_INCLUDES) parent_interface = interface.parent if parent_interface: header_includes.update( v8_types.includes_for_interface(parent_interface)) extended_attributes = interface.extended_attributes # [ActiveDOMObject] is_active_dom_object = 'ActiveDOMObject' in extended_attributes # [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) # [SetWrapperReferenceFrom] reachable_node_function = extended_attributes.get( 'SetWrapperReferenceFrom') if reachable_node_function: includes.update(['core/dom/Element.h']) # [SetWrapperReferenceTo] set_wrapper_reference_to_list = [ { 'name': argument.name, # FIXME: properly should be: # 'cpp_type': argument.idl_type.cpp_type_args(raw_type=True), # (if type is non-wrapper type like NodeFilter, normally RefPtr) # Raw pointers faster though, and NodeFilter hacky anyway. 'cpp_type': argument.idl_type.implemented_as + '*', 'idl_type': argument.idl_type, } 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() # [NotScriptWrappable] is_script_wrappable = 'NotScriptWrappable' not in extended_attributes # [SpecialWrapFor] if 'SpecialWrapFor' in extended_attributes: special_wrap_for = extended_attribute_value_as_list( interface, 'SpecialWrapFor') else: special_wrap_for = [] for special_wrap_interface in special_wrap_for: v8_types.add_includes_for_interface(special_wrap_interface) # [Custom=Wrap], [SetWrapperReferenceFrom] has_visit_dom_wrapper = (has_extended_attribute_value( interface, 'Custom', 'VisitDOMWrapper') or reachable_node_function or set_wrapper_reference_to_list) wrapper_class_id = ('NodeClassId' if inherits_interface( interface.name, 'Node') else 'ObjectClassId') context = { 'cpp_class': cpp_name(interface), '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_dependent_lifetime': is_dependent_lifetime, 'is_exception': interface.is_exception, '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', 'parent_interface': parent_interface, 'reachable_node_function': reachable_node_function, 'set_wrapper_reference_to_list': set_wrapper_reference_to_list, 'special_wrap_for': special_wrap_for, 'wrapper_class_id': wrapper_class_id, } # Constructors constructors = [ constructor_context(interface, constructor) for constructor in interface.constructors # FIXME: shouldn't put named constructors with constructors # (currently needed for Perl compatibility) # Handle named constructors separately if constructor.name == 'Constructor' ] if len(constructors) > 1: context['constructor_overloads'] = overloads_context(constructors) # [CustomConstructor] custom_constructors = [{ # Only needed for computing interface length 'number_of_required_arguments': number_of_required_arguments(constructor), } for constructor in interface.custom_constructors] # [EventConstructor] has_event_constructor = 'EventConstructor' in extended_attributes any_type_attributes = [ attribute for attribute in interface.attributes if attribute.idl_type.name == 'Any' ] # [NamedConstructor] named_constructor = named_constructor_context(interface) if (constructors or custom_constructors or has_event_constructor or named_constructor): includes.add('core/frame/LocalDOMWindow.h') context.update({ 'any_type_attributes': any_type_attributes, 'constructors': constructors, 'has_custom_constructor': bool(custom_constructors), 'has_event_constructor': has_event_constructor, 'interface_length': interface_length(interface, constructors + custom_constructors), 'is_constructor_raises_exception': extended_attributes.get('RaisesException') == 'Constructor', # [RaisesException=Constructor] 'named_constructor': named_constructor, }) constants = [ constant_context(constant) for constant in interface.constants ] # Constants context.update({ 'constants': constants, 'has_constant_configuration': True, }) # Attributes attributes = [ v8_attributes.attribute_context(interface, attribute) for attribute in interface.attributes ] context.update({ 'attributes': 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), }) # Methods methods = [ v8_methods.method_context(interface, method) for method in interface.operations if method.name ] # Skip anonymous special operations (methods) compute_method_overloads_context(methods) # Stringifier if interface.stringifier: stringifier = interface.stringifier method = IdlOperation(interface.idl_name) method.name = 'toString' method.idl_type = IdlType('DOMString') method.extended_attributes.update(stringifier.extended_attributes) if stringifier.attribute: method.extended_attributes[ 'ImplementedAs'] = stringifier.attribute.name elif stringifier.operation: method.extended_attributes[ 'ImplementedAs'] = stringifier.operation.name methods.append(v8_methods.method_context(interface, method)) conditionally_enabled_methods = [] custom_registration_methods = [] method_configuration_methods = [] for method in methods: # Skip all but one method in each set of overloaded methods. if 'overload_index' in method and 'overloads' not in method: continue if 'overloads' in method: overloads = method['overloads'] conditionally_exposed_function = overloads['exposed_test_all'] has_custom_registration = overloads['has_custom_registration_all'] else: conditionally_exposed_function = method['exposed_test'] has_custom_registration = method['has_custom_registration'] if conditionally_exposed_function: conditionally_enabled_methods.append(method) continue if has_custom_registration: custom_registration_methods.append(method) continue method_configuration_methods.append(method) for method in methods: # The value of the Function object’s “length” property is a Number # determined as follows: # 1. Let S be the effective overload set for regular operations (if the # operation is a regular operation) or for static operations (if the # operation is a static operation) with identifier id on interface I and # with argument count 0. # 2. Return the length of the shortest argument list of the entries in S. # FIXME: This calculation doesn't take into account whether runtime # enabled overloads are actually enabled, so length may be incorrect. # E.g., [RuntimeEnabled=Foo] void f(); void f(long x); # should have length 1 if Foo is not enabled, but length 0 if it is. method['length'] = (method['overloads']['minarg'] if 'overloads' in method else method['number_of_required_arguments']) context.update({ 'conditionally_enabled_methods': conditionally_enabled_methods, 'custom_registration_methods': custom_registration_methods, 'method_configuration_methods': method_configuration_methods, 'methods': methods, }) context.update({ 'indexed_property_getter': indexed_property_getter(interface), 'indexed_property_setter': indexed_property_setter(interface), 'indexed_property_deleter': indexed_property_deleter(interface), 'is_override_builtins': 'OverrideBuiltins' in extended_attributes, 'named_property_getter': named_property_getter(interface), 'named_property_setter': named_property_setter(interface), 'named_property_deleter': named_property_deleter(interface), }) return context
def create_interface_context(self, interface, component, interfaces): '''Creates a Jinja context which is based on an interface.''' assert component in ['core', 'modules'] name = '%s%s' % (v8_utilities.cpp_name(interface), 'Partial' if interface.is_partial else '') # Constructors has_constructor_callback = False if not interface.is_partial: constructors = any(constructor.name == 'Constructor' for constructor in interface.constructors) custom_constructors = interface.custom_constructors html_constructor = 'HTMLConstructor' in interface.extended_attributes has_constructor_callback = constructors or custom_constructors or html_constructor attributes = [] methods = [] has_cross_origin_indexed_getter = False has_cross_origin_named_enum = False has_cross_origin_named_getter = False has_cross_origin_named_setter = False has_origin_safe_method_setter = False has_security_check = False indexed_property_getter = None is_global = False named_property_getter = None component_info = self._info_provider.component_info if interface.name in SNAPSHOTTED_INTERFACES: attributes = [ v8_attributes.attribute_context(interface, attribute, interfaces, component_info) for attribute in interface.attributes ] methods = v8_interface.methods_context(interface, component_info)['methods'] is_global = 'Global' in interface.extended_attributes named_property_getter = v8_interface.property_getter( interface.named_property_getter, ['name']) indexed_property_getter = v8_interface.property_getter( interface.indexed_property_getter, ['index']) if not interface.is_partial: has_origin_safe_method_setter = is_global and any( method['is_check_security_for_receiver'] and not method['is_unforgeable'] for method in methods) has_security_check = ('CheckSecurity' in interface.extended_attributes and interface.name != 'EventTarget') has_cross_origin_named_getter = ( any(method['is_cross_origin'] for method in methods) or any(attribute['has_cross_origin_getter'] for attribute in attributes)) has_cross_origin_named_setter = any( attribute['has_cross_origin_setter'] for attribute in attributes) has_cross_origin_indexed_getter = indexed_property_getter and indexed_property_getter[ 'is_cross_origin'] has_cross_origin_named_enum = has_cross_origin_named_getter or has_cross_origin_named_setter if named_property_getter and named_property_getter[ 'is_cross_origin']: has_cross_origin_named_getter = True return { 'attributes': attributes, '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, 'has_cross_origin_named_setter': has_cross_origin_named_setter, 'has_cross_origin_named_enumerator': has_cross_origin_named_enum, 'has_cross_origin_indexed_getter': has_cross_origin_indexed_getter, 'has_security_check': has_security_check, 'indexed_property_getter': indexed_property_getter, '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_partial': interface.is_partial, '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_class': v8_utilities.v8_class_name_or_partial(interface), }
def create_interface_context(self, interface, interfaces): '''Creates a Jinja context which is based on an interface.''' name = '%s%s' % (v8_utilities.cpp_name(interface), 'Partial' if interface.is_partial else '') # Constructors constructors = any(constructor.name == 'Constructor' for constructor in interface.constructors) custom_constructors = interface.custom_constructors html_constructor = 'HTMLConstructor' in interface.extended_attributes has_constructor_callback = constructors or custom_constructors or html_constructor attributes = [] methods = [] has_cross_origin_indexed_getter = False has_cross_origin_named_enum = False has_cross_origin_named_getter = False has_cross_origin_named_setter = False has_origin_safe_method_setter = False has_security_check = False indexed_property_getter = None is_global = False named_property_getter = None if interface.name in SNAPSHOTTED_INTERFACES: attributes = [v8_attributes.attribute_context(interface, attribute, interfaces) for attribute in interface.attributes] methods = v8_interface.methods_context(interface)['methods'] is_global = ('PrimaryGlobal' in interface.extended_attributes or 'Global' in interface.extended_attributes) named_property_getter = v8_interface.property_getter( interface.named_property_getter, ['name']) indexed_property_getter = v8_interface.property_getter( interface.indexed_property_getter, ['index']) if not interface.is_partial: has_origin_safe_method_setter = is_global and any( method['is_check_security_for_receiver'] and not method['is_unforgeable'] for method in methods) has_security_check = ('CheckSecurity' in interface.extended_attributes and interface.name != 'EventTarget') has_cross_origin_named_getter = (any(method['is_cross_origin'] for method in methods) or any(attribute['has_cross_origin_getter'] for attribute in attributes)) has_cross_origin_named_setter = any(attribute['has_cross_origin_setter'] for attribute in attributes) has_cross_origin_indexed_getter = indexed_property_getter and indexed_property_getter['is_cross_origin'] has_cross_origin_named_enum = has_cross_origin_named_getter or has_cross_origin_named_setter if named_property_getter and named_property_getter['is_cross_origin']: has_cross_origin_named_getter = True return { 'attributes': attributes, '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, 'has_cross_origin_named_setter': has_cross_origin_named_setter, 'has_cross_origin_named_enumerator': has_cross_origin_named_enum, 'has_cross_origin_indexed_getter': has_cross_origin_indexed_getter, 'has_security_check': has_security_check, 'indexed_property_getter': indexed_property_getter, 'indexed_property_setter': v8_interface.property_setter(interface.indexed_property_setter, interface), 'indexed_property_deleter': v8_interface.property_deleter(interface.indexed_property_deleter), '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), }