def generate_constructor(interface, constructor): return { 'argument_list': constructor_argument_list(interface, constructor), 'arguments': [ v8_methods.generate_argument(interface, constructor, argument, index) for index, argument in enumerate(constructor.arguments) ], 'cpp_type': cpp_template_type(cpp_ptr_type('RefPtr', 'RawPtr', gc_type(interface)), cpp_name(interface)), 'has_exception_state': # [RaisesException=Constructor] interface.extended_attributes.get('RaisesException') == 'Constructor' or any(argument for argument in constructor.arguments if argument.idl_type.name == 'SerializedScriptValue' or argument.idl_type.is_integer_type), 'is_constructor': True, 'is_named_constructor': False, 'number_of_required_arguments': number_of_required_arguments(constructor), }
def generate_argument(interface, method, argument, index): extended_attributes = argument.extended_attributes idl_type = argument.idl_type this_cpp_value = cpp_value(interface, method, index) is_variadic_wrapper_type = argument.is_variadic and idl_type.is_wrapper_type return { 'cpp_type': idl_type.cpp_type_args(used_in_cpp_sequence=is_variadic_wrapper_type), 'cpp_value': this_cpp_value, 'enum_validation_expression': idl_type.enum_validation_expression, 'has_default': 'Default' in extended_attributes, 'has_event_listener_argument': any( argument_so_far for argument_so_far in method.arguments[:index] if argument_so_far.idl_type.name == 'EventListener'), # Dictionary is special-cased, but arrays and sequences shouldn't be 'idl_type': not idl_type.array_or_sequence_type and idl_type.base_type, 'idl_type_object': idl_type, 'index': index, 'is_clamp': 'Clamp' in extended_attributes, 'is_callback_interface': idl_type.is_callback_interface, 'is_nullable': idl_type.is_nullable, 'is_optional': argument.is_optional, 'is_strict_type_checking': 'StrictTypeChecking' in extended_attributes, 'is_variadic_wrapper_type': is_variadic_wrapper_type, 'vector_type': v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc_type), 'is_wrapper_type': idl_type.is_wrapper_type, 'name': argument.name, 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name, method, this_cpp_value, for_main_world=True), 'v8_set_return_value': v8_set_return_value(interface.name, method, this_cpp_value), 'v8_value_to_local_cpp_value': v8_value_to_local_cpp_value(argument, index), 'v8_value_to_local_cpp_value_async': v8_value_to_local_cpp_value(argument, index, async=True), }
def constructor_context(interface, constructor): # [RaisesException=Constructor] is_constructor_raises_exception = \ interface.extended_attributes.get('RaisesException') == 'Constructor' return { 'arguments': [v8_methods.argument_context(interface, constructor, argument, index) for index, argument in enumerate(constructor.arguments)], 'cpp_type': cpp_template_type( cpp_ptr_type('RefPtr', 'RawPtr', gc_type(interface)), cpp_name(interface)), 'cpp_value': v8_methods.cpp_value( interface, constructor, len(constructor.arguments)), 'has_exception_state': is_constructor_raises_exception or any(argument for argument in constructor.arguments if argument.idl_type.name == 'SerializedScriptValue' or argument.idl_type.v8_conversion_needs_exception_state), 'is_call_with_document': # [ConstructorCallWith=Document] has_extended_attribute_value(interface, 'ConstructorCallWith', 'Document'), 'is_call_with_execution_context': # [ConstructorCallWith=ExecutionContext] has_extended_attribute_value(interface, 'ConstructorCallWith', 'ExecutionContext'), 'is_constructor': True, 'is_named_constructor': False, 'is_raises_exception': is_constructor_raises_exception, 'number_of_required_arguments': number_of_required_arguments(constructor), }
def generate_argument(interface, method, argument, index): extended_attributes = argument.extended_attributes idl_type = argument.idl_type this_cpp_value = cpp_value(interface, method, index) is_variadic_wrapper_type = argument.is_variadic and idl_type.is_wrapper_type return { 'cpp_type': idl_type.cpp_type_args(used_in_cpp_sequence=is_variadic_wrapper_type), 'cpp_value': this_cpp_value, 'enum_validation_expression': idl_type.enum_validation_expression, 'has_default': 'Default' in extended_attributes, 'has_event_listener_argument': any(argument_so_far for argument_so_far in method.arguments[:index] if argument_so_far.idl_type.name == 'EventListener'), 'has_type_checking_interface': (has_extended_attribute_value(interface, 'TypeChecking', 'Interface') or has_extended_attribute_value(method, 'TypeChecking', 'Interface')) and idl_type.is_wrapper_type, 'has_type_checking_unrestricted': (has_extended_attribute_value(interface, 'TypeChecking', 'Unrestricted') or has_extended_attribute_value(method, 'TypeChecking', 'Unrestricted')) and idl_type.name in ('Float', 'Double'), # Dictionary is special-cased, but arrays and sequences shouldn't be 'idl_type': not idl_type.array_or_sequence_type and idl_type.base_type, 'idl_type_object': idl_type, 'index': index, 'is_clamp': 'Clamp' in extended_attributes, 'is_callback_interface': idl_type.is_callback_interface, 'is_nullable': idl_type.is_nullable, 'is_optional': argument.is_optional, 'is_variadic_wrapper_type': is_variadic_wrapper_type, 'vector_type': v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc_type), 'is_wrapper_type': idl_type.is_wrapper_type, 'name': argument.name, 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name, method, this_cpp_value, for_main_world=True), 'v8_set_return_value': v8_set_return_value(interface.name, method, this_cpp_value), 'v8_value_to_local_cpp_value': v8_value_to_local_cpp_value(argument, index), }
def argument_context(interface, method, argument, index): extended_attributes = argument.extended_attributes idl_type = argument.idl_type this_cpp_value = cpp_value(interface, method, index) is_variadic_wrapper_type = argument.is_variadic and idl_type.is_wrapper_type type_checking_interface = ( (has_extended_attribute_value(interface, 'TypeChecking', 'Interface') or has_extended_attribute_value(method, 'TypeChecking', 'Interface')) and idl_type.is_wrapper_type) type_checked = (type_checking_interface and # These allow null and undefined values, so a type-check is still required. not idl_type.is_nullable and not (argument.is_optional and 'Default' in extended_attributes)) if ('ImplementedInPrivateScript' in extended_attributes and not idl_type.is_wrapper_type and not idl_type.is_basic_type): raise Exception('Private scripts supports only primitive types and DOM wrappers.') default_cpp_value = argument.default_cpp_value return { 'cpp_type': idl_type.cpp_type_args(extended_attributes=extended_attributes, raw_type=True, used_as_variadic_argument=argument.is_variadic), 'cpp_value': this_cpp_value, # FIXME: check that the default value's type is compatible with the argument's 'default_value': default_cpp_value, 'enum_validation_expression': idl_type.enum_validation_expression, 'handle': '%sHandle' % argument.name, # FIXME: remove once [Default] removed and just use argument.default_value 'has_default': 'Default' in extended_attributes or default_cpp_value, 'has_type_checking_interface': type_checking_interface, 'has_type_checking_unrestricted': (has_extended_attribute_value(interface, 'TypeChecking', 'Unrestricted') or has_extended_attribute_value(method, 'TypeChecking', 'Unrestricted')) and idl_type.name in ('Float', 'Double'), # Dictionary is special-cased, but arrays and sequences shouldn't be 'idl_type': idl_type.base_type, 'idl_type_object': idl_type, 'index': index, 'is_callback_interface': idl_type.is_callback_interface, # FIXME: Remove generic 'Dictionary' special-casing 'is_dictionary': idl_type.is_dictionary or idl_type.base_type == 'Dictionary', 'is_nullable': idl_type.is_nullable, 'is_optional': argument.is_optional, 'is_variadic_wrapper_type': is_variadic_wrapper_type, 'is_wrapper_type': idl_type.is_wrapper_type, 'name': argument.name, 'private_script_cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( argument.name, isolate='scriptState->isolate()', creation_context='scriptState->context()->Global()'), 'v8_set_return_value': v8_set_return_value(interface.name, method, this_cpp_value), 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name, method, this_cpp_value, for_main_world=True), 'v8_value_to_local_cpp_value': v8_value_to_local_cpp_value(argument, index, type_checked, return_promise=method.returns_promise), 'vector_type': v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc_type), }
def argument_context(interface, method, argument, index): extended_attributes = argument.extended_attributes idl_type = argument.idl_type this_cpp_value = cpp_value(interface, method, index) is_variadic_wrapper_type = argument.is_variadic and idl_type.is_wrapper_type if ( "ImplementedInPrivateScript" in extended_attributes and not idl_type.is_wrapper_type and not idl_type.is_basic_type ): raise Exception("Private scripts supports only primitive types and DOM wrappers.") default_cpp_value = argument.default_cpp_value return { "cpp_type": idl_type.cpp_type_args( extended_attributes=extended_attributes, raw_type=True, used_as_variadic_argument=argument.is_variadic ), "cpp_value": this_cpp_value, # FIXME: check that the default value's type is compatible with the argument's "default_value": default_cpp_value, "enum_validation_expression": idl_type.enum_validation_expression, "handle": "%sHandle" % argument.name, # FIXME: remove once [Default] removed and just use argument.default_value "has_default": "Default" in extended_attributes or default_cpp_value, "has_type_checking_interface": ( has_extended_attribute_value(interface, "TypeChecking", "Interface") or has_extended_attribute_value(method, "TypeChecking", "Interface") ) and idl_type.is_wrapper_type, "has_type_checking_unrestricted": ( has_extended_attribute_value(interface, "TypeChecking", "Unrestricted") or has_extended_attribute_value(method, "TypeChecking", "Unrestricted") ) and idl_type.name in ("Float", "Double"), # Dictionary is special-cased, but arrays and sequences shouldn't be "idl_type": idl_type.base_type, "idl_type_object": idl_type, "index": index, "is_callback_interface": idl_type.is_callback_interface, # FIXME: Remove generic 'Dictionary' special-casing "is_dictionary": idl_type.is_dictionary or idl_type.base_type == "Dictionary", "is_nullable": idl_type.is_nullable, "is_optional": argument.is_optional, "is_variadic_wrapper_type": is_variadic_wrapper_type, "is_wrapper_type": idl_type.is_wrapper_type, "name": argument.name, "private_script_cpp_value_to_v8_value": idl_type.cpp_value_to_v8_value( argument.name, isolate="scriptState->isolate()", creation_context="scriptState->context()->Global()" ), "v8_set_return_value": v8_set_return_value(interface.name, method, this_cpp_value), "v8_set_return_value_for_main_world": v8_set_return_value( interface.name, method, this_cpp_value, for_main_world=True ), "v8_value_to_local_cpp_value": v8_value_to_local_cpp_value( argument, index, return_promise=method.returns_promise ), "vector_type": v8_types.cpp_ptr_type("Vector", "HeapVector", idl_type.gc_type), }
def argument_context(interface, method, argument, index): extended_attributes = argument.extended_attributes idl_type = argument.idl_type this_cpp_value = cpp_value(interface, method, index) is_variadic_wrapper_type = argument.is_variadic and idl_type.is_wrapper_type # [TypeChecking=Interface] / [LegacyInterfaceTypeChecking] has_type_checking_interface = ( not is_legacy_interface_type_checking(interface, method) and idl_type.is_wrapper_type) if ('ImplementedInPrivateScript' in extended_attributes and not idl_type.is_wrapper_type and not idl_type.is_basic_type): raise Exception('Private scripts supports only primitive types and DOM wrappers.') set_default_value = argument.set_default_value this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attributes, raw_type=True, used_as_variadic_argument=argument.is_variadic) return { 'cpp_type': ( v8_types.cpp_template_type('Nullable', this_cpp_type) if idl_type.is_explicit_nullable and not argument.is_variadic else this_cpp_type), 'cpp_value': this_cpp_value, # FIXME: check that the default value's type is compatible with the argument's 'set_default_value': set_default_value, 'enum_type': idl_type.enum_type, 'enum_values': idl_type.enum_values, 'handle': '%sHandle' % argument.name, # FIXME: remove once [Default] removed and just use argument.default_value 'has_default': 'Default' in extended_attributes or set_default_value, 'has_type_checking_interface': has_type_checking_interface, # Dictionary is special-cased, but arrays and sequences shouldn't be 'idl_type': idl_type.base_type, 'idl_type_object': idl_type, 'index': index, 'is_callback_function': idl_type.is_callback_function, 'is_callback_interface': idl_type.is_callback_interface, # FIXME: Remove generic 'Dictionary' special-casing 'is_dictionary': idl_type.is_dictionary or idl_type.base_type == 'Dictionary', 'is_explicit_nullable': idl_type.is_explicit_nullable, 'is_nullable': idl_type.is_nullable, 'is_optional': argument.is_optional, 'is_variadic': argument.is_variadic, 'is_variadic_wrapper_type': is_variadic_wrapper_type, 'is_wrapper_type': idl_type.is_wrapper_type, 'name': argument.name, 'private_script_cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( argument.name, isolate='scriptState->isolate()', creation_context='scriptState->context()->Global()'), 'use_permissive_dictionary_conversion': 'PermissiveDictionaryConversion' in extended_attributes, 'v8_set_return_value': v8_set_return_value(interface.name, method, this_cpp_value), 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name, method, this_cpp_value, for_main_world=True), 'v8_value_to_local_cpp_value': v8_value_to_local_cpp_value(method, argument, index), 'vector_type': v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc_type), }
def argument_context(interface, method, argument, index): extended_attributes = argument.extended_attributes idl_type = argument.idl_type this_cpp_value = cpp_value(interface, method, index) is_variadic_wrapper_type = argument.is_variadic and idl_type.is_wrapper_type if ('ImplementedInPrivateScript' in extended_attributes and not idl_type.is_wrapper_type and not idl_type.is_basic_type): raise Exception('Private scripts supports only primitive types and DOM wrappers.') default_cpp_value = argument.default_cpp_value return { 'cpp_type': idl_type.cpp_type_args(extended_attributes=extended_attributes, raw_type=True, used_as_variadic_argument=argument.is_variadic), 'cpp_value': this_cpp_value, # FIXME: check that the default value's type is compatible with the argument's 'default_value': default_cpp_value, 'enum_validation_expression': idl_type.enum_validation_expression, 'handle': '%sHandle' % argument.name, # FIXME: remove once [Default] removed and just use argument.default_value 'has_default': 'Default' in extended_attributes or default_cpp_value, 'has_type_checking_interface': (has_extended_attribute_value(interface, 'TypeChecking', 'Interface') or has_extended_attribute_value(method, 'TypeChecking', 'Interface')) and idl_type.is_wrapper_type, 'has_type_checking_unrestricted': (has_extended_attribute_value(interface, 'TypeChecking', 'Unrestricted') or has_extended_attribute_value(method, 'TypeChecking', 'Unrestricted')) and idl_type.name in ('Float', 'Double'), # Dictionary is special-cased, but arrays and sequences shouldn't be 'idl_type': idl_type.base_type, 'idl_type_object': idl_type, 'index': index, 'is_callback_interface': idl_type.is_callback_interface, # FIXME: Remove generic 'Dictionary' special-casing 'is_dictionary': idl_type.is_dictionary or idl_type.base_type == 'Dictionary', 'is_nullable': idl_type.is_nullable, 'is_optional': argument.is_optional, 'is_variadic_wrapper_type': is_variadic_wrapper_type, 'is_wrapper_type': idl_type.is_wrapper_type, 'name': argument.name, 'private_script_cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( argument.name, isolate='scriptState->isolate()', creation_context='scriptState->context()->Global()'), 'v8_set_return_value': v8_set_return_value(interface.name, method, this_cpp_value), 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name, method, this_cpp_value, for_main_world=True), 'v8_value_to_local_cpp_value': v8_value_to_local_cpp_value(argument, index, return_promise=method.returns_promise), 'vector_type': v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc_type), }
def v8_value_to_local_cpp_variadic_value(argument, index, async): assert argument.is_variadic idl_type = argument.idl_type vector_type = v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc_type) macro = 'TONATIVE_VOID' + ('_ASYNC' if async else '') macro_args = [ '%s<%s>' % (vector_type, idl_type.cpp_type), argument.name, 'toNativeArguments<%s>(info, %s)' % (idl_type.cpp_type, index), ] if async: macro_args.append('info') return '%s(%s)' % (macro, ', '.join(macro_args))
def v8_value_to_local_cpp_value(argument, index): extended_attributes = argument.extended_attributes idl_type = argument.idl_type name = argument.name if argument.is_variadic: vector_type = v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc_type) return 'TONATIVE_VOID({vector_type}<{cpp_type}>, {name}, toNativeArguments<{cpp_type}>(info, {index}))'.format( vector_type=vector_type, cpp_type=idl_type.cpp_type, name=name, index=index) # [Default=NullString] if (argument.is_optional and idl_type.name == 'String' and extended_attributes.get('Default') == 'NullString'): v8_value = 'argumentOrNull(info, %s)' % index else: v8_value = 'info[%s]' % index return idl_type.v8_value_to_local_cpp_value(extended_attributes, v8_value, name, index=index)
def constructor_context(interface, constructor): arguments_need_try_catch = any( v8_methods.argument_needs_try_catch(constructor, argument) for argument in constructor.arguments) # [RaisesException=Constructor] is_constructor_raises_exception = \ interface.extended_attributes.get('RaisesException') == 'Constructor' return { 'arguments': [ v8_methods.argument_context(interface, constructor, argument, index) for index, argument in enumerate(constructor.arguments) ], 'arguments_need_try_catch': arguments_need_try_catch, 'cpp_type': cpp_template_type(cpp_ptr_type('RefPtr', 'RawPtr', gc_type(interface)), cpp_name(interface)), 'cpp_value': v8_methods.cpp_value(interface, constructor, len(constructor.arguments)), 'has_exception_state': is_constructor_raises_exception or any(argument for argument in constructor.arguments if argument.idl_type.name == 'SerializedScriptValue' or argument.idl_type.may_raise_exception_on_conversion), 'is_call_with_document': # [ConstructorCallWith=Document] has_extended_attribute_value(interface, 'ConstructorCallWith', 'Document'), 'is_call_with_execution_context': # [ConstructorCallWith=ExecutionContext] has_extended_attribute_value(interface, 'ConstructorCallWith', 'ExecutionContext'), 'is_constructor': True, 'is_named_constructor': False, 'is_raises_exception': is_constructor_raises_exception, 'number_of_required_arguments': number_of_required_arguments(constructor), }
def generate_argument(interface, method, argument, index): extended_attributes = argument.extended_attributes idl_type = argument.idl_type this_cpp_value = cpp_value(interface, method, index) is_variadic_wrapper_type = argument.is_variadic and idl_type.is_wrapper_type return { 'cpp_type': idl_type.cpp_type_args(extended_attributes=extended_attributes, used_as_argument=True, used_as_variadic_argument=argument.is_variadic), 'cpp_value': this_cpp_value, # FIXME: check that the default value's type is compatible with the argument's 'default_value': str(argument.default_value) if argument.default_value else None, 'enum_validation_expression': idl_type.enum_validation_expression, # FIXME: remove once [Default] removed and just use argument.default_value 'has_default': 'Default' in extended_attributes or argument.default_value, 'has_event_listener_argument': any( argument_so_far for argument_so_far in method.arguments[:index] if argument_so_far.idl_type.name == 'EventListener'), 'has_type_checking_interface': (has_extended_attribute_value(interface, 'TypeChecking', 'Interface') or has_extended_attribute_value(method, 'TypeChecking', 'Interface')) and idl_type.is_wrapper_type, 'has_type_checking_unrestricted': (has_extended_attribute_value(interface, 'TypeChecking', 'Unrestricted') or has_extended_attribute_value(method, 'TypeChecking', 'Unrestricted')) and idl_type.name in ('Float', 'Double'), # Dictionary is special-cased, but arrays and sequences shouldn't be 'idl_type': not idl_type.array_or_sequence_type and idl_type.base_type, 'idl_type_object': idl_type, 'index': index, 'is_clamp': 'Clamp' in extended_attributes, 'is_callback_interface': idl_type.is_callback_interface, 'is_nullable': idl_type.is_nullable, 'is_optional': argument.is_optional, 'is_variadic_wrapper_type': is_variadic_wrapper_type, 'vector_type': v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc_type), 'is_wrapper_type': idl_type.is_wrapper_type, 'name': argument.name, 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name, method, this_cpp_value, for_main_world=True), 'v8_set_return_value': v8_set_return_value(interface.name, method, this_cpp_value), 'v8_value_to_local_cpp_value': v8_value_to_local_cpp_value(argument, index), }
def generate_constructor(interface, constructor): return { 'argument_list': constructor_argument_list(interface, constructor), 'arguments': [v8_methods.generate_argument(interface, constructor, argument, index) for index, argument in enumerate(constructor.arguments)], 'cpp_type': cpp_template_type( cpp_ptr_type('RefPtr', 'RawPtr', gc_type(interface)), cpp_name(interface)), 'has_exception_state': # [RaisesException=Constructor] interface.extended_attributes.get('RaisesException') == 'Constructor' or any(argument for argument in constructor.arguments if argument.idl_type.name == 'SerializedScriptValue' or argument.idl_type.is_integer_type), 'is_constructor': True, 'is_named_constructor': False, 'is_variadic': False, # Required for overload resolution 'number_of_required_arguments': number_of_required_arguments(constructor), }
def generate_constructor(interface, constructor): return { "argument_list": constructor_argument_list(interface, constructor), "arguments": [ v8_methods.generate_argument(interface, constructor, argument, index) for index, argument in enumerate(constructor.arguments) ], "cpp_type": cpp_template_type(cpp_ptr_type("RefPtr", "RawPtr", gc_type(interface)), cpp_name(interface)), "has_exception_state": # [RaisesException=Constructor] interface.extended_attributes.get("RaisesException") == "Constructor" or any( argument for argument in constructor.arguments if argument.idl_type.name == "SerializedScriptValue" or argument.idl_type.is_integer_type ), "is_constructor": True, "is_named_constructor": False, "is_variadic": False, # Required for overload resolution "number_of_required_arguments": number_of_required_arguments(constructor), }
def generate_constructor(interface, constructor): arguments_need_try_catch = any(v8_methods.argument_needs_try_catch(argument) for argument in constructor.arguments) return { 'arguments': [v8_methods.generate_argument(interface, constructor, argument, index) for index, argument in enumerate(constructor.arguments)], 'arguments_need_try_catch': arguments_need_try_catch, 'cpp_type': cpp_template_type( cpp_ptr_type('RefPtr', 'RawPtr', gc_type(interface)), cpp_name(interface)), 'cpp_value': v8_methods.cpp_value( interface, constructor, len(constructor.arguments)), 'has_exception_state': # [RaisesException=Constructor] interface.extended_attributes.get('RaisesException') == 'Constructor' or any(argument for argument in constructor.arguments if argument.idl_type.name == 'SerializedScriptValue' or argument.idl_type.is_integer_type), 'is_constructor': True, 'is_named_constructor': False, 'number_of_required_arguments': number_of_required_arguments(constructor), }
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 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 # [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_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_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)) # 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']) 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