def dictionary_context(dictionary, interfaces_info): includes.clear() includes.update(DICTIONARY_CPP_INCLUDES) members = [member_context(dictionary, member) for member in sorted(dictionary.members, key=operator.attrgetter('name'))] for member in members: if member['runtime_enabled_function']: includes.add('platform/RuntimeEnabledFeatures.h') break cpp_class = v8_utilities.cpp_name(dictionary) context = { 'cpp_class': cpp_class, 'header_includes': set(DICTIONARY_H_INCLUDES), 'members': members, 'required_member_names': sorted([member.name for member in dictionary.members if member.is_required]), 'use_permissive_dictionary_conversion': 'PermissiveDictionaryConversion' in dictionary.extended_attributes, 'v8_class': v8_types.v8_type(cpp_class), 'v8_original_class': v8_types.v8_type(dictionary.name), } if dictionary.parent: IdlType(dictionary.parent).add_includes_for_type() parent_cpp_class = v8_utilities.cpp_name_from_interfaces_info( dictionary.parent, interfaces_info) context.update({ 'parent_cpp_class': parent_cpp_class, 'parent_v8_class': v8_types.v8_type(parent_cpp_class), }) return context
def dictionary_context(dictionary, interfaces_info): includes.clear() includes.update(DICTIONARY_CPP_INCLUDES) cpp_class = v8_utilities.cpp_name(dictionary) context = { 'cpp_class': cpp_class, 'header_includes': set(DICTIONARY_H_INCLUDES), 'members': [ member_context(dictionary, member) for member in sorted(dictionary.members, key=operator.attrgetter('name')) ], 'use_permissive_dictionary_conversion': 'PermissiveDictionaryConversion' in dictionary.extended_attributes, 'v8_class': v8_types.v8_type(cpp_class), 'v8_original_class': v8_types.v8_type(dictionary.name), } if dictionary.parent: IdlType(dictionary.parent).add_includes_for_type() parent_cpp_class = v8_utilities.cpp_name_from_interfaces_info( dictionary.parent, interfaces_info) context.update({ 'parent_cpp_class': parent_cpp_class, 'parent_v8_class': v8_types.v8_type(parent_cpp_class), }) return context
def dictionary_context(dictionary, interfaces_info): includes.clear() includes.update(DICTIONARY_CPP_INCLUDES) if 'RuntimeEnabled' in dictionary.extended_attributes: raise Exception('Dictionary cannot be RuntimeEnabled: %s' % dictionary.name) members = [ member_context(dictionary, member) for member in sorted(dictionary.members, key=operator.attrgetter('name')) ] for member in members: if member['runtime_enabled_feature_name']: includes.add('platform/runtime_enabled_features.h') break has_origin_trial_members = False for member in members: if member['origin_trial_feature_name']: has_origin_trial_members = True includes.add('core/origin_trials/origin_trials.h') break cpp_class = v8_utilities.cpp_name(dictionary) context = { 'cpp_class': cpp_class, 'has_origin_trial_members': has_origin_trial_members, 'header_includes': set(DICTIONARY_H_INCLUDES), 'members': members, 'required_member_names': sorted([ member.name for member in dictionary.members if member.is_required ]), 'use_permissive_dictionary_conversion': 'PermissiveDictionaryConversion' in dictionary.extended_attributes, 'v8_class': v8_types.v8_type(cpp_class), 'v8_original_class': v8_types.v8_type(dictionary.name), } if dictionary.parent: IdlType(dictionary.parent).add_includes_for_type() parent_cpp_class = v8_utilities.cpp_name_from_interfaces_info( dictionary.parent, interfaces_info) context.update({ 'parent_cpp_class': parent_cpp_class, 'parent_v8_class': v8_types.v8_type(parent_cpp_class), }) return context
def dictionary_context(dictionary, interfaces_info): includes.clear() includes.update(DICTIONARY_CPP_INCLUDES) cpp_class = v8_utilities.cpp_name(dictionary) context = { "cpp_class": cpp_class, "header_includes": set(DICTIONARY_H_INCLUDES), "members": [ member_context(dictionary, member) for member in sorted(dictionary.members, key=operator.attrgetter("name")) ], "use_permissive_dictionary_conversion": "PermissiveDictionaryConversion" in dictionary.extended_attributes, "v8_class": v8_types.v8_type(cpp_class), "v8_original_class": v8_types.v8_type(dictionary.name), } if dictionary.parent: IdlType(dictionary.parent).add_includes_for_type() parent_cpp_class = v8_utilities.cpp_name_from_interfaces_info(dictionary.parent, interfaces_info) context.update({"parent_cpp_class": parent_cpp_class, "parent_v8_class": v8_types.v8_type(parent_cpp_class)}) return context
def dictionary_context(dictionary, interfaces_info): includes.clear() includes.update(DICTIONARY_CPP_INCLUDES) cpp_class = v8_utilities.cpp_name(dictionary) context = { 'cpp_class': cpp_class, 'header_includes': set(DICTIONARY_H_INCLUDES), 'members': [member_context(dictionary, member) for member in sorted(dictionary.members, key=operator.attrgetter('name'))], 'use_permissive_dictionary_conversion': 'PermissiveDictionaryConversion' in dictionary.extended_attributes, 'v8_class': v8_types.v8_type(cpp_class), 'v8_original_class': v8_types.v8_type(dictionary.name), } if dictionary.parent: IdlType(dictionary.parent).add_includes_for_type() parent_cpp_class = v8_utilities.cpp_name_from_interfaces_info( dictionary.parent, interfaces_info) context.update({ 'parent_cpp_class': parent_cpp_class, 'parent_v8_class': v8_types.v8_type(parent_cpp_class), }) return context
def generate_attribute(interface, attribute): idl_type = attribute.idl_type extended_attributes = attribute.extended_attributes 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']) contents = { 'access_control_list': access_control_list(attribute), 'activity_logging_world_list_for_getter': v8_utilities.activity_logging_world_list(attribute, 'Getter'), # [ActivityLogging] 'activity_logging_world_list_for_setter': v8_utilities.activity_logging_world_list(attribute, 'Setter'), # [ActivityLogging] 'cached_attribute_validation_method': extended_attributes.get('CachedAttribute'), 'conditional_string': v8_utilities.conditional_string(attribute), 'cpp_type': v8_types.cpp_type(idl_type), 'getter_callback_name': getter_callback_name(interface, attribute), 'getter_callback_name_for_main_world': getter_callback_name_for_main_world(interface, attribute), 'has_custom_getter': has_custom_getter, 'has_custom_setter': has_custom_setter, 'idl_type': idl_type, 'is_call_with_execution_context': v8_utilities.has_extended_attribute_value(attribute, 'CallWith', 'ExecutionContext'), 'is_constructor': is_constructor_attribute(attribute), 'is_getter_raises_exception': has_extended_attribute(attribute, ('GetterRaisesException', 'RaisesException')), 'is_keep_alive_for_gc': is_keep_alive_for_gc(attribute), 'is_nullable': attribute.is_nullable, 'is_read_only': attribute.is_read_only, 'is_replaceable': 'Replaceable' in attribute.extended_attributes, 'is_setter_raises_exception': has_extended_attribute(attribute, ('RaisesException', 'SetterRaisesException')), 'is_static': attribute.is_static, 'name': attribute.name, 'per_context_enabled_function_name': v8_utilities.per_context_enabled_function_name(attribute), # [PerContextEnabled] 'property_attributes': property_attributes(attribute), 'setter_callback_name': setter_callback_name(interface, attribute), 'setter_callback_name_for_main_world': setter_callback_name_for_main_world(interface, attribute), 'v8_type': v8_types.v8_type(idl_type), 'runtime_enabled_function_name': v8_utilities.runtime_enabled_function_name(attribute), # [RuntimeEnabled] 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended_attributes else [''], # [PerWorldBindings] 'wrapper_type_info': wrapper_type_info(attribute), } if is_constructor_attribute(attribute): includes.update(v8_types.includes_for_type(idl_type)) return contents if not has_custom_getter: generate_getter(interface, attribute, contents) if not attribute.is_read_only and not has_custom_setter: generate_setter(interface, attribute, contents) return contents
def generate_attribute_and_includes(attribute): idl_type = attribute.data_type # FIXME: need to check should_keep_attribute_alive, but for now sufficient # to check if primitive. should_keep_attribute_alive = not v8_types.primitive_type(idl_type) if should_keep_attribute_alive: return_v8_value_statement = None # unused includes = v8_types.includes_for_type(idl_type) includes.add('bindings/v8/V8HiddenPropertyName.h') else: cpp_value = 'imp->%s()' % uncapitalize(attribute.name) return_v8_value_statement = v8_types.v8_set_return_value(idl_type, cpp_value, callback_info='info') includes = [] contents = { 'name': attribute.name, 'conditional_string': generate_conditional_string(attribute), 'cpp_method_name': cpp_method_name(attribute), 'cpp_type': v8_types.cpp_type(idl_type, pointer_type='RefPtr'), 'should_keep_attribute_alive': should_keep_attribute_alive, 'return_v8_value_statement': return_v8_value_statement, 'v8_type': v8_types.v8_type(idl_type), } return contents, includes
def v8_class_name(interface): return v8_types.v8_type(interface.name)
def container_context(union_type, interfaces_info): cpp_includes.clear() header_forward_decls.clear() header_includes.clear() cpp_includes.update(UNION_CPP_INCLUDES) header_includes.update(UNION_H_INCLUDES) members = [] # These variables refer to member contexts if the given union type has # corresponding types. They are used for V8 -> impl conversion. array_buffer_type = None array_buffer_view_type = None array_or_sequence_type = None boolean_type = None dictionary_type = None interface_types = [] numeric_type = None object_type = None string_type = None for member in union_type.member_types: context = member_context(member, interfaces_info) members.append(context) if member.base_type == 'ArrayBuffer': if array_buffer_type: raise Exception('%s is ambiguous.' % union_type.name) array_buffer_type = context elif member.base_type == 'ArrayBufferView': if array_buffer_view_type: raise Exception('%s is ambiguous.' % union_type.name) array_buffer_view_type = context elif member.is_dictionary: if dictionary_type: raise Exception('%s is ambiguous.' % union_type.name) dictionary_type = context elif member.is_array_or_sequence_type: if array_or_sequence_type: raise Exception('%s is ambiguous.' % union_type.name) array_or_sequence_type = context # "Dictionary" is an object, rather than an IDL dictionary. elif member.base_type == 'Dictionary': if object_type: raise Exception('%s is ambiguous.' % union_type.name) object_type = context elif member.is_interface_type: interface_types.append(context) elif member is union_type.boolean_member_type: boolean_type = context elif member is union_type.numeric_member_type: numeric_type = context elif member is union_type.string_member_type: string_type = context else: raise Exception('%s is not supported as an union member.' % member.name) # Nullable restriction checks nullable_members = union_type.number_of_nullable_member_types if nullable_members > 1: raise Exception('%s contains more than one nullable members' % union_type.name) if dictionary_type and nullable_members == 1: raise Exception('%s has a dictionary and a nullable member' % union_type.name) cpp_class = union_type.cpp_type return { 'array_buffer_type': array_buffer_type, 'array_buffer_view_type': array_buffer_view_type, 'array_or_sequence_type': array_or_sequence_type, 'boolean_type': boolean_type, 'cpp_class': cpp_class, 'cpp_includes': sorted(cpp_includes - UNION_CPP_INCLUDES_BLACKLIST), 'dictionary_type': dictionary_type, 'header_includes': sorted(header_includes), 'header_forward_decls': sorted(header_forward_decls), 'includes_nullable_type': union_type.includes_nullable_type, 'interface_types': interface_types, 'members': members, 'numeric_type': numeric_type, 'object_type': object_type, 'string_type': string_type, 'type_string': str(union_type), 'v8_class': v8_types.v8_type(cpp_class), }
def generate_attribute(interface, attribute): idl_type = attribute.idl_type extended_attributes = attribute.extended_attributes v8_types.add_includes_for_type(idl_type) # [CheckSecurity] is_check_security_for_node = 'CheckSecurity' in extended_attributes if is_check_security_for_node: includes.add('bindings/v8/BindingSecurity.h') # [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']) # [Reflect] is_reflect = 'Reflect' in extended_attributes if is_reflect: includes.add('core/dom/custom/CustomElementCallbackDispatcher.h') if (idl_type == 'EventHandler' and interface.name in ['Window', 'WorkerGlobalScope'] and attribute.name == 'onerror'): includes.add('bindings/v8/V8ErrorHandler.h') contents = { 'access_control_list': access_control_list(attribute), 'activity_logging_world_list_for_getter': v8_utilities.activity_logging_world_list( attribute, 'Getter'), # [ActivityLogging] 'activity_logging_world_list_for_setter': v8_utilities.activity_logging_world_list( attribute, 'Setter'), # [ActivityLogging] 'cached_attribute_validation_method': extended_attributes.get('CachedAttribute'), 'conditional_string': v8_utilities.conditional_string(attribute), 'constructor_type': v8_types.constructor_type(idl_type) if is_constructor_attribute(attribute) else None, 'cpp_name': cpp_name(attribute), 'cpp_type': v8_types.cpp_type(idl_type), 'deprecate_as': v8_utilities.deprecate_as(attribute), # [DeprecateAs] 'enum_validation_expression': v8_utilities.enum_validation_expression(idl_type), 'has_custom_getter': has_custom_getter, 'has_custom_setter': has_custom_setter, 'has_strict_type_checking': ('StrictTypeChecking' in extended_attributes and v8_types.is_interface_type(idl_type)), 'idl_type': idl_type, 'is_call_with_execution_context': v8_utilities.has_extended_attribute_value(attribute, 'CallWith', 'ExecutionContext'), 'is_check_security_for_node': is_check_security_for_node, 'is_expose_js_accessors': 'ExposeJSAccessors' in extended_attributes, 'is_getter_raises_exception': ( # [RaisesException] 'RaisesException' in extended_attributes and extended_attributes['RaisesException'] in [None, 'Getter']), 'is_initialized_by_event_constructor': 'InitializedByEventConstructor' in extended_attributes, 'is_keep_alive_for_gc': is_keep_alive_for_gc(attribute), 'is_nullable': attribute.is_nullable, 'is_per_world_bindings': 'PerWorldBindings' in extended_attributes, 'is_read_only': attribute.is_read_only, 'is_reflect': is_reflect, 'is_replaceable': 'Replaceable' in attribute.extended_attributes, 'is_setter_raises_exception': ('RaisesException' in extended_attributes and extended_attributes['RaisesException'] in [None, 'Setter']), 'is_static': attribute.is_static, 'is_unforgeable': 'Unforgeable' in extended_attributes, 'measure_as': v8_utilities.measure_as(attribute), # [MeasureAs] 'name': attribute.name, 'per_context_enabled_function': v8_utilities.per_context_enabled_function_name( attribute), # [PerContextEnabled] 'property_attributes': property_attributes(attribute), 'setter_callback': setter_callback_name(interface, attribute), 'v8_type': v8_types.v8_type(idl_type), 'runtime_enabled_function': v8_utilities.runtime_enabled_function_name( attribute), # [RuntimeEnabled] 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended_attributes else [''], # [PerWorldBindings] } if is_constructor_attribute(attribute): return contents if not has_custom_getter: generate_getter(interface, attribute, contents) if not (attribute.is_read_only or has_custom_setter): contents.update({ 'cpp_setter': setter_expression(interface, attribute, contents), 'v8_value_to_local_cpp_value': v8_types.v8_value_to_local_cpp_value(idl_type, extended_attributes, 'jsValue', 'cppValue'), }) return contents
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 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 # [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 # [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 = { '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' 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( '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, } # 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] # 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), }) # 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']) 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), }) # 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'] 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: 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 generate_interface(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 is_audio_buffer = inherits_interface(interface.name, 'AudioBuffer') if is_audio_buffer: includes.add('modules/webaudio/AudioBuffer.h') is_document = inherits_interface(interface.name, 'Document') if is_document: includes.update([ 'bindings/v8/ScriptController.h', 'bindings/v8/V8WindowShell.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/v8/BindingSecurity.h') # [DependentLifetime] is_dependent_lifetime = 'DependentLifetime' in extended_attributes # [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/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(used_as_argument=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() # [SpecialWrapFor] if 'SpecialWrapFor' in extended_attributes: special_wrap_for = extended_attributes['SpecialWrapFor'].split('|') 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) this_gc_type = gc_type(interface) template_contents = { 'conditional_string': conditional_string(interface), # [Conditional] 'cpp_class': cpp_name(interface), 'gc_type': this_gc_type, '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_audio_buffer': is_audio_buffer, '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'), '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, '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', } # Constructors constructors = [ generate_constructor(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: template_contents['constructor_overloads'] = generate_overloads( 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/v8/Dictionary.h') if any_type_attributes: includes.add('bindings/v8/SerializedScriptValue.h') # [NamedConstructor] named_constructor = generate_named_constructor(interface) if (constructors or custom_constructors or has_event_constructor or named_constructor): includes.add('bindings/v8/V8ObjectConstructor.h') includes.add('core/frame/DOMWindow.h') template_contents.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_call_with_document': has_extended_attribute_value( interface, 'ConstructorCallWith', 'Document'), # [ConstructorCallWith=Document] 'is_constructor_call_with_execution_context': has_extended_attribute_value( interface, 'ConstructorCallWith', 'ExecutionContext'), # [ConstructorCallWith=ExeuctionContext] 'is_constructor_raises_exception': extended_attributes.get('RaisesException') == 'Constructor', # [RaisesException=Constructor] 'named_constructor': named_constructor, }) # Constants template_contents.update({ 'constants': [generate_constant(constant) for constant in interface.constants], 'do_not_check_constants': 'DoNotCheckConstants' in extended_attributes, }) # Attributes attributes = [ v8_attributes.generate_attribute(interface, attribute) for attribute in interface.attributes ] template_contents.update({ 'attributes': attributes, 'has_accessors': any(attribute['is_expose_js_accessors'] 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']) for attribute in attributes), 'has_constructor_attributes': any(attribute['constructor_type'] for attribute in attributes), 'has_per_context_enabled_attributes': any(attribute['per_context_enabled_function'] for attribute in attributes), 'has_replaceable_attributes': any(attribute['is_replaceable'] for attribute in attributes), }) # Methods methods = [ v8_methods.generate_method(interface, method) for method in interface.operations if method.name ] # Skip anonymous special operations (methods) generate_method_overloads(methods) for method in methods: method['do_generate_method_configuration'] = ( method['do_not_check_signature'] and not method['per_context_enabled_function'] and # For overloaded methods, only generate one accessor ('overload_index' not in method or method['overload_index'] == 1)) template_contents.update({ 'has_origin_safe_method_setter': any(method['is_check_security_for_frame'] and not method['is_read_only'] for method in methods), 'has_method_configuration': any(method['do_generate_method_configuration'] for method in methods), 'has_per_context_enabled_methods': any(method['per_context_enabled_function'] for method in methods), 'methods': methods, }) template_contents.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 template_contents
def generate_attribute(interface, attribute): idl_type = attribute.idl_type extended_attributes = attribute.extended_attributes v8_types.add_includes_for_type(idl_type) # [CheckSecurity] is_check_security_for_node = 'CheckSecurity' in extended_attributes if is_check_security_for_node: includes.add('bindings/v8/BindingSecurity.h') # [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']) # [RaisesException] is_getter_raises_exception = ( 'RaisesException' in extended_attributes and extended_attributes['RaisesException'] in [None, 'Getter']) if is_check_security_for_node or is_getter_raises_exception: includes.add('bindings/v8/ExceptionMessages.h') # [Reflect] is_reflect = 'Reflect' in extended_attributes if is_reflect: includes.add('core/dom/custom/CustomElementCallbackDispatcher.h') if (idl_type == 'EventHandler' and interface.name in ['Window', 'WorkerGlobalScope'] and attribute.name == 'onerror'): includes.add('bindings/v8/V8ErrorHandler.h') contents = { 'access_control_list': access_control_list(attribute), 'activity_logging_world_list_for_getter': v8_utilities.activity_logging_world_list(attribute, 'Getter'), # [ActivityLogging] 'activity_logging_world_list_for_setter': v8_utilities.activity_logging_world_list(attribute, 'Setter'), # [ActivityLogging] 'cached_attribute_validation_method': extended_attributes.get('CachedAttribute'), 'conditional_string': v8_utilities.conditional_string(attribute), 'constructor_type': v8_types.constructor_type(idl_type) if is_constructor_attribute(attribute) else None, 'cpp_name': cpp_name(attribute), 'cpp_type': v8_types.cpp_type(idl_type), 'deprecate_as': v8_utilities.deprecate_as(attribute), # [DeprecateAs] 'enum_validation_expression': v8_utilities.enum_validation_expression(idl_type), 'has_custom_getter': has_custom_getter, 'has_custom_setter': has_custom_setter, 'has_strict_type_checking': ( 'StrictTypeChecking' in extended_attributes and v8_types.is_interface_type(idl_type)), 'idl_type': idl_type, 'is_call_with_execution_context': v8_utilities.has_extended_attribute_value(attribute, 'CallWith', 'ExecutionContext'), 'is_check_security_for_node': is_check_security_for_node, 'is_expose_js_accessors': 'ExposeJSAccessors' in extended_attributes, 'is_getter_raises_exception': ( 'RaisesException' in extended_attributes and extended_attributes['RaisesException'] in [None, 'Getter']), 'is_initialized_by_event_constructor': 'InitializedByEventConstructor' in extended_attributes, 'is_keep_alive_for_gc': is_keep_alive_for_gc(attribute), 'is_nullable': attribute.is_nullable, 'is_per_world_bindings': 'PerWorldBindings' in extended_attributes, 'is_read_only': attribute.is_read_only, 'is_reflect': is_reflect, 'is_replaceable': 'Replaceable' in attribute.extended_attributes, 'is_setter_raises_exception': ( 'RaisesException' in extended_attributes and extended_attributes['RaisesException'] in [None, 'Setter']), 'is_static': attribute.is_static, 'is_unforgeable': 'Unforgeable' in extended_attributes, 'measure_as': v8_utilities.measure_as(attribute), # [MeasureAs] 'name': attribute.name, 'per_context_enabled_function': v8_utilities.per_context_enabled_function_name(attribute), # [PerContextEnabled] 'property_attributes': property_attributes(attribute), 'setter_callback': setter_callback_name(interface, attribute), 'v8_type': v8_types.v8_type(idl_type), 'runtime_enabled_function': v8_utilities.runtime_enabled_function_name(attribute), # [RuntimeEnabled] 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended_attributes else [''], # [PerWorldBindings] } if is_constructor_attribute(attribute): return contents if not has_custom_getter: generate_getter(interface, attribute, contents) if not(attribute.is_read_only or has_custom_setter): contents.update({ 'cpp_setter': setter_expression(interface, attribute, contents), 'v8_value_to_local_cpp_value': v8_types.v8_value_to_local_cpp_value( idl_type, extended_attributes, 'jsValue', 'cppValue'), }) return contents
def generate_interface(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 is_audio_buffer = inherits_interface(interface.name, 'AudioBuffer') if is_audio_buffer: includes.add('modules/webaudio/AudioBuffer.h') is_document = inherits_interface(interface.name, 'Document') if is_document: includes.update(['bindings/v8/ScriptController.h', 'bindings/v8/V8WindowShell.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/v8/BindingSecurity.h') # [DependentLifetime] is_dependent_lifetime = 'DependentLifetime' in extended_attributes # [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/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(used_as_argument=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() # [SpecialWrapFor] if 'SpecialWrapFor' in extended_attributes: special_wrap_for = extended_attributes['SpecialWrapFor'].split('|') else: special_wrap_for = [] for special_wrap_interface in special_wrap_for: v8_types.add_includes_for_interface(special_wrap_interface) # [WillBeGarbageCollected] is_will_be_garbage_collected = 'WillBeGarbageCollected' 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) template_contents = { 'conditional_string': conditional_string(interface), # [Conditional] 'cpp_class': cpp_name(interface), '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_audio_buffer': is_audio_buffer, '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_will_be_garbage_collected': is_will_be_garbage_collected, 'is_node': inherits_interface(interface.name, 'Node'), 'measure_as': v8_utilities.measure_as(interface), # [MeasureAs] 'parent_interface': parent_interface, 'pass_ref_ptr': 'PassRefPtrWillBeRawPtr' if is_will_be_garbage_collected else 'PassRefPtr', 'reachable_node_function': reachable_node_function, 'ref_ptr': 'RefPtrWillBeRawPtr' if is_will_be_garbage_collected else 'RefPtr', '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_configuration': 'WrapperConfiguration::Dependent' if (has_visit_dom_wrapper or is_active_dom_object or is_dependent_lifetime) else 'WrapperConfiguration::Independent', } # Constructors constructors = [generate_constructor(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'] generate_constructor_overloads(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/v8/Dictionary.h') if any_type_attributes: includes.add('bindings/v8/SerializedScriptValue.h') # [NamedConstructor] named_constructor = generate_named_constructor(interface) if (constructors or custom_constructors or has_event_constructor or named_constructor): includes.add('bindings/v8/V8ObjectConstructor.h') includes.add('core/frame/DOMWindow.h') template_contents.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_call_with_document': has_extended_attribute_value( interface, 'ConstructorCallWith', 'Document'), # [ConstructorCallWith=Document] 'is_constructor_call_with_execution_context': has_extended_attribute_value( interface, 'ConstructorCallWith', 'ExecutionContext'), # [ConstructorCallWith=ExeuctionContext] 'is_constructor_raises_exception': extended_attributes.get('RaisesException') == 'Constructor', # [RaisesException=Constructor] 'named_constructor': named_constructor, }) # Constants template_contents.update({ 'constants': [generate_constant(constant) for constant in interface.constants], 'do_not_check_constants': 'DoNotCheckConstants' in extended_attributes, }) # Attributes attributes = [v8_attributes.generate_attribute(interface, attribute) for attribute in interface.attributes] template_contents.update({ 'attributes': attributes, 'has_accessors': any(attribute['is_expose_js_accessors'] 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']) for attribute in attributes), 'has_constructor_attributes': any(attribute['constructor_type'] for attribute in attributes), 'has_per_context_enabled_attributes': any(attribute['per_context_enabled_function'] for attribute in attributes), 'has_replaceable_attributes': any(attribute['is_replaceable'] for attribute in attributes), }) # Methods methods = [v8_methods.generate_method(interface, method) for method in interface.operations if method.name] # Skip anonymous special operations (methods) generate_overloads(methods) for method in methods: method['do_generate_method_configuration'] = ( method['do_not_check_signature'] and not method['per_context_enabled_function'] and # For overloaded methods, only generate one accessor ('overload_index' not in method or method['overload_index'] == 1)) template_contents.update({ 'has_origin_safe_method_setter': any( method['is_check_security_for_frame'] and not method['is_read_only'] for method in methods), 'has_method_configuration': any(method['do_generate_method_configuration'] for method in methods), 'has_per_context_enabled_methods': any(method['per_context_enabled_function'] for method in methods), 'methods': methods, }) template_contents.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 template_contents
def attribute_context(interface, attribute): idl_type = attribute.idl_type base_idl_type = idl_type.base_type extended_attributes = attribute.extended_attributes idl_type.add_includes_for_type() # [CheckSecurity] is_check_security_for_node = 'CheckSecurity' in extended_attributes if is_check_security_for_node: includes.add('bindings/core/v8/BindingSecurity.h') # [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']) # [CustomElementCallbacks], [Reflect] is_custom_element_callbacks = 'CustomElementCallbacks' in extended_attributes is_reflect = 'Reflect' in extended_attributes if is_custom_element_callbacks or is_reflect: includes.add('core/dom/custom/CustomElementCallbackDispatcher.h') # [PerWorldBindings] if 'PerWorldBindings' in extended_attributes: assert idl_type.is_wrapper_type or 'LogActivity' in extended_attributes, '[PerWorldBindings] should only be used with wrapper types: %s.%s' % (interface.name, attribute.name) # [TypeChecking] has_type_checking_unrestricted = ( (has_extended_attribute_value(interface, 'TypeChecking', 'Unrestricted') or has_extended_attribute_value(attribute, 'TypeChecking', 'Unrestricted')) and idl_type.name in ('Float', 'Double')) # [ImplementedInPrivateScript] is_implemented_in_private_script = 'ImplementedInPrivateScript' in extended_attributes if is_implemented_in_private_script: includes.add('bindings/core/v8/PrivateScriptRunner.h') includes.add('core/frame/LocalFrame.h') if (base_idl_type == 'EventHandler' and interface.name in ['Window', 'WorkerGlobalScope'] and attribute.name == 'onerror'): includes.add('bindings/core/v8/V8ErrorHandler.h') # Nullable type where the corresponding C++ type supports a null value. is_nullable_simple = idl_type.is_nullable and ( (idl_type.is_string_type or idl_type.is_wrapper_type) and not idl_type.array_or_sequence_type) context = { 'access_control_list': access_control_list(attribute), 'activity_logging_world_list_for_getter': v8_utilities.activity_logging_world_list(attribute, 'Getter'), # [ActivityLogging] 'activity_logging_world_list_for_setter': v8_utilities.activity_logging_world_list(attribute, 'Setter'), # [ActivityLogging] 'activity_logging_include_old_value_for_setter': 'LogPreviousValue' in extended_attributes, # [ActivityLogging] 'activity_logging_world_check': v8_utilities.activity_logging_world_check(attribute), # [ActivityLogging] 'argument_cpp_type': idl_type.cpp_type_args(used_as_argument=True), 'cached_attribute_validation_method': extended_attributes.get('CachedAttribute'), 'conditional_string': v8_utilities.conditional_string(attribute), 'constructor_type': idl_type.constructor_type_name if is_constructor_attribute(attribute) else None, 'cpp_name': cpp_name(attribute), 'cpp_type': idl_type.cpp_type, 'deprecate_as': v8_utilities.deprecate_as(attribute), # [DeprecateAs] 'enum_validation_expression': idl_type.enum_validation_expression, 'has_custom_getter': has_custom_getter, 'has_custom_setter': has_custom_setter, 'has_type_checking_unrestricted': has_type_checking_unrestricted, 'idl_type': str(idl_type), # need trailing [] on array for Dictionary::ConversionContext::setConversionType 'is_call_with_execution_context': v8_utilities.has_extended_attribute_value(attribute, 'CallWith', 'ExecutionContext'), 'is_call_with_script_state': v8_utilities.has_extended_attribute_value(attribute, 'CallWith', 'ScriptState'), 'is_check_security_for_node': is_check_security_for_node, 'is_custom_element_callbacks': is_custom_element_callbacks, 'is_expose_js_accessors': 'ExposeJSAccessors' in extended_attributes, 'is_getter_raises_exception': # [RaisesException] 'RaisesException' in extended_attributes and extended_attributes['RaisesException'] in (None, 'Getter'), 'is_implemented_in_private_script': is_implemented_in_private_script, 'is_initialized_by_event_constructor': 'InitializedByEventConstructor' in extended_attributes, 'is_keep_alive_for_gc': is_keep_alive_for_gc(interface, attribute), 'is_nullable': idl_type.is_nullable, 'is_nullable_simple': is_nullable_simple, 'is_partial_interface_member': 'PartialInterfaceImplementedAs' in extended_attributes, 'is_per_world_bindings': 'PerWorldBindings' in extended_attributes, 'is_read_only': attribute.is_read_only, 'is_reflect': is_reflect, 'is_replaceable': 'Replaceable' in attribute.extended_attributes, 'is_static': attribute.is_static, 'is_url': 'URL' in extended_attributes, 'is_unforgeable': 'Unforgeable' in extended_attributes, 'measure_as': v8_utilities.measure_as(attribute), # [MeasureAs] 'name': attribute.name, 'per_context_enabled_function': v8_utilities.per_context_enabled_function_name(attribute), # [PerContextEnabled] 'private_script_v8_value_to_local_cpp_value': idl_type.v8_value_to_local_cpp_value( extended_attributes, 'v8Value', 'cppValue', isolate='scriptState->isolate()', used_in_private_script=True), 'property_attributes': property_attributes(attribute), 'put_forwards': 'PutForwards' in extended_attributes, 'reflect_empty': extended_attributes.get('ReflectEmpty'), 'reflect_invalid': extended_attributes.get('ReflectInvalid', ''), 'reflect_missing': extended_attributes.get('ReflectMissing'), 'reflect_only': extended_attributes['ReflectOnly'].split('|') if 'ReflectOnly' in extended_attributes else None, 'runtime_enabled_function': v8_utilities.runtime_enabled_function_name(attribute), # [RuntimeEnabled] 'setter_callback': setter_callback_name(interface, attribute), 'v8_type': v8_types.v8_type(base_idl_type), 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended_attributes else [''], # [PerWorldBindings] } if is_constructor_attribute(attribute): constructor_getter_context(interface, attribute, context) return context if not has_custom_getter: getter_context(interface, attribute, context) if (not has_custom_setter and (not attribute.is_read_only or 'PutForwards' in extended_attributes)): setter_context(interface, attribute, context) return context
def container_context(union_type, info_provider): cpp_includes.clear() header_forward_decls.clear() header_includes.clear() cpp_includes.update(UNION_CPP_INCLUDES) header_includes.update(UNION_H_INCLUDES) members = [] # These variables refer to member contexts if the given union type has # corresponding types. They are used for V8 -> impl conversion. array_buffer_type = None array_buffer_view_type = None array_or_sequence_type = None boolean_type = None dictionary_type = None interface_types = [] numeric_type = None object_type = None record_type = None string_type = None for member in sorted(union_type.flattened_member_types, key=lambda m: m.name): context = member_context(member, info_provider) members.append(context) if member.base_type == 'ArrayBuffer': if array_buffer_type: raise Exception('%s is ambiguous.' % union_type.name) array_buffer_type = context elif member.base_type == 'ArrayBufferView': if array_buffer_view_type: raise Exception('%s is ambiguous.' % union_type.name) array_buffer_view_type = context elif member.is_dictionary: if dictionary_type: raise Exception('%s is ambiguous.' % union_type.name) dictionary_type = context elif member.is_array_or_sequence_type: if array_or_sequence_type: raise Exception('%s is ambiguous.' % union_type.name) array_or_sequence_type = context # "Dictionary" is an object, rather than an IDL dictionary. elif member.base_type == 'Dictionary': if object_type or record_type: raise Exception('%s is ambiguous.' % union_type.name) object_type = context elif member.is_record_type: if object_type or record_type: raise Exception('%s is ambiguous.' % union_type.name) record_type = context elif member.is_interface_type: interface_types.append(context) elif member is union_type.boolean_member_type: boolean_type = context elif member is union_type.numeric_member_type: numeric_type = context elif member is union_type.string_member_type: string_type = context else: raise Exception('%s is not supported as an union member.' % member.name) # Nullable restriction checks nullable_members = union_type.number_of_nullable_member_types if nullable_members > 1: raise Exception('%s contains more than one nullable members' % union_type.name) if dictionary_type and nullable_members == 1: raise Exception('%s has a dictionary and a nullable member' % union_type.name) cpp_class = union_type.cpp_type return { 'array_buffer_type': array_buffer_type, 'array_buffer_view_type': array_buffer_view_type, 'array_or_sequence_type': array_or_sequence_type, 'boolean_type': boolean_type, 'cpp_class': cpp_class, 'cpp_includes': sorted(cpp_includes), 'dictionary_type': dictionary_type, 'header_includes': sorted(header_includes), 'header_forward_decls': sorted(header_forward_decls), 'includes_nullable_type': union_type.includes_nullable_type, 'interface_types': interface_types, 'members': members, 'numeric_type': numeric_type, 'object_type': object_type, 'record_type': record_type, 'string_type': string_type, 'type_string': str(union_type), 'v8_class': v8_types.v8_type(cpp_class), }
def generate_attribute(interface, attribute): idl_type = attribute.idl_type base_idl_type = idl_type.base_type extended_attributes = attribute.extended_attributes idl_type.add_includes_for_type() # [CheckSecurity] is_check_security_for_node = 'CheckSecurity' in extended_attributes if is_check_security_for_node: includes.add('bindings/v8/BindingSecurity.h') # [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']) # [CustomElementCallbacks], [Reflect] is_custom_element_callbacks = 'CustomElementCallbacks' in extended_attributes is_reflect = 'Reflect' in extended_attributes if is_custom_element_callbacks or is_reflect: includes.add('core/dom/custom/CustomElementCallbackDispatcher.h') # [PerWorldBindings] if 'PerWorldBindings' in extended_attributes: assert idl_type.is_wrapper_type or 'LogActivity' in extended_attributes, '[PerWorldBindings] should only be used with wrapper types: %s.%s' % ( interface.name, attribute.name) # [RaisesException], [RaisesException=Setter] is_setter_raises_exception = ('RaisesException' in extended_attributes and extended_attributes['RaisesException'] in [None, 'Setter']) # [TypeChecking] has_type_checking_interface = (( has_extended_attribute_value(interface, 'TypeChecking', 'Interface') or has_extended_attribute_value(attribute, 'TypeChecking', 'Interface')) and idl_type.is_wrapper_type) has_type_checking_nullable = ( (has_extended_attribute_value(interface, 'TypeChecking', 'Nullable') or has_extended_attribute_value(attribute, 'TypeChecking', 'Nullable')) and idl_type.is_wrapper_type) has_type_checking_unrestricted = (( has_extended_attribute_value(interface, 'TypeChecking', 'Unrestricted') or has_extended_attribute_value(attribute, 'TypeChecking', 'Unrestricted')) and idl_type.name in ('Float', 'Double')) if (base_idl_type == 'EventHandler' and interface.name in ['Window', 'WorkerGlobalScope'] and attribute.name == 'onerror'): includes.add('bindings/v8/V8ErrorHandler.h') contents = { 'access_control_list': access_control_list(attribute), 'activity_logging_world_list_for_getter': v8_utilities.activity_logging_world_list(attribute, 'Getter'), # [ActivityLogging] 'activity_logging_world_list_for_setter': v8_utilities.activity_logging_world_list(attribute, 'Setter'), # [ActivityLogging] 'activity_logging_include_old_value_for_setter': 'LogPreviousValue' in extended_attributes, # [ActivityLogging] 'cached_attribute_validation_method': extended_attributes.get('CachedAttribute'), 'conditional_string': v8_utilities.conditional_string(attribute), 'constructor_type': idl_type.constructor_type_name if is_constructor_attribute(attribute) else None, 'cpp_name': cpp_name(attribute), 'cpp_type': idl_type.cpp_type, 'cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value(cpp_value='original', creation_context='info.Holder()'), 'deprecate_as': v8_utilities.deprecate_as(attribute), # [DeprecateAs] 'enum_validation_expression': idl_type.enum_validation_expression, 'has_custom_getter': has_custom_getter, 'has_custom_setter': has_custom_setter, 'has_setter_exception_state': is_setter_raises_exception or has_type_checking_interface or has_type_checking_nullable or has_type_checking_unrestricted or idl_type.is_integer_type, 'has_type_checking_interface': has_type_checking_interface, 'has_type_checking_nullable': has_type_checking_nullable, 'has_type_checking_unrestricted': has_type_checking_unrestricted, 'idl_type': str(idl_type), # need trailing [] on array for Dictionary::ConversionContext::setConversionType 'is_call_with_execution_context': v8_utilities.has_extended_attribute_value(attribute, 'CallWith', 'ExecutionContext'), 'is_call_with_script_state': v8_utilities.has_extended_attribute_value(attribute, 'CallWith', 'ScriptState'), 'is_check_security_for_node': is_check_security_for_node, 'is_custom_element_callbacks': is_custom_element_callbacks, 'is_expose_js_accessors': 'ExposeJSAccessors' in extended_attributes, 'is_getter_raises_exception': # [RaisesException] 'RaisesException' in extended_attributes and extended_attributes['RaisesException'] in (None, 'Getter'), 'is_initialized_by_event_constructor': 'InitializedByEventConstructor' in extended_attributes, 'is_keep_alive_for_gc': is_keep_alive_for_gc(interface, attribute), 'is_nullable': attribute.idl_type.is_nullable, 'is_partial_interface_member': 'PartialInterfaceImplementedAs' in extended_attributes, 'is_per_world_bindings': 'PerWorldBindings' in extended_attributes, 'is_read_only': attribute.is_read_only, 'is_reflect': is_reflect, 'is_replaceable': 'Replaceable' in attribute.extended_attributes, 'is_setter_call_with_execution_context': v8_utilities.has_extended_attribute_value(attribute, 'SetterCallWith', 'ExecutionContext'), 'is_setter_raises_exception': is_setter_raises_exception, 'is_static': attribute.is_static, 'is_url': 'URL' in extended_attributes, 'is_unforgeable': 'Unforgeable' in extended_attributes, 'measure_as': v8_utilities.measure_as(attribute), # [MeasureAs] 'name': attribute.name, 'per_context_enabled_function': v8_utilities.per_context_enabled_function_name(attribute), # [PerContextEnabled] 'property_attributes': property_attributes(attribute), 'put_forwards': 'PutForwards' in extended_attributes, 'reflect_empty': extended_attributes.get('ReflectEmpty'), 'reflect_invalid': extended_attributes.get('ReflectInvalid', ''), 'reflect_missing': extended_attributes.get('ReflectMissing'), 'reflect_only': extended_attributes['ReflectOnly'].split('|') if 'ReflectOnly' in extended_attributes else None, 'setter_callback': setter_callback_name(interface, attribute), 'v8_type': v8_types.v8_type(base_idl_type), 'runtime_enabled_function': v8_utilities.runtime_enabled_function_name(attribute), # [RuntimeEnabled] 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended_attributes else [''], # [PerWorldBindings] } if is_constructor_attribute(attribute): generate_constructor_getter(interface, attribute, contents) return contents if not has_custom_getter: generate_getter(interface, attribute, contents) if (not has_custom_setter and (not attribute.is_read_only or 'PutForwards' in extended_attributes)): generate_setter(interface, attribute, contents) return contents
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 generate_attribute(interface, attribute): idl_type = attribute.idl_type base_idl_type = idl_type.base_type extended_attributes = attribute.extended_attributes idl_type.add_includes_for_type() # [CheckSecurity] is_check_security_for_node = 'CheckSecurity' in extended_attributes if is_check_security_for_node: includes.add('bindings/v8/BindingSecurity.h') # [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']) # [CustomElementCallbacks], [Reflect] is_custom_element_callbacks = 'CustomElementCallbacks' in extended_attributes is_reflect = 'Reflect' in extended_attributes if is_custom_element_callbacks or is_reflect: includes.add('core/dom/custom/CustomElementCallbackDispatcher.h') # [RaisesException], [RaisesException=Setter] is_setter_raises_exception = ( 'RaisesException' in extended_attributes and extended_attributes['RaisesException'] in [None, 'Setter']) # [StrictTypeChecking] has_strict_type_checking = ( ('StrictTypeChecking' in extended_attributes or 'StrictTypeChecking' in interface.extended_attributes) and idl_type.is_wrapper_type) if (base_idl_type == 'EventHandler' and interface.name in ['Window', 'WorkerGlobalScope'] and attribute.name == 'onerror'): includes.add('bindings/v8/V8ErrorHandler.h') contents = { 'access_control_list': access_control_list(attribute), 'activity_logging_world_list_for_getter': v8_utilities.activity_logging_world_list(attribute, 'Getter'), # [ActivityLogging] 'activity_logging_world_list_for_setter': v8_utilities.activity_logging_world_list(attribute, 'Setter'), # [ActivityLogging] 'cached_attribute_validation_method': extended_attributes.get('CachedAttribute'), 'conditional_string': v8_utilities.conditional_string(attribute), 'constructor_type': idl_type.constructor_type_name if is_constructor_attribute(attribute) else None, 'cpp_name': cpp_name(attribute), 'cpp_type': idl_type.cpp_type, 'deprecate_as': v8_utilities.deprecate_as(attribute), # [DeprecateAs] 'enum_validation_expression': idl_type.enum_validation_expression, 'has_custom_getter': has_custom_getter, 'has_custom_setter': has_custom_setter, 'has_strict_type_checking': has_strict_type_checking, 'idl_type': str(idl_type), # need trailing [] on array for Dictionary::ConversionContext::setConversionType 'is_call_with_execution_context': v8_utilities.has_extended_attribute_value(attribute, 'CallWith', 'ExecutionContext'), 'is_call_with_new_script_state': v8_utilities.has_extended_attribute_value(attribute, 'CallWith', 'NewScriptState'), 'is_check_security_for_node': is_check_security_for_node, 'is_custom_element_callbacks': is_custom_element_callbacks, 'is_expose_js_accessors': 'ExposeJSAccessors' in extended_attributes, 'is_getter_raises_exception': ( # [RaisesException] 'RaisesException' in extended_attributes and extended_attributes['RaisesException'] in [None, 'Getter']), 'is_initialized_by_event_constructor': 'InitializedByEventConstructor' in extended_attributes, 'is_keep_alive_for_gc': is_keep_alive_for_gc(interface, attribute), 'is_nullable': attribute.idl_type.is_nullable, 'is_partial_interface_member': 'PartialInterfaceImplementedAs' in extended_attributes, 'is_per_world_bindings': 'PerWorldBindings' in extended_attributes, 'is_read_only': attribute.is_read_only, 'is_reflect': is_reflect, 'is_replaceable': 'Replaceable' in attribute.extended_attributes, 'is_setter_call_with_execution_context': v8_utilities.has_extended_attribute_value(attribute, 'SetterCallWith', 'ExecutionContext'), 'is_setter_raises_exception': is_setter_raises_exception, 'has_setter_exception_state': ( is_setter_raises_exception or has_strict_type_checking or idl_type.is_integer_type), 'is_static': attribute.is_static, 'is_url': 'URL' in extended_attributes, 'is_unforgeable': 'Unforgeable' in extended_attributes, 'measure_as': v8_utilities.measure_as(attribute), # [MeasureAs] 'name': attribute.name, 'per_context_enabled_function': v8_utilities.per_context_enabled_function_name(attribute), # [PerContextEnabled] 'property_attributes': property_attributes(attribute), 'put_forwards': 'PutForwards' in extended_attributes, 'reflect_empty': extended_attributes.get('ReflectEmpty'), 'reflect_invalid': extended_attributes.get('ReflectInvalid', ''), 'reflect_missing': extended_attributes.get('ReflectMissing'), 'reflect_only': extended_attributes['ReflectOnly'].split('|') if 'ReflectOnly' in extended_attributes else None, 'setter_callback': setter_callback_name(interface, attribute), 'v8_type': v8_types.v8_type(base_idl_type), 'runtime_enabled_function': v8_utilities.runtime_enabled_function_name(attribute), # [RuntimeEnabled] 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended_attributes else [''], # [PerWorldBindings] } if is_constructor_attribute(attribute): generate_constructor_getter(interface, attribute, contents) return contents if not has_custom_getter: generate_getter(interface, attribute, contents) if (not has_custom_setter and (not attribute.is_read_only or 'PutForwards' in extended_attributes)): generate_setter(interface, attribute, contents) return contents
def generate_interface(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 is_audio_buffer = inherits_interface(interface.name, "AudioBuffer") if is_audio_buffer: includes.add("modules/webaudio/AudioBuffer.h") is_document = inherits_interface(interface.name, "Document") if is_document: includes.update(["bindings/v8/ScriptController.h", "bindings/v8/V8WindowShell.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/v8/BindingSecurity.h") # [DependentLifetime] is_dependent_lifetime = "DependentLifetime" in extended_attributes # [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/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(used_as_argument=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() # [SpecialWrapFor] if "SpecialWrapFor" in extended_attributes: special_wrap_for = extended_attributes["SpecialWrapFor"].split("|") 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 ) this_gc_type = gc_type(interface) template_contents = { "conditional_string": conditional_string(interface), # [Conditional] "cpp_class": cpp_name(interface), "gc_type": this_gc_type, "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_audio_buffer": is_audio_buffer, "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"), "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, "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", } # Constructors constructors = [ generate_constructor(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: template_contents["constructor_overloads"] = generate_overloads(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/v8/Dictionary.h") if any_type_attributes: includes.add("bindings/v8/SerializedScriptValue.h") # [NamedConstructor] named_constructor = generate_named_constructor(interface) if constructors or custom_constructors or has_event_constructor or named_constructor: includes.add("bindings/v8/V8ObjectConstructor.h") includes.add("core/frame/DOMWindow.h") template_contents.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_call_with_document": has_extended_attribute_value( interface, "ConstructorCallWith", "Document" ), # [ConstructorCallWith=Document] "is_constructor_call_with_execution_context": has_extended_attribute_value( interface, "ConstructorCallWith", "ExecutionContext" ), # [ConstructorCallWith=ExeuctionContext] "is_constructor_raises_exception": extended_attributes.get("RaisesException") == "Constructor", # [RaisesException=Constructor] "named_constructor": named_constructor, } ) # Constants template_contents.update( { "constants": [generate_constant(constant) for constant in interface.constants], "do_not_check_constants": "DoNotCheckConstants" in extended_attributes, } ) # Attributes attributes = [v8_attributes.generate_attribute(interface, attribute) for attribute in interface.attributes] template_contents.update( { "attributes": attributes, "has_accessors": any(attribute["is_expose_js_accessors"] 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"] ) for attribute in attributes ), "has_constructor_attributes": any(attribute["constructor_type"] for attribute in attributes), "has_per_context_enabled_attributes": any( attribute["per_context_enabled_function"] for attribute in attributes ), "has_replaceable_attributes": any(attribute["is_replaceable"] for attribute in attributes), } ) # Methods methods = [ v8_methods.generate_method(interface, method) for method in interface.operations if method.name ] # Skip anonymous special operations (methods) generate_method_overloads(methods) for method in methods: method["do_generate_method_configuration"] = ( method["do_not_check_signature"] and not method["per_context_enabled_function"] and # For overloaded methods, only generate one accessor ("overload_index" not in method or method["overload_index"] == 1) ) template_contents.update( { "has_origin_safe_method_setter": any( method["is_check_security_for_frame"] and not method["is_read_only"] for method in methods ), "has_method_configuration": any(method["do_generate_method_configuration"] for method in methods), "has_per_context_enabled_methods": any(method["per_context_enabled_function"] for method in methods), "methods": methods, } ) template_contents.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 template_contents
def generate_attribute(interface, attribute): idl_type = attribute.idl_type extended_attributes = attribute.extended_attributes has_custom_getter = has_extended_attribute(attribute, ('Custom', 'CustomGetter')) has_custom_setter = not attribute.is_read_only and has_extended_attribute( attribute, ('Custom', 'CustomSetter')) contents = { 'access_control_list': access_control_list(attribute), 'activity_logging_world_list_for_getter': v8_utilities.activity_logging_world_list( attribute, 'Getter'), # [ActivityLogging] 'activity_logging_world_list_for_setter': v8_utilities.activity_logging_world_list( attribute, 'Setter'), # [ActivityLogging] 'cached_attribute_validation_method': extended_attributes.get('CachedAttribute'), 'conditional_string': v8_utilities.generate_conditional_string(attribute), 'cpp_type': v8_types.cpp_type(idl_type), 'getter_callback_name': getter_callback_name(interface, attribute), 'getter_callback_name_for_main_world': getter_callback_name_for_main_world(interface, attribute), 'has_custom_getter': has_custom_getter, 'has_custom_setter': has_custom_setter, 'idl_type': idl_type, 'is_constructor': is_constructor_attribute(attribute), 'is_getter_raises_exception': has_extended_attribute(attribute, ('GetterRaisesException', 'RaisesException')), 'is_keep_alive_for_gc': is_keep_alive_for_gc(attribute), 'is_nullable': attribute.is_nullable, 'is_read_only': attribute.is_read_only, 'is_replaceable': 'Replaceable' in attribute.extended_attributes, 'is_setter_raises_exception': has_extended_attribute(attribute, ('RaisesException', 'SetterRaisesException')), 'is_static': attribute.is_static, 'name': attribute.name, 'per_context_enabled_function_name': v8_utilities.per_context_enabled_function_name( attribute), # [PerContextEnabled] 'property_attributes': property_attributes(attribute), 'setter_callback_name': setter_callback_name(interface, attribute), 'setter_callback_name_for_main_world': setter_callback_name_for_main_world(interface, attribute), 'v8_type': v8_types.v8_type(idl_type), 'runtime_enabled_function_name': v8_utilities.runtime_enabled_function_name( attribute), # [RuntimeEnabled] 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended_attributes else [''], # [PerWorldBindings] 'wrapper_type_info': wrapper_type_info(attribute), } if is_constructor_attribute(attribute): includes.update(v8_types.includes_for_type(idl_type)) return contents if not has_custom_getter: generate_getter(interface, attribute, contents) if not attribute.is_read_only and not has_custom_setter: generate_setter(interface, attribute, contents) return contents