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 property_getter(getter, cpp_arguments): def is_null_expression(idl_type): if idl_type.is_union_type: notnull = ' || '.join([ member_argument['null_check_value'] for member_argument in idl_type.union_arguments ]) return '!(%s)' % notnull if idl_type.name == 'String': return 'result.isNull()' if idl_type.is_interface_type: return '!result' return '' idl_type = getter.idl_type extended_attributes = getter.extended_attributes is_raises_exception = 'RaisesException' in extended_attributes # FIXME: make more generic, so can use v8_methods.cpp_value cpp_method_name = 'impl->%s' % cpp_name(getter) if is_raises_exception: cpp_arguments.append('exceptionState') union_arguments = idl_type.union_arguments if union_arguments: cpp_arguments.extend([ member_argument['cpp_value'] for member_argument in union_arguments ]) cpp_value = '%s(%s)' % (cpp_method_name, ', '.join(cpp_arguments)) return { 'cpp_type': idl_type.cpp_type, 'cpp_value': cpp_value, 'is_custom': 'Custom' in extended_attributes and (not extended_attributes['Custom'] or has_extended_attribute_value(getter, 'Custom', 'PropertyGetter')), 'is_custom_property_enumerator': has_extended_attribute_value(getter, 'Custom', 'PropertyEnumerator'), 'is_custom_property_query': has_extended_attribute_value(getter, 'Custom', 'PropertyQuery'), 'is_enumerable': 'NotEnumerable' not in extended_attributes, 'is_null_expression': is_null_expression(idl_type), 'is_raises_exception': is_raises_exception, 'name': cpp_name(getter), 'union_arguments': union_arguments, 'v8_set_return_value': idl_type.v8_set_return_value('result', extended_attributes=extended_attributes, script_wrappable='impl', release=idl_type.release), }
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 setter_context(interface, attribute, interfaces, context): if 'PutForwards' in attribute.extended_attributes: # Make sure the target interface and attribute exist. target_interface_name = attribute.idl_type.base_type target_attribute_name = attribute.extended_attributes['PutForwards'] interface = interfaces[target_interface_name] try: next(candidate for candidate in interface.attributes if candidate.name == target_attribute_name) except StopIteration: raise Exception('[PutForward] target not found:\n' 'Attribute "%s" is not present in interface "%s"' % (target_attribute_name, target_interface_name)) context['target_attribute_name'] = target_attribute_name return if ('Replaceable' in attribute.extended_attributes): # Create the property, and early-return if an exception is thrown. # Subsequent cleanup code may not be prepared to handle a pending # exception. context['cpp_setter'] = ( 'if (info.Holder()->CreateDataProperty(' + 'info.GetIsolate()->GetCurrentContext(), property_name, v8_value).IsNothing())' + '\n return') return extended_attributes = attribute.extended_attributes idl_type = attribute.idl_type # [RaisesException], [RaisesException=Setter] is_setter_raises_exception = ('RaisesException' in extended_attributes and extended_attributes['RaisesException'] in [None, 'Setter']) # [LegacyInterfaceTypeChecking] has_type_checking_interface = ( not is_legacy_interface_type_checking(interface, attribute) and idl_type.is_wrapper_type) context.update({ 'has_setter_exception_state': is_setter_raises_exception or has_type_checking_interface or idl_type.v8_conversion_needs_exception_state, 'has_type_checking_interface': has_type_checking_interface, 'is_setter_call_with_execution_context': has_extended_attribute_value(attribute, 'SetterCallWith', 'ExecutionContext'), 'is_setter_call_with_script_state': has_extended_attribute_value(attribute, 'SetterCallWith', 'ScriptState'), 'is_setter_raises_exception': is_setter_raises_exception, 'v8_value_to_local_cpp_value': idl_type.v8_value_to_local_cpp_value(extended_attributes, 'v8_value', 'cpp_value'), }) # setter_expression() depends on context values we set above. context['cpp_setter'] = setter_expression(interface, attribute, context)
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 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() # [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')) context = { 'argument_cpp_type': idl_type.cpp_type_args(used_as_rvalue_type=True), 'cached_attribute_validation_method': extended_attributes.get('CachedAttribute'), '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_type_initializer': idl_type.cpp_type_initializer, 'enum_validation_expression': idl_type.enum_validation_expression, 'exposed_test': v8_utilities.exposed(attribute, interface), # [Exposed] 'has_custom_getter': has_custom_getter(attribute), 'has_custom_setter': has_custom_setter(attribute), '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_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': idl_type.is_nullable, 'is_explicit_nullable': idl_type.is_explicit_nullable, 'is_partial_interface_member': 'PartialInterfaceImplementedAs' in extended_attributes, 'is_read_only': attribute.is_read_only, 'is_replaceable': 'Replaceable' in attribute.extended_attributes, 'is_static': attribute.is_static, 'is_url': 'URL' in extended_attributes, 'name': attribute.name, 'put_forwards': 'PutForwards' in extended_attributes, 'setter_callback': setter_callback_name(interface, attribute), } if is_constructor_attribute(attribute): constructor_getter_context(interface, attribute, context) return context if not has_custom_getter(attribute): getter_context(interface, attribute, context) if (not has_custom_setter(attribute) and (not attribute.is_read_only or 'PutForwards' in extended_attributes)): setter_context(interface, attribute, context) return context
def setter_context(interface, attribute, context): if "PutForwards" in attribute.extended_attributes: # Use target interface and attribute in place of original interface and # attribute from this point onwards. target_interface_name = attribute.idl_type.base_type target_attribute_name = attribute.extended_attributes["PutForwards"] interface = interfaces[target_interface_name] try: attribute = next(candidate for candidate in interface.attributes if candidate.name == target_attribute_name) except StopIteration: raise Exception( "[PutForward] target not found:\n" 'Attribute "%s" is not present in interface "%s"' % (target_attribute_name, target_interface_name) ) extended_attributes = attribute.extended_attributes idl_type = attribute.idl_type # [RaisesException], [RaisesException=Setter] is_setter_raises_exception = "RaisesException" in extended_attributes and extended_attributes[ "RaisesException" ] in [None, "Setter"] # [TypeChecking=Interface] 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 type_checked = ( has_type_checking_interface and # These allow null values, so a type-check is still required. not idl_type.is_nullable ) context.update( { "has_setter_exception_state": is_setter_raises_exception or has_type_checking_interface or context["has_type_checking_unrestricted"] or idl_type.v8_conversion_needs_exception_state, "has_type_checking_interface": has_type_checking_interface, "is_setter_call_with_execution_context": v8_utilities.has_extended_attribute_value( attribute, "SetterCallWith", "ExecutionContext" ), "is_setter_raises_exception": is_setter_raises_exception, "private_script_cpp_value_to_v8_value": idl_type.cpp_value_to_v8_value( "cppValue", isolate="scriptState->isolate()", creation_context="scriptState->context()->Global()" ), "v8_value_to_local_cpp_value": idl_type.v8_value_to_local_cpp_value( extended_attributes, "v8Value", "cppValue", needs_type_check=not type_checked ), } ) # setter_expression() depends on context values we set above. context["cpp_setter"] = setter_expression(interface, attribute, context)
def setter_context(interface, attribute, context): if 'PutForwards' in attribute.extended_attributes: # Use target interface and attribute in place of original interface and # attribute from this point onwards. target_interface_name = attribute.idl_type.base_type target_attribute_name = attribute.extended_attributes['PutForwards'] interface = interfaces[target_interface_name] try: attribute = next(candidate for candidate in interface.attributes if candidate.name == target_attribute_name) except StopIteration: raise Exception('[PutForward] target not found:\n' 'Attribute "%s" is not present in interface "%s"' % (target_attribute_name, target_interface_name)) extended_attributes = attribute.extended_attributes idl_type = attribute.idl_type # [RaisesException], [RaisesException=Setter] is_setter_raises_exception = ('RaisesException' in extended_attributes and extended_attributes['RaisesException'] in [None, 'Setter']) # [TypeChecking=Interface] 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) context.update({ 'has_setter_exception_state': is_setter_raises_exception or has_type_checking_interface or context['has_type_checking_unrestricted'] or idl_type.may_raise_exception_on_conversion, 'has_type_checking_interface': has_type_checking_interface, 'is_setter_call_with_execution_context': v8_utilities.has_extended_attribute_value(attribute, 'SetterCallWith', 'ExecutionContext'), 'is_setter_raises_exception': is_setter_raises_exception, 'private_script_cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( 'cppValue', isolate='scriptState->isolate()', creation_context='scriptState->context()->Global()'), 'v8_value_to_local_cpp_value': idl_type.v8_value_to_local_cpp_value(extended_attributes, 'v8Value', 'cppValue'), }) # setter_expression() depends on context values we set above. context['cpp_setter'] = setter_expression(interface, attribute, context)
def setter_context(interface, attribute, context): if 'PutForwards' in attribute.extended_attributes: # Use target interface and attribute in place of original interface and # attribute from this point onwards. target_interface_name = attribute.idl_type.base_type target_attribute_name = attribute.extended_attributes['PutForwards'] interface = interfaces[target_interface_name] try: attribute = next(candidate for candidate in interface.attributes if candidate.name == target_attribute_name) except StopIteration: raise Exception('[PutForward] target not found:\n' 'Attribute "%s" is not present in interface "%s"' % (target_attribute_name, target_interface_name)) extended_attributes = attribute.extended_attributes idl_type = attribute.idl_type # [RaisesException], [RaisesException=Setter] is_setter_raises_exception = ( 'RaisesException' in extended_attributes and extended_attributes['RaisesException'] in [None, 'Setter']) # [TypeChecking=Interface] 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) type_checked = (has_type_checking_interface and # These allow null values, so a type-check is still required. not idl_type.is_nullable) context.update({ 'has_setter_exception_state': is_setter_raises_exception or has_type_checking_interface or context['has_type_checking_unrestricted'] or idl_type.v8_conversion_needs_exception_state, 'has_type_checking_interface': has_type_checking_interface, 'is_setter_call_with_execution_context': v8_utilities.has_extended_attribute_value( attribute, 'SetterCallWith', 'ExecutionContext'), 'is_setter_raises_exception': is_setter_raises_exception, 'private_script_cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( 'cppValue', isolate='scriptState->isolate()', creation_context='scriptState->context()->Global()'), 'v8_value_to_local_cpp_value': idl_type.v8_value_to_local_cpp_value( extended_attributes, 'v8Value', 'cppValue', needs_type_check=not type_checked), }) # setter_expression() depends on context values we set above. context['cpp_setter'] = setter_expression(interface, attribute, context)
def constructor_arguments(interface): arguments = [] # [ConstructorCallWith=ExecutionContext] if has_extended_attribute_value(interface, 'ConstructorCallWith', 'ExecutionContext'): arguments.append('context') # [ConstructorCallWith=Document] if has_extended_attribute_value(interface, 'ConstructorCallWith', 'Document'): arguments.append('document') # FIXME: actual arguments! # [RaisesException=Constructor] if interface.extended_attributes.get('RaisesException') == 'Constructor': arguments.append('exceptionState') return arguments
def property_getter(getter, cpp_arguments): def is_null_expression(idl_type): if v8_types.is_union_type(idl_type): return ' && '.join('!result%sEnabled' % i for i, _ in enumerate(idl_type.union_member_types)) if idl_type == 'DOMString': return 'result.isNull()' if is_interface_type(idl_type): return '!result' return '' idl_type = getter.idl_type extended_attributes = getter.extended_attributes is_raises_exception = 'RaisesException' in extended_attributes if v8_types.is_union_type(idl_type): release = [v8_types.is_interface_type(union_member_type) for union_member_type in idl_type.union_member_types] else: release = v8_types.is_interface_type(idl_type) # FIXME: make more generic, so can use v8_methods.cpp_value cpp_method_name = 'imp->%s' % cpp_name(getter) if is_raises_exception: cpp_arguments.append('exceptionState') this_union_arguments = v8_methods.union_arguments(idl_type) if this_union_arguments: cpp_arguments.extend(this_union_arguments) cpp_value = '%s(%s)' % (cpp_method_name, ', '.join(cpp_arguments)) return { 'cpp_type': v8_types.cpp_type(idl_type), 'cpp_value': cpp_value, 'is_custom': 'Custom' in extended_attributes and (not extended_attributes['Custom'] or has_extended_attribute_value(getter, 'Custom', 'PropertyGetter')), 'is_custom_property_enumerator': has_extended_attribute_value( getter, 'Custom', 'PropertyEnumerator'), 'is_custom_property_query': has_extended_attribute_value( getter, 'Custom', 'PropertyQuery'), 'is_enumerable': 'NotEnumerable' not in extended_attributes, 'is_null_expression': is_null_expression(idl_type), 'is_raises_exception': is_raises_exception, 'name': cpp_name(getter), 'union_arguments': v8_methods.union_arguments(idl_type), 'v8_set_return_value': v8_types.v8_set_return_value(idl_type, 'result', extended_attributes=extended_attributes, script_wrappable='imp', release=release), }
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) return_promise = (method.idl_type.name == 'Promise' if method.idl_type else False) 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'), 'idl_type': idl_type.base_type, 'idl_type_object': idl_type, 'index': index, 'is_callback_interface': idl_type.is_callback_interface, 'is_nullable': idl_type.is_nullable, 'is_optional': argument.is_optional, 'is_wrapper_type': idl_type.is_wrapper_type, 'name': argument.name, }
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 constructor_argument_list(interface, constructor): arguments = [] # [ConstructorCallWith=ExecutionContext] if has_extended_attribute_value(interface, "ConstructorCallWith", "ExecutionContext"): arguments.append("context") # [ConstructorCallWith=Document] if has_extended_attribute_value(interface, "ConstructorCallWith", "Document"): arguments.append("document") arguments.extend([argument.name for argument in constructor.arguments]) # [RaisesException=Constructor] if interface.extended_attributes.get("RaisesException") == "Constructor": arguments.append("exceptionState") return arguments
def constructor_argument_list(interface, constructor): arguments = [] # [ConstructorCallWith=ExecutionContext] if has_extended_attribute_value(interface, 'ConstructorCallWith', 'ExecutionContext'): arguments.append('context') # [ConstructorCallWith=Document] if has_extended_attribute_value(interface, 'ConstructorCallWith', 'Document'): arguments.append('document') arguments.extend([argument.name for argument in constructor.arguments]) # [RaisesException=Constructor] if interface.extended_attributes.get('RaisesException') == 'Constructor': arguments.append('exceptionState') return arguments
def v8_set_return_value(interface_name, method, cpp_value, for_main_world=False): idl_type = method.idl_type extended_attributes = method.extended_attributes if not idl_type or idl_type.name == 'void': # Constructors and void methods don't have a return type return None release = False # [CallWith=ScriptState], [RaisesException] if (has_extended_attribute_value(method, 'CallWith', 'ScriptState') or 'RaisesException' in extended_attributes or idl_type.is_union_type): cpp_value = 'result' # use local variable for value release = idl_type.release script_wrappable = 'impl' if inherits_interface(interface_name, 'Node') else '' return idl_type.v8_set_return_value(cpp_value, extended_attributes, script_wrappable=script_wrappable, release=release, for_main_world=for_main_world)
def use_local_result(method): extended_attributes = method.extended_attributes idl_type = method.idl_type return (has_extended_attribute_value(method, 'CallWith', 'ScriptState') or 'NewObject' in extended_attributes or 'RaisesException' in extended_attributes or idl_type.is_union_type or idl_type.is_explicit_nullable)
def use_local_result(method): extended_attributes = method.extended_attributes idl_type = method.idl_type return (has_extended_attribute_value(method, 'CallWith', 'ScriptState') or 'RaisesException' in extended_attributes or idl_type.is_union_type or idl_type.is_explicit_nullable)
def v8_set_return_value(interface_name, method, cpp_value, for_main_world=False): idl_type = method.idl_type extended_attributes = method.extended_attributes if idl_type == 'void': return None is_union_type = v8_types.is_union_type(idl_type) release = False # [CallWith=ScriptState], [RaisesException] if (has_extended_attribute_value(method, 'CallWith', 'ScriptState') or 'RaisesException' in extended_attributes or is_union_type): # use local variable for value cpp_value = 'result' if is_union_type: release = [ v8_types.is_interface_type(union_member_type) for union_member_type in idl_type.union_member_types ] else: release = v8_types.is_interface_type(idl_type) script_wrappable = 'imp' if v8_types.inherits_interface( interface_name, 'Node') else '' return v8_types.v8_set_return_value(idl_type, cpp_value, extended_attributes, script_wrappable=script_wrappable, release=release, for_main_world=for_main_world)
def property_getter(getter, cpp_arguments): def is_null_expression(idl_type): if idl_type.is_union_type: notnull = ' || '.join([ member_argument['null_check_value'] for member_argument in idl_type.union_arguments]) return '!(%s)' % notnull if idl_type.name == 'String': return 'result.isNull()' if idl_type.is_interface_type: return '!result' return '' idl_type = getter.idl_type extended_attributes = getter.extended_attributes is_raises_exception = 'RaisesException' in extended_attributes # FIXME: make more generic, so can use v8_methods.cpp_value cpp_method_name = 'impl->%s' % cpp_name(getter) if is_raises_exception: cpp_arguments.append('exceptionState') union_arguments = idl_type.union_arguments if union_arguments: cpp_arguments.extend([member_argument['cpp_value'] for member_argument in union_arguments]) cpp_value = '%s(%s)' % (cpp_method_name, ', '.join(cpp_arguments)) return { 'cpp_type': idl_type.cpp_type, 'cpp_value': cpp_value, 'is_custom': 'Custom' in extended_attributes and (not extended_attributes['Custom'] or has_extended_attribute_value(getter, 'Custom', 'PropertyGetter')), 'is_custom_property_enumerator': has_extended_attribute_value( getter, 'Custom', 'PropertyEnumerator'), 'is_custom_property_query': has_extended_attribute_value( getter, 'Custom', 'PropertyQuery'), 'is_enumerable': 'NotEnumerable' not in extended_attributes, 'is_null_expression': is_null_expression(idl_type), 'is_raises_exception': is_raises_exception, 'name': cpp_name(getter), 'union_arguments': union_arguments, 'v8_set_return_value': idl_type.v8_set_return_value('result', extended_attributes=extended_attributes, script_wrappable='impl', release=idl_type.release), }
def getter_context(interface, attribute, context): idl_type = attribute.idl_type base_idl_type = idl_type.base_type extended_attributes = attribute.extended_attributes cpp_value = getter_expression(interface, attribute, context) # Normally we can inline the function call into the return statement to # avoid the overhead of using a Ref<> temporary, but for some cases # (nullable types, EventHandler, [CachedAttribute], or if there are # exceptions), we need to use a local variable. # FIXME: check if compilers are smart enough to inline this, and if so, # always use a local variable (for readability and CG simplicity). if (idl_type.is_explicit_nullable or base_idl_type == 'EventHandler' or 'CachedAttribute' in extended_attributes or 'ReflectOnly' in extended_attributes or context['is_keep_alive_for_gc'] or context['is_getter_raises_exception'] or context['high_entropy'] == 'Direct'): context['cpp_value_original'] = cpp_value cpp_value = 'cpp_value' def v8_set_return_value_statement(for_main_world=False): if (context['is_keep_alive_for_gc'] or 'CachedAttribute' in extended_attributes): return 'V8SetReturnValue(info, v8_value)' if idl_type.is_explicit_nullable: cpp_return_value = 'cpp_value.value()' if idl_type.is_frozen_array: cpp_return_value = 'FreezeV8Object(ToV8(cpp_value.value(), info.Holder(), info.GetIsolate()), info.GetIsolate())' return 'V8SetReturnValue(info, {})'.format(cpp_return_value) return idl_type.v8_set_return_value( cpp_value, extended_attributes=extended_attributes, script_wrappable='impl', for_main_world=for_main_world, is_static=attribute.is_static) cpp_value_to_script_wrappable = cpp_value if idl_type.is_array_buffer_view_or_typed_array: cpp_value_to_script_wrappable += '.View()' context.update({ 'cpp_value': cpp_value, 'cpp_value_to_script_wrappable': cpp_value_to_script_wrappable, 'cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( cpp_value=cpp_value, creation_context='holder', extended_attributes=extended_attributes), 'is_getter_call_with_script_state': has_extended_attribute_value(attribute, 'GetterCallWith', 'ScriptState'), 'v8_set_return_value_for_main_world': v8_set_return_value_statement(for_main_world=True), 'v8_set_return_value': v8_set_return_value_statement(), })
def cpp_value(interface, method, number_of_arguments): def cpp_argument(argument): idl_type = argument.idl_type if idl_type.name == 'EventListener': return argument.name if idl_type.is_dictionary: return '*%s' % argument.name if (idl_type.name in ['NodeFilter', 'NodeFilterOrNull', 'XPathNSResolver', 'XPathNSResolverOrNull']): # FIXME: remove this special case return '%s.release()' % argument.name return argument.name # Truncate omitted optional arguments arguments = method.arguments[:number_of_arguments] cpp_arguments = [] if 'ImplementedInPrivateScript' in method.extended_attributes: cpp_arguments.append('toFrameIfNotDetached(info.GetIsolate()->GetCurrentContext())') cpp_arguments.append('impl') if method.is_constructor: call_with_values = interface.extended_attributes.get('ConstructorCallWith') else: call_with_values = method.extended_attributes.get('CallWith') cpp_arguments.extend(v8_utilities.call_with_arguments(call_with_values)) # Members of IDL partial interface definitions are implemented in C++ as # static member functions, which for instance members (non-static members) # take *impl as their first argument if ('PartialInterfaceImplementedAs' in method.extended_attributes and not 'ImplementedInPrivateScript' in method.extended_attributes and not method.is_static): cpp_arguments.append('*impl') cpp_arguments.extend(cpp_argument(argument) for argument in arguments) this_union_arguments = method.idl_type and method.idl_type.union_arguments if this_union_arguments: cpp_arguments.extend([member_argument['cpp_value'] for member_argument in this_union_arguments]) if 'ImplementedInPrivateScript' in method.extended_attributes: if method.idl_type.name != 'void': cpp_arguments.append('&result') elif ('RaisesException' in method.extended_attributes or (method.is_constructor and has_extended_attribute_value(interface, 'RaisesException', 'Constructor'))): cpp_arguments.append('exceptionState') if method.name == 'Constructor': base_name = 'create' elif method.name == 'NamedConstructor': base_name = 'createForJSConstructor' elif 'ImplementedInPrivateScript' in method.extended_attributes: base_name = '%sMethod' % method.name else: base_name = v8_utilities.cpp_name(method) cpp_method_name = v8_utilities.scoped_name(interface, method, base_name) return '%s(%s)' % (cpp_method_name, ', '.join(cpp_arguments))
def cpp_value(interface, method, number_of_arguments): def cpp_argument(argument): idl_type = argument.idl_type if idl_type.name == "EventListener": return argument.name if idl_type.is_dictionary: return "*%s" % argument.name if idl_type.name in ["NodeFilter", "NodeFilterOrNull", "XPathNSResolver", "XPathNSResolverOrNull"]: # FIXME: remove this special case return "%s.release()" % argument.name return argument.name # Truncate omitted optional arguments arguments = method.arguments[:number_of_arguments] cpp_arguments = [] if "ImplementedInPrivateScript" in method.extended_attributes: cpp_arguments.append("toFrameIfNotDetached(info.GetIsolate()->GetCurrentContext())") cpp_arguments.append("impl") if method.is_constructor: call_with_values = interface.extended_attributes.get("ConstructorCallWith") else: call_with_values = method.extended_attributes.get("CallWith") cpp_arguments.extend(v8_utilities.call_with_arguments(call_with_values)) # Members of IDL partial interface definitions are implemented in C++ as # static member functions, which for instance members (non-static members) # take *impl as their first argument if ( "PartialInterfaceImplementedAs" in method.extended_attributes and not "ImplementedInPrivateScript" in method.extended_attributes and not method.is_static ): cpp_arguments.append("*impl") cpp_arguments.extend(cpp_argument(argument) for argument in arguments) this_union_arguments = method.idl_type and method.idl_type.union_arguments if this_union_arguments: cpp_arguments.extend([member_argument["cpp_value"] for member_argument in this_union_arguments]) if "ImplementedInPrivateScript" in method.extended_attributes: if method.idl_type.name != "void": cpp_arguments.append("&result") elif "RaisesException" in method.extended_attributes or ( method.is_constructor and has_extended_attribute_value(interface, "RaisesException", "Constructor") ): cpp_arguments.append("exceptionState") if method.name == "Constructor": base_name = "create" elif method.name == "NamedConstructor": base_name = "createForJSConstructor" elif "ImplementedInPrivateScript" in method.extended_attributes: base_name = "%sMethod" % method.name else: base_name = v8_utilities.cpp_name(method) cpp_method_name = v8_utilities.scoped_name(interface, method, base_name) return "%s(%s)" % (cpp_method_name, ", ".join(cpp_arguments))
def v8_set_return_value(method, cpp_value): idl_type = method.idl_type if idl_type == 'void': return None # [CallWith=ScriptState] if has_extended_attribute_value(method, 'CallWith', 'ScriptState'): cpp_value = 'result' # use local variable for value return v8_types.v8_set_return_value(idl_type, cpp_value, method.extended_attributes)
def v8_set_return_value(interface_name, method, cpp_value, for_main_world=False): idl_type = method.idl_type extended_attributes = method.extended_attributes if idl_type.name == 'void': return None release = False # [CallWith=ScriptState|NewScriptState], [RaisesException] if (has_extended_attribute_value(method, 'CallWith', 'ScriptState') or has_extended_attribute_value(method, 'CallWith', 'NewScriptState') or 'RaisesException' in extended_attributes or idl_type.is_union_type): cpp_value = 'result' # use local variable for value release = idl_type.release script_wrappable = 'impl' if inherits_interface(interface_name, 'Node') else '' return idl_type.v8_set_return_value(cpp_value, extended_attributes, script_wrappable=script_wrappable, release=release, for_main_world=for_main_world)
def cpp_value(interface, method, number_of_arguments): def cpp_argument(argument): idl_type = argument.idl_type if idl_type.name == 'EventListener': return argument.name if (idl_type.name in ['NodeFilter', 'NodeFilterOrNull', 'XPathNSResolver', 'XPathNSResolverOrNull']): # FIXME: remove this special case return '%s.release()' % argument.name return argument.name # Truncate omitted optional arguments arguments = method.arguments[:number_of_arguments] cpp_arguments = [] if 'ImplementedInPrivateScript' in method.extended_attributes: cpp_arguments.append('toLocalFrame(toFrameIfNotDetached(info.GetIsolate()->GetCurrentContext()))') cpp_arguments.append('impl') if method.is_constructor: call_with_values = interface.extended_attributes.get('ConstructorCallWith') else: call_with_values = method.extended_attributes.get('CallWith') cpp_arguments.extend(v8_utilities.call_with_arguments(call_with_values)) # Members of IDL partial interface definitions are implemented in C++ as # static member functions, which for instance members (non-static members) # take *impl as their first argument if ('PartialInterfaceImplementedAs' in method.extended_attributes and not 'ImplementedInPrivateScript' in method.extended_attributes and not method.is_static): cpp_arguments.append('*impl') cpp_arguments.extend(cpp_argument(argument) for argument in arguments) if 'ImplementedInPrivateScript' in method.extended_attributes: if method.idl_type.name != 'void': cpp_arguments.append('&result') elif ('RaisesException' in method.extended_attributes or (method.is_constructor and has_extended_attribute_value(interface, 'RaisesException', 'Constructor'))): cpp_arguments.append('exceptionState') # If a method returns an IDL dictionary or union type, the return value is # passed as an argument to impl classes. idl_type = method.idl_type if idl_type and idl_type.use_output_parameter_for_result: cpp_arguments.append('result') if method.name == 'Constructor': base_name = 'create' elif method.name == 'NamedConstructor': base_name = 'createForJSConstructor' elif 'ImplementedInPrivateScript' in method.extended_attributes: base_name = '%sMethod' % method.name else: base_name = v8_utilities.cpp_name(method) cpp_method_name = v8_utilities.scoped_name(interface, method, base_name) return '%s(%s)' % (cpp_method_name, ', '.join(cpp_arguments))
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 use_local_result(method): extended_attributes = method.extended_attributes idl_type = method.idl_type return (has_extended_attribute_value(method, 'CallWith', 'ScriptState') or 'NewObject' in extended_attributes or 'RaisesException' in extended_attributes or idl_type.is_union_type or idl_type.is_dictionary or idl_type.is_explicit_nullable or v8_utilities.high_entropy(method) == 'Direct')
def setter_context(interface, attribute, context): if 'PutForwards' in attribute.extended_attributes: # Use target interface and attribute in place of original interface and # attribute from this point onwards. target_interface_name = attribute.idl_type.base_type target_attribute_name = attribute.extended_attributes['PutForwards'] interface = interfaces[target_interface_name] try: attribute = next(candidate for candidate in interface.attributes if candidate.name == target_attribute_name) except StopIteration: raise Exception('[PutForward] target not found:\n' 'Attribute "%s" is not present in interface "%s"' % (target_attribute_name, target_interface_name)) if ('Replaceable' in attribute.extended_attributes or is_constructor_attribute(attribute)): context[ 'cpp_setter'] = '%sCreateDataProperty(propertyName, v8Value, info)' % cpp_name( interface) return extended_attributes = attribute.extended_attributes idl_type = attribute.idl_type # [RaisesException], [RaisesException=Setter] is_setter_raises_exception = ('RaisesException' in extended_attributes and extended_attributes['RaisesException'] in [None, 'Setter']) # [LegacyInterfaceTypeChecking] has_type_checking_interface = ( not is_legacy_interface_type_checking(interface, attribute) and idl_type.is_wrapper_type) context.update({ 'has_setter_exception_state': is_setter_raises_exception or has_type_checking_interface or idl_type.v8_conversion_needs_exception_state, 'has_type_checking_interface': has_type_checking_interface, 'is_setter_call_with_execution_context': has_extended_attribute_value(attribute, 'SetterCallWith', 'ExecutionContext'), 'is_setter_raises_exception': is_setter_raises_exception, 'private_script_cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( 'cppValue', isolate='scriptState->isolate()', creation_context='scriptState->context()->Global()'), 'v8_value_to_local_cpp_value': idl_type.v8_value_to_local_cpp_value(extended_attributes, 'v8Value', 'cppValue'), }) # setter_expression() depends on context values we set above. context['cpp_setter'] = setter_expression(interface, attribute, context)
def use_local_result(method): extended_attributes = method.extended_attributes idl_type = method.idl_type return ( has_extended_attribute_value(method, "CallWith", "ScriptState") or "ImplementedInPrivateScript" in extended_attributes or "RaisesException" in extended_attributes or idl_type.is_union_type or idl_type.is_explicit_nullable )
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 setter_context(interface, attribute, interfaces, context): if "PutForwards" in attribute.extended_attributes: # Use target interface and attribute in place of original interface and # attribute from this point onwards. target_interface_name = attribute.idl_type.base_type target_attribute_name = attribute.extended_attributes["PutForwards"] interface = interfaces[target_interface_name] try: attribute = next(candidate for candidate in interface.attributes if candidate.name == target_attribute_name) except StopIteration: raise Exception( "[PutForward] target not found:\n" 'Attribute "%s" is not present in interface "%s"' % (target_attribute_name, target_interface_name) ) if "Replaceable" in attribute.extended_attributes: context[ "cpp_setter" ] = "v8CallBoolean(info.Holder()->CreateDataProperty(info.GetIsolate()->GetCurrentContext(), propertyName, v8Value))" return extended_attributes = attribute.extended_attributes idl_type = attribute.idl_type # [RaisesException], [RaisesException=Setter] is_setter_raises_exception = "RaisesException" in extended_attributes and extended_attributes[ "RaisesException" ] in [None, "Setter"] # [LegacyInterfaceTypeChecking] has_type_checking_interface = ( not is_legacy_interface_type_checking(interface, attribute) and idl_type.is_wrapper_type ) context.update( { "has_setter_exception_state": is_setter_raises_exception or has_type_checking_interface or idl_type.v8_conversion_needs_exception_state, "has_type_checking_interface": has_type_checking_interface, "is_setter_call_with_execution_context": has_extended_attribute_value( attribute, "SetterCallWith", "ExecutionContext" ), "is_setter_raises_exception": is_setter_raises_exception, "private_script_cpp_value_to_v8_value": idl_type.cpp_value_to_v8_value( "cppValue", isolate="scriptState->isolate()", creation_context="scriptState->context()->Global()" ), "v8_value_to_local_cpp_value": idl_type.v8_value_to_local_cpp_value( extended_attributes, "v8Value", "cppValue" ), } ) # setter_expression() depends on context values we set above. context["cpp_setter"] = setter_expression(interface, attribute, context)
def property_getter(getter, cpp_arguments): def is_null_expression(idl_type): if idl_type.is_union_type: return " && ".join("!result%sEnabled" % i for i, _ in enumerate(idl_type.member_types)) if idl_type.name == "String": return "result.isNull()" if idl_type.is_interface_type: return "!result" return "" idl_type = getter.idl_type extended_attributes = getter.extended_attributes is_raises_exception = "RaisesException" in extended_attributes # FIXME: make more generic, so can use v8_methods.cpp_value cpp_method_name = "impl->%s" % cpp_name(getter) if is_raises_exception: cpp_arguments.append("exceptionState") union_arguments = idl_type.union_arguments if union_arguments: cpp_arguments.extend(union_arguments) cpp_value = "%s(%s)" % (cpp_method_name, ", ".join(cpp_arguments)) return { "cpp_type": idl_type.cpp_type, "cpp_value": cpp_value, "is_custom": "Custom" in extended_attributes and (not extended_attributes["Custom"] or has_extended_attribute_value(getter, "Custom", "PropertyGetter")), "is_custom_property_enumerator": has_extended_attribute_value(getter, "Custom", "PropertyEnumerator"), "is_custom_property_query": has_extended_attribute_value(getter, "Custom", "PropertyQuery"), "is_enumerable": "NotEnumerable" not in extended_attributes, "is_null_expression": is_null_expression(idl_type), "is_raises_exception": is_raises_exception, "name": cpp_name(getter), "union_arguments": union_arguments, "v8_set_return_value": idl_type.v8_set_return_value( "result", extended_attributes=extended_attributes, script_wrappable="impl", release=idl_type.release ), }
def setter_context(interface, attribute, context): if "PutForwards" in attribute.extended_attributes: # Use target interface and attribute in place of original interface and # attribute from this point onwards. target_interface_name = attribute.idl_type.base_type target_attribute_name = attribute.extended_attributes["PutForwards"] interface = interfaces[target_interface_name] try: attribute = next(candidate for candidate in interface.attributes if candidate.name == target_attribute_name) except StopIteration: raise Exception( "[PutForward] target not found:\n" 'Attribute "%s" is not present in interface "%s"' % (target_attribute_name, target_interface_name) ) extended_attributes = attribute.extended_attributes idl_type = attribute.idl_type # [RaisesException], [RaisesException=Setter] is_setter_raises_exception = "RaisesException" in extended_attributes and extended_attributes[ "RaisesException" ] in [None, "Setter"] # [TypeChecking=Interface] 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 context.update( { "has_setter_exception_state": is_setter_raises_exception or has_type_checking_interface or context["has_type_checking_unrestricted"] or idl_type.may_raise_exception_on_conversion, "has_type_checking_interface": has_type_checking_interface, "is_setter_call_with_execution_context": v8_utilities.has_extended_attribute_value( attribute, "SetterCallWith", "ExecutionContext" ), "is_setter_raises_exception": is_setter_raises_exception, } )
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_legacy_overload_string': # [LegacyOverloadString] 'LegacyOverloadString' in extended_attributes, '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_numeric_type': idl_type.is_numeric_type, '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 setter_context(interface, attribute, context): if 'PutForwards' in attribute.extended_attributes: # Use target interface and attribute in place of original interface and # attribute from this point onwards. target_interface_name = attribute.idl_type.base_type target_attribute_name = attribute.extended_attributes['PutForwards'] interface = interfaces[target_interface_name] try: attribute = next(candidate for candidate in interface.attributes if candidate.name == target_attribute_name) except StopIteration: raise Exception('[PutForward] target not found:\n' 'Attribute "%s" is not present in interface "%s"' % (target_attribute_name, target_interface_name)) extended_attributes = attribute.extended_attributes idl_type = attribute.idl_type # [RaisesException], [RaisesException=Setter] is_setter_raises_exception = ( 'RaisesException' in extended_attributes and extended_attributes['RaisesException'] in [None, 'Setter']) # [TypeChecking=Interface] 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) context.update({ 'has_setter_exception_state': is_setter_raises_exception or has_type_checking_interface or context['has_type_checking_unrestricted'] or idl_type.may_raise_exception_on_conversion, 'has_type_checking_interface': has_type_checking_interface, 'is_setter_call_with_execution_context': v8_utilities.has_extended_attribute_value( attribute, 'SetterCallWith', 'ExecutionContext'), 'is_setter_raises_exception': is_setter_raises_exception, })
def cpp_value(interface, method, number_of_arguments): # Truncate omitted optional arguments arguments = method.arguments[:number_of_arguments] cpp_arguments = [] if 'ImplementedInPrivateScript' in method.extended_attributes: cpp_arguments.append( 'toLocalFrame(toFrameIfNotDetached(info.GetIsolate()->GetCurrentContext()))' ) cpp_arguments.append('impl') if method.is_constructor: call_with_values = interface.extended_attributes.get( 'ConstructorCallWith') else: call_with_values = method.extended_attributes.get('CallWith') cpp_arguments.extend(v8_utilities.call_with_arguments(call_with_values)) # Members of IDL partial interface definitions are implemented in C++ as # static member functions, which for instance members (non-static members) # take *impl as their first argument if ('PartialInterfaceImplementedAs' in method.extended_attributes and 'ImplementedInPrivateScript' not in method.extended_attributes and not method.is_static): cpp_arguments.append('*impl') cpp_arguments.extend(argument.name for argument in arguments) if 'ImplementedInPrivateScript' in method.extended_attributes: if method.idl_type.name != 'void': cpp_arguments.append('&result') elif ('RaisesException' in method.extended_attributes or (method.is_constructor and has_extended_attribute_value( interface, 'RaisesException', 'Constructor'))): cpp_arguments.append('exceptionState') # If a method returns an IDL dictionary or union type, the return value is # passed as an argument to impl classes. idl_type = method.idl_type if idl_type and idl_type.use_output_parameter_for_result: cpp_arguments.append('result') if method.name == 'Constructor': base_name = 'create' elif method.name == 'NamedConstructor': base_name = 'createForJSConstructor' elif 'ImplementedInPrivateScript' in method.extended_attributes: base_name = '%sMethod' % method.name else: base_name = v8_utilities.cpp_name(method) cpp_method_name = v8_utilities.scoped_name(interface, method, base_name) return '%s(%s)' % (cpp_method_name, ', '.join(cpp_arguments))
def setter_context(interface, attribute, context): if 'PutForwards' in attribute.extended_attributes: # Use target interface and attribute in place of original interface and # attribute from this point onwards. target_interface_name = attribute.idl_type.base_type target_attribute_name = attribute.extended_attributes['PutForwards'] interface = interfaces[target_interface_name] try: attribute = next(candidate for candidate in interface.attributes if candidate.name == target_attribute_name) except StopIteration: raise Exception('[PutForward] target not found:\n' 'Attribute "%s" is not present in interface "%s"' % (target_attribute_name, target_interface_name)) if ('Replaceable' in attribute.extended_attributes or is_constructor_attribute(attribute)): context['cpp_setter'] = '%sCreateDataProperty(propertyName, v8Value, info)' % cpp_name(interface) return extended_attributes = attribute.extended_attributes idl_type = attribute.idl_type # [RaisesException], [RaisesException=Setter] is_setter_raises_exception = ( 'RaisesException' in extended_attributes and extended_attributes['RaisesException'] in [None, 'Setter']) # [TypeChecking=Interface] / [LegacyInterfaceTypeChecking] has_type_checking_interface = ( not is_legacy_interface_type_checking(interface, attribute) and idl_type.is_wrapper_type) context.update({ 'has_setter_exception_state': is_setter_raises_exception or has_type_checking_interface or idl_type.v8_conversion_needs_exception_state, 'has_type_checking_interface': has_type_checking_interface, 'is_setter_call_with_execution_context': has_extended_attribute_value( attribute, 'SetterCallWith', 'ExecutionContext'), 'is_setter_raises_exception': is_setter_raises_exception, 'private_script_cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( 'cppValue', isolate='scriptState->isolate()', creation_context='scriptState->context()->Global()'), 'v8_value_to_local_cpp_value': idl_type.v8_value_to_local_cpp_value( extended_attributes, 'v8Value', 'cppValue'), }) # setter_expression() depends on context values we set above. context['cpp_setter'] = setter_expression(interface, attribute, context)
def cpp_value(interface, method, number_of_arguments): # Truncate omitted optional arguments arguments = method.arguments[:number_of_arguments] cpp_arguments = [] if "ImplementedInPrivateScript" in method.extended_attributes: cpp_arguments.append("toLocalFrame(toFrameIfNotDetached(info.GetIsolate()->GetCurrentContext()))") cpp_arguments.append("impl") if method.is_constructor: call_with_values = interface.extended_attributes.get("ConstructorCallWith") else: call_with_values = method.extended_attributes.get("CallWith") cpp_arguments.extend(v8_utilities.call_with_arguments(call_with_values)) # Members of IDL partial interface definitions are implemented in C++ as # static member functions, which for instance members (non-static members) # take *impl as their first argument if ( "PartialInterfaceImplementedAs" in method.extended_attributes and "ImplementedInPrivateScript" not in method.extended_attributes and not method.is_static ): cpp_arguments.append("*impl") cpp_arguments.extend(argument.name for argument in arguments) if "ImplementedInPrivateScript" in method.extended_attributes: if method.idl_type.name != "void": cpp_arguments.append("&result") elif "RaisesException" in method.extended_attributes or ( method.is_constructor and has_extended_attribute_value(interface, "RaisesException", "Constructor") ): cpp_arguments.append("exceptionState") # If a method returns an IDL dictionary or union type, the return value is # passed as an argument to impl classes. idl_type = method.idl_type if idl_type and idl_type.use_output_parameter_for_result: cpp_arguments.append("result") if method.name == "Constructor": base_name = "create" elif method.name == "NamedConstructor": base_name = "createForJSConstructor" elif "ImplementedInPrivateScript" in method.extended_attributes: base_name = "%sMethod" % method.name else: base_name = v8_utilities.cpp_name(method) cpp_method_name = v8_utilities.scoped_name(interface, method, base_name) return "%s(%s)" % (cpp_method_name, ", ".join(cpp_arguments))
def cpp_value(interface, method, number_of_arguments): def cpp_argument(argument): idl_type = argument.idl_type if idl_type.name == 'EventListener': if (interface.name == 'EventTarget' and method.name == 'removeEventListener'): # FIXME: remove this special case by moving get() into # EventTarget::removeEventListener return '%s.get()' % argument.name return argument.name if (idl_type.is_callback_interface or idl_type.name in ['NodeFilter', 'XPathNSResolver']): # FIXME: remove this special case return '%s.release()' % argument.name return argument.name # Truncate omitted optional arguments arguments = method.arguments[:number_of_arguments] cpp_arguments = [] if method.is_constructor: call_with_values = interface.extended_attributes.get( 'ConstructorCallWith') else: call_with_values = method.extended_attributes.get('CallWith') cpp_arguments.extend(v8_utilities.call_with_arguments(call_with_values)) # Members of IDL partial interface definitions are implemented in C++ as # static member functions, which for instance members (non-static members) # take *impl as their first argument if ('PartialInterfaceImplementedAs' in method.extended_attributes and not method.is_static): cpp_arguments.append('*impl') cpp_arguments.extend(cpp_argument(argument) for argument in arguments) this_union_arguments = method.idl_type and method.idl_type.union_arguments if this_union_arguments: cpp_arguments.extend(this_union_arguments) if ('RaisesException' in method.extended_attributes or (method.is_constructor and has_extended_attribute_value( interface, 'RaisesException', 'Constructor'))): cpp_arguments.append('exceptionState') if method.name == 'Constructor': base_name = 'create' elif method.name == 'NamedConstructor': base_name = 'createForJSConstructor' else: base_name = v8_utilities.cpp_name(method) cpp_method_name = v8_utilities.scoped_name(interface, method, base_name) return '%s(%s)' % (cpp_method_name, ', '.join(cpp_arguments))
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) return_promise = method.idl_type.name == "Promise" if method.idl_type else False 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"), "idl_type": idl_type.base_type, "idl_type_object": idl_type, "index": index, "is_callback_interface": idl_type.is_callback_interface, "is_nullable": idl_type.is_nullable, "is_optional": argument.is_optional, "is_wrapper_type": idl_type.is_wrapper_type, "name": argument.name, }
def setter_context(interface, attribute, interfaces, context): if 'PutForwards' in attribute.extended_attributes: # Make sure the target interface and attribute exist. target_interface_name = attribute.idl_type.base_type target_attribute_name = attribute.extended_attributes['PutForwards'] interface = interfaces[target_interface_name] try: next(candidate for candidate in interface.attributes if candidate.name == target_attribute_name) except StopIteration: raise Exception('[PutForward] target not found:\n' 'Attribute "%s" is not present in interface "%s"' % (target_attribute_name, target_interface_name)) context['target_attribute_name'] = target_attribute_name return if ('Replaceable' in attribute.extended_attributes): context['cpp_setter'] = ( 'V8CallBoolean(info.Holder()->CreateDataProperty(' + 'info.GetIsolate()->GetCurrentContext(), propertyName, v8Value))') return extended_attributes = attribute.extended_attributes idl_type = attribute.idl_type # [RaisesException], [RaisesException=Setter] is_setter_raises_exception = ( 'RaisesException' in extended_attributes and extended_attributes['RaisesException'] in [None, 'Setter']) # [LegacyInterfaceTypeChecking] has_type_checking_interface = ( not is_legacy_interface_type_checking(interface, attribute) and idl_type.is_wrapper_type) context.update({ 'has_setter_exception_state': is_setter_raises_exception or has_type_checking_interface or idl_type.v8_conversion_needs_exception_state, 'has_type_checking_interface': has_type_checking_interface, 'is_setter_call_with_execution_context': has_extended_attribute_value( attribute, 'SetterCallWith', 'ExecutionContext'), 'is_setter_raises_exception': is_setter_raises_exception, 'v8_value_to_local_cpp_value': idl_type.v8_value_to_local_cpp_value( extended_attributes, 'v8Value', 'cppValue'), }) # setter_expression() depends on context values we set above. context['cpp_setter'] = setter_expression(interface, attribute, 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 cpp_value(interface, method, number_of_arguments): def cpp_argument(argument): idl_type = argument.idl_type if idl_type.name == 'EventListener': if (interface.name == 'EventTarget' and method.name == 'removeEventListener'): # FIXME: remove this special case by moving get() into # EventTarget::removeEventListener return '%s.get()' % argument.name return argument.name if (idl_type.is_callback_interface or idl_type.name in ['NodeFilter', 'XPathNSResolver']): # FIXME: remove this special case return '%s.release()' % argument.name return argument.name # Truncate omitted optional arguments arguments = method.arguments[:number_of_arguments] cpp_arguments = [] if method.is_constructor: call_with_values = interface.extended_attributes.get('ConstructorCallWith') else: call_with_values = method.extended_attributes.get('CallWith') cpp_arguments.extend(v8_utilities.call_with_arguments(call_with_values)) # Members of IDL partial interface definitions are implemented in C++ as # static member functions, which for instance members (non-static members) # take *impl as their first argument if ('PartialInterfaceImplementedAs' in method.extended_attributes and not method.is_static): cpp_arguments.append('*impl') cpp_arguments.extend(cpp_argument(argument) for argument in arguments) this_union_arguments = method.idl_type and method.idl_type.union_arguments if this_union_arguments: cpp_arguments.extend(this_union_arguments) if ('RaisesException' in method.extended_attributes or (method.is_constructor and has_extended_attribute_value(interface, 'RaisesException', 'Constructor'))): cpp_arguments.append('exceptionState') if method.name == 'Constructor': base_name = 'create' elif method.name == 'NamedConstructor': base_name = 'createForJSConstructor' else: base_name = v8_utilities.cpp_name(method) cpp_method_name = v8_utilities.scoped_name(interface, method, base_name) return '%s(%s)' % (cpp_method_name, ', '.join(cpp_arguments))
def property_setter(setter): idl_type = setter.arguments[1].idl_type extended_attributes = setter.extended_attributes is_raises_exception = 'RaisesException' in extended_attributes return { 'has_type_checking_interface': has_extended_attribute_value(setter, 'TypeChecking', 'Interface') and idl_type.is_wrapper_type, 'idl_type': idl_type.base_type, 'is_custom': 'Custom' in extended_attributes, 'has_exception_state': is_raises_exception or idl_type.is_integer_type, 'is_raises_exception': is_raises_exception, 'name': cpp_name(setter), }
def cpp_value(interface, method, number_of_arguments): # Truncate omitted optional arguments arguments = method.arguments[:number_of_arguments] cpp_arguments = [] if method.is_constructor: call_with_values = interface.extended_attributes.get( 'ConstructorCallWith') else: call_with_values = method.extended_attributes.get('CallWith') cpp_arguments.extend(v8_utilities.call_with_arguments(call_with_values)) # Members of IDL partial interface definitions are implemented in C++ as # static member functions, which for instance members (non-static members) # take *impl as their first argument if ('PartialInterfaceImplementedAs' in method.extended_attributes and not method.is_static): cpp_arguments.append('*impl') for argument in arguments: variable_name = NameStyleConverter(argument.name).to_snake_case() if argument.idl_type.base_type == 'SerializedScriptValue': cpp_arguments.append('std::move(%s)' % variable_name) else: cpp_arguments.append(variable_name) if ('RaisesException' in method.extended_attributes or (method.is_constructor and has_extended_attribute_value( interface, 'RaisesException', 'Constructor'))): cpp_arguments.append('exception_state') # If a method returns an IDL dictionary or union type, the return value is # passed as an argument to impl classes. idl_type = method.idl_type if idl_type and idl_type.use_output_parameter_for_result: cpp_arguments.append('result') if method.name == 'Constructor': base_name = 'Create' elif method.name == 'NamedConstructor': base_name = 'CreateForJSConstructor' else: base_name = v8_utilities.cpp_name(method) cpp_method_name = v8_utilities.scoped_name(interface, method, base_name) return '%s(%s)' % (cpp_method_name, ', '.join(cpp_arguments))
def method_context(interface, method): arguments = method.arguments extended_attributes = method.extended_attributes idl_type = method.idl_type is_static = method.is_static name = method.name idl_type.add_includes_for_type() this_cpp_value = cpp_value(interface, method, len(arguments)) def function_template(): if is_static: return 'functionTemplate' return 'prototypeTemplate' is_call_with_script_arguments = has_extended_attribute_value( method, 'CallWith', 'ScriptArguments') if is_call_with_script_arguments: includes.update([ 'bindings/core/v8/ScriptCallStackFactory.h', 'core/inspector/ScriptArguments.h' ]) is_call_with_script_state = has_extended_attribute_value( method, 'CallWith', 'ScriptState') if is_call_with_script_state: includes.add('bindings/core/v8/ScriptState.h') is_custom_element_callbacks = 'CustomElementCallbacks' in extended_attributes if is_custom_element_callbacks: includes.add('core/dom/custom/CustomElementProcessingStack.h') is_raises_exception = 'RaisesException' in extended_attributes arguments_need_try_catch = (any( argument_needs_try_catch(method, argument) for argument in arguments)) return { 'arguments': [ argument_context(interface, method, argument, index) for index, argument in enumerate(arguments) ], 'arguments_need_try_catch': arguments_need_try_catch, 'cpp_type': (v8_types.cpp_template_type('Nullable', idl_type.cpp_type) if idl_type.is_explicit_nullable else idl_type.cpp_type), 'cpp_value': this_cpp_value, 'cpp_type_initializer': idl_type.cpp_type_initializer, 'custom_registration_extended_attributes': CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES.intersection( extended_attributes.iterkeys()), 'exposed_test': v8_utilities.exposed(method, interface), # [Exposed] 'function_template': function_template(), 'has_custom_registration': is_static or v8_utilities.has_extended_attribute( method, CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES), 'has_exception_state': is_raises_exception or any(argument for argument in arguments if argument.idl_type.name == 'SerializedScriptValue' or argument.idl_type.may_raise_exception_on_conversion), 'idl_type': idl_type.base_type, 'is_call_with_execution_context': has_extended_attribute_value(method, 'CallWith', 'ExecutionContext'), 'is_call_with_script_arguments': is_call_with_script_arguments, 'is_call_with_script_state': is_call_with_script_state, 'is_custom': 'Custom' in extended_attributes, 'is_custom_element_callbacks': is_custom_element_callbacks, 'is_explicit_nullable': idl_type.is_explicit_nullable, 'is_partial_interface_member': 'PartialInterfaceImplementedAs' in extended_attributes, 'is_raises_exception': is_raises_exception, 'is_static': is_static, 'is_variadic': arguments and arguments[-1].is_variadic, 'name': name, 'number_of_arguments': len(arguments), 'number_of_required_arguments': len([ argument for argument in arguments if not (argument.is_optional or argument.is_variadic) ]), 'number_of_required_or_variadic_arguments': len([argument for argument in arguments if not argument.is_optional]), 'union_arguments': idl_type.union_arguments, 'use_local_result': use_local_result(method), }
def generate_method(interface, method): arguments = method.arguments extended_attributes = method.extended_attributes idl_type = method.idl_type is_static = method.is_static name = method.name this_cpp_value = cpp_value(interface, method, len(arguments)) this_custom_signature = custom_signature(method, arguments) def function_template(): if is_static: return 'functionTemplate' if 'Unforgeable' in extended_attributes: return 'instanceTemplate' return 'prototypeTemplate' def signature(): if this_custom_signature: return name + 'Signature' if is_static or 'DoNotCheckSignature' in extended_attributes: return 'v8::Local<v8::Signature>()' return 'defaultSignature' is_call_with_script_arguments = has_extended_attribute_value( method, 'CallWith', 'ScriptArguments') if is_call_with_script_arguments: includes.update([ 'bindings/v8/ScriptCallStackFactory.h', 'core/inspector/ScriptArguments.h' ]) is_call_with_script_state = has_extended_attribute_value( method, 'CallWith', 'ScriptState') if is_call_with_script_state: includes.add('bindings/v8/ScriptState.h') is_check_security_for_node = 'CheckSecurity' in extended_attributes if is_check_security_for_node: includes.add('bindings/v8/BindingSecurity.h') is_custom_element_callbacks = 'CustomElementCallbacks' in extended_attributes if is_custom_element_callbacks: includes.add('core/dom/custom/CustomElementCallbackDispatcher.h') contents = { 'activity_logging_world_list': v8_utilities.activity_logging_world_list(method), # [ActivityLogging] 'arguments': [ generate_argument(interface, method, argument, index) for index, argument in enumerate(arguments) ], 'conditional_string': v8_utilities.conditional_string(method), 'cpp_type': v8_types.cpp_type(idl_type), 'cpp_value': this_cpp_value, 'custom_signature': this_custom_signature, 'deprecate_as': v8_utilities.deprecate_as(method), # [DeprecateAs] 'do_not_check_signature': not (this_custom_signature or is_static or v8_utilities.has_extended_attribute(method, [ 'DoNotCheckSecurity', 'DoNotCheckSignature', 'NotEnumerable', 'ReadOnly', 'RuntimeEnabled', 'Unforgeable' ])), 'function_template': function_template(), 'idl_type': idl_type, 'is_call_with_execution_context': has_extended_attribute_value(method, 'CallWith', 'ExecutionContext'), 'is_call_with_script_arguments': is_call_with_script_arguments, 'is_call_with_script_state': is_call_with_script_state, 'is_check_security_for_frame': ('CheckSecurity' in interface.extended_attributes and 'DoNotCheckSecurity' not in extended_attributes), 'is_check_security_for_node': is_check_security_for_node, 'is_custom': 'Custom' in extended_attributes, 'is_custom_element_callbacks': is_custom_element_callbacks, 'is_do_not_check_security': 'DoNotCheckSecurity' in extended_attributes, 'is_per_world_bindings': 'PerWorldBindings' in extended_attributes, 'is_raises_exception': 'RaisesException' in extended_attributes, 'is_read_only': 'ReadOnly' in extended_attributes, 'is_static': is_static, 'is_strict_type_checking': 'StrictTypeChecking' in extended_attributes, 'is_variadic': arguments and arguments[-1].is_variadic, 'measure_as': v8_utilities.measure_as(method), # [MeasureAs] 'name': name, 'number_of_arguments': len(arguments), 'number_of_required_arguments': len([ argument for argument in arguments if not (argument.is_optional or argument.is_variadic) ]), 'number_of_required_or_variadic_arguments': len([argument for argument in arguments if not argument.is_optional]), 'per_context_enabled_function': v8_utilities.per_context_enabled_function_name( method), # [PerContextEnabled] 'property_attributes': property_attributes(method), 'runtime_enabled_function': v8_utilities.runtime_enabled_function_name(method), # [RuntimeEnabled] 'signature': signature(), 'v8_set_return_value': v8_set_return_value(method, this_cpp_value), 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended_attributes else [''], # [PerWorldBindings] } return contents
def method_context(interface, method, is_visible=True): arguments = method.arguments extended_attributes = method.extended_attributes idl_type = method.idl_type is_static = method.is_static name = method.name if is_visible: idl_type.add_includes_for_type(extended_attributes) this_cpp_value = cpp_value(interface, method, len(arguments)) is_call_with_script_arguments = has_extended_attribute_value(method, 'CallWith', 'ScriptArguments') if is_call_with_script_arguments: includes.update(['bindings/core/v8/ScriptCallStack.h', 'core/inspector/ScriptArguments.h']) is_call_with_script_state = has_extended_attribute_value(method, 'CallWith', 'ScriptState') is_call_with_this_value = has_extended_attribute_value(method, 'CallWith', 'ThisValue') if is_call_with_script_state or is_call_with_this_value: includes.add('platform/bindings/ScriptState.h') # [CheckSecurity] is_cross_origin = 'CrossOrigin' in extended_attributes is_check_security_for_receiver = ( has_extended_attribute_value(interface, 'CheckSecurity', 'Receiver') and not is_cross_origin) is_check_security_for_return_value = ( has_extended_attribute_value(method, 'CheckSecurity', 'ReturnValue')) if is_check_security_for_receiver or is_check_security_for_return_value: includes.add('bindings/core/v8/BindingSecurity.h') is_ce_reactions = 'CEReactions' in extended_attributes if is_ce_reactions: includes.add('core/html/custom/CEReactionsScope.h') is_custom_element_callbacks = 'CustomElementCallbacks' in extended_attributes if is_custom_element_callbacks: includes.add('core/html/custom/V0CustomElementProcessingStack.h') is_raises_exception = 'RaisesException' in extended_attributes is_custom_call_prologue = has_extended_attribute_value(method, 'Custom', 'CallPrologue') is_custom_call_epilogue = has_extended_attribute_value(method, 'Custom', 'CallEpilogue') is_post_message = 'PostMessage' in extended_attributes if is_post_message: includes.add('bindings/core/v8/serialization/SerializedScriptValueFactory.h') includes.add('bindings/core/v8/serialization/Transferables.h') includes.add('core/typed_arrays/DOMArrayBufferBase.h') includes.add('core/imagebitmap/ImageBitmap.h') if 'LenientThis' in extended_attributes: raise Exception('[LenientThis] is not supported for operations.') argument_contexts = [ argument_context(interface, method, argument, index, is_visible=is_visible) for index, argument in enumerate(arguments)] return { 'activity_logging_world_list': v8_utilities.activity_logging_world_list(method), # [ActivityLogging] 'arguments': argument_contexts, 'cpp_type': (v8_types.cpp_template_type('Nullable', idl_type.cpp_type) if idl_type.is_explicit_nullable else idl_type.cpp_type), 'cpp_value': this_cpp_value, 'cpp_type_initializer': idl_type.cpp_type_initializer, 'deprecate_as': v8_utilities.deprecate_as(method), # [DeprecateAs] 'do_not_test_new_object': 'DoNotTestNewObject' in extended_attributes, 'exposed_test': v8_utilities.exposed(method, interface), # [Exposed] 'has_exception_state': is_raises_exception or is_check_security_for_receiver or any(argument for argument in arguments if (argument.idl_type.name == 'SerializedScriptValue' or argument_conversion_needs_exception_state(method, argument))), 'has_optional_argument_without_default_value': any(True for argument_context in argument_contexts if argument_context['is_optional_without_default_value']), 'idl_type': idl_type.base_type, 'is_call_with_execution_context': has_extended_attribute_value(method, 'CallWith', 'ExecutionContext'), 'is_call_with_script_arguments': is_call_with_script_arguments, 'is_call_with_script_state': is_call_with_script_state, 'is_call_with_this_value': is_call_with_this_value, 'is_ce_reactions': is_ce_reactions, 'is_check_security_for_receiver': is_check_security_for_receiver, 'is_check_security_for_return_value': is_check_security_for_return_value, 'is_cross_origin': 'CrossOrigin' in extended_attributes, 'is_custom': 'Custom' in extended_attributes and not (is_custom_call_prologue or is_custom_call_epilogue), 'is_custom_call_prologue': is_custom_call_prologue, 'is_custom_call_epilogue': is_custom_call_epilogue, 'is_custom_element_callbacks': is_custom_element_callbacks, 'is_explicit_nullable': idl_type.is_explicit_nullable, 'is_new_object': 'NewObject' in extended_attributes, 'is_partial_interface_member': 'PartialInterfaceImplementedAs' in extended_attributes, 'is_per_world_bindings': 'PerWorldBindings' in extended_attributes, 'is_post_message': is_post_message, 'is_raises_exception': is_raises_exception, 'is_static': is_static, 'is_unforgeable': is_unforgeable(interface, method), 'is_variadic': arguments and arguments[-1].is_variadic, 'measure_as': v8_utilities.measure_as(method, interface), # [MeasureAs] 'name': name, 'number_of_arguments': len(arguments), 'number_of_required_arguments': len([ argument for argument in arguments if not (argument.is_optional or argument.is_variadic)]), 'number_of_required_or_variadic_arguments': len([ argument for argument in arguments if not argument.is_optional]), 'on_instance': v8_utilities.on_instance(interface, method), 'on_interface': v8_utilities.on_interface(interface, method), 'on_prototype': v8_utilities.on_prototype(interface, method), 'origin_trial_enabled_function': v8_utilities.origin_trial_enabled_function_name(method), # [OriginTrialEnabled] 'origin_trial_feature_name': v8_utilities.origin_trial_feature_name(method), # [OriginTrialEnabled] 'property_attributes': property_attributes(interface, method), 'returns_promise': method.returns_promise, 'runtime_call_stats': runtime_call_stats_context(interface, method), 'runtime_enabled_feature_name': v8_utilities.runtime_enabled_feature_name(method), # [RuntimeEnabled] 'secure_context_test': v8_utilities.secure_context(method, interface), # [SecureContext] 'use_output_parameter_for_result': idl_type.use_output_parameter_for_result, 'use_local_result': use_local_result(method), '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), 'visible': is_visible, 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended_attributes else [''], # [PerWorldBindings], }
def attribute_context(interface, attribute, interfaces, component_info): """Creates a Jinja template context for an attribute of an interface. Args: interface: An interface which |attribute| belongs to attribute: An attribute to create the context for interfaces: A dict which maps an interface name to the definition which can be referred if needed component_info: A dict containing component wide information Returns: A Jinja template context for |attribute| """ idl_type = attribute.idl_type base_idl_type = idl_type.base_type extended_attributes = attribute.extended_attributes idl_type.add_includes_for_type(extended_attributes) if idl_type.enum_values: includes.add('core/inspector/console_message.h') includes.add('platform/heap/heap.h') # [CheckSecurity] is_cross_origin = 'CrossOrigin' in extended_attributes is_check_security_for_receiver = (has_extended_attribute_value( interface, 'CheckSecurity', 'Receiver') and is_cross_origin) is_check_security_for_return_value = (has_extended_attribute_value( attribute, 'CheckSecurity', 'ReturnValue')) if is_check_security_for_receiver or is_check_security_for_return_value: includes.add('bindings/core/v8/binding_security.h') if is_check_security_for_return_value: includes.add('core/frame/web_feature.h') includes.add('platform/instrumentation/use_counter.h') # [CrossOrigin] if has_extended_attribute_value(attribute, 'CrossOrigin', 'Setter'): includes.add('platform/bindings/v8_cross_origin_callback_info.h') # [Constructor] # TODO(yukishiino): Constructors are much like methods although constructors # are not methods. Constructors must be data-type properties, and we can # support them as a kind of methods. constructor_type = idl_type.constructor_type_name if is_constructor_attribute( attribute) else None # [CEReactions] is_ce_reactions = 'CEReactions' in extended_attributes if is_ce_reactions: includes.add('core/html/custom/ce_reactions_scope.h') # [CustomElementCallbacks], [Reflect] is_custom_element_callbacks = 'CustomElementCallbacks' in extended_attributes is_reflect = 'Reflect' in extended_attributes # [ReflectOnly] reflect_only = extended_attribute_value_as_list(attribute, 'ReflectOnly') if reflect_only: reflect_only = map( lambda v: cpp_content_attribute_value_name(interface, v), reflect_only) if is_custom_element_callbacks or is_reflect: includes.add('core/html/custom/v0_custom_element_processing_stack.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) # [SaveSameObject] is_save_same_object = ('SameObject' in attribute.extended_attributes and 'SaveSameObject' in attribute.extended_attributes) # [StringContext] if idl_type.has_string_context: includes.add('bindings/core/v8/generated_code_helper.h') # [CachedAccessor] is_cached_accessor = 'CachedAccessor' in extended_attributes # [LenientSetter] is_lenient_setter = 'LenientSetter' in extended_attributes # [CachedAttribute] cached_attribute_validation_method = extended_attributes.get( 'CachedAttribute') keep_alive_for_gc = is_keep_alive_for_gc(interface, attribute) does_generate_getter = (not has_custom_getter(attribute) and not constructor_type) does_generate_setter = ( has_setter(interface, attribute) and not (has_custom_setter(attribute) or is_lenient_setter)) use_private_property_in_getter = (does_generate_getter and (cached_attribute_validation_method or is_save_same_object or keep_alive_for_gc)) use_private_property_in_setter = (does_generate_setter and cached_attribute_validation_method) private_property_is_shared_between_getter_and_setter = ( use_private_property_in_getter and use_private_property_in_setter) does_use_private_property = (use_private_property_in_getter or use_private_property_in_setter or is_cached_accessor) if does_use_private_property: includes.add('platform/bindings/v8_private_property.h') # [LogActivity] if 'LogActivity' in extended_attributes: includes.add('platform/bindings/v8_per_context_data.h') # [DeprecateAs], [MeasureAs] deprecate_as = v8_utilities.deprecate_as(attribute) measure_as = v8_utilities.measure_as(attribute, interface) # [HighEntropy] high_entropy = v8_utilities.high_entropy(attribute) is_lazy_data_attribute = \ (constructor_type and not (measure_as or deprecate_as)) or \ (str(idl_type) == 'Window' and attribute.name in ('frames', 'self', 'window')) runtime_features = component_info['runtime_enabled_features'] internal_name = cpp_encoded_property_name(attribute) cpp_type = idl_type.cpp_type if idl_type.is_explicit_nullable: cpp_type = v8_types.cpp_template_type('base::Optional', cpp_type) context = { # [ActivityLogging] '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_world_check': v8_utilities.activity_logging_world_check(attribute), 'cached_accessor_name': 'k%s%s' % (interface.name, attribute.name.capitalize()), 'cached_attribute_validation_method': cached_attribute_validation_method, 'camel_case_name': NameStyleConverter(internal_name).to_upper_camel_case(), 'constructor_type': constructor_type, 'context_enabled_feature_name': v8_utilities.context_enabled_feature_name(attribute), 'cpp_name': cpp_name(attribute), 'cpp_type': cpp_type, 'cpp_type_initializer': idl_type.cpp_type_initializer, 'deprecate_as': deprecate_as, 'does_generate_getter': does_generate_getter, 'does_generate_setter': does_generate_setter, 'enum_type': idl_type.enum_type, 'enum_values': idl_type.enum_values, # [Exposed] 'exposed_test': v8_utilities.exposed(attribute, interface), 'getter_has_no_side_effect': has_extended_attribute_value(attribute, 'Affects', 'Nothing'), 'has_cross_origin_getter': has_extended_attribute_value(attribute, 'CrossOrigin', None) or has_extended_attribute_value(attribute, 'CrossOrigin', 'Getter'), 'has_cross_origin_setter': has_extended_attribute_value(attribute, 'CrossOrigin', 'Setter'), 'has_custom_getter': has_custom_getter(attribute), 'has_custom_setter': has_custom_setter(attribute), 'has_promise_type': idl_type.name == 'Promise', 'has_setter': has_setter(interface, attribute), 'high_entropy': high_entropy, 'idl_type': str(idl_type), 'is_cached_accessor': is_cached_accessor, 'is_call_with_execution_context': has_extended_attribute_value(attribute, 'CallWith', 'ExecutionContext'), 'is_call_with_script_state': has_extended_attribute_value(attribute, 'CallWith', 'ScriptState'), 'is_ce_reactions': is_ce_reactions, 'is_check_security_for_receiver': is_check_security_for_receiver, 'is_check_security_for_return_value': is_check_security_for_return_value, 'is_custom_element_callbacks': is_custom_element_callbacks, # TODO(yukishiino): Make all DOM attributes accessor-type properties. 'is_data_type_property': is_data_type_property(interface, attribute), 'is_getter_raises_exception': # [RaisesException] 'RaisesException' in extended_attributes and extended_attributes['RaisesException'] in (None, 'Getter'), 'is_keep_alive_for_gc': keep_alive_for_gc, 'is_lazy_data_attribute': is_lazy_data_attribute, 'is_lenient_setter': is_lenient_setter, 'is_lenient_this': 'LegacyLenientThis' in extended_attributes, 'is_nullable': idl_type.is_nullable, 'is_explicit_nullable': idl_type.is_explicit_nullable, 'is_named_constructor': is_named_constructor_attribute(attribute), 'is_partial_interface_member': 'PartialInterfaceImplementedAs' in extended_attributes, 'is_per_world_bindings': 'PerWorldBindings' in extended_attributes, 'is_put_forwards': 'PutForwards' in extended_attributes, 'is_read_only': attribute.is_read_only, 'is_reflect': is_reflect, 'is_replaceable': 'Replaceable' in attribute.extended_attributes, 'is_save_same_object': is_save_same_object, 'is_static': attribute.is_static, 'is_url': 'URL' in extended_attributes, 'is_unforgeable': is_unforgeable(attribute), 'measure_as': measure_as, 'name': attribute.name, 'on_instance': v8_utilities.on_instance(interface, attribute), 'on_interface': v8_utilities.on_interface(interface, attribute), 'on_prototype': v8_utilities.on_prototype(interface, attribute), # [RuntimeEnabled] for origin trial 'origin_trial_feature_name': v8_utilities.origin_trial_feature_name(attribute, runtime_features), 'private_property_is_shared_between_getter_and_setter': private_property_is_shared_between_getter_and_setter, 'property_attributes': property_attributes(interface, attribute), 'reflect_empty': cpp_content_attribute_value_name( interface, extended_attributes.get('ReflectEmpty')), 'reflect_invalid': cpp_content_attribute_value_name( interface, extended_attributes.get('ReflectInvalid', '')), 'reflect_missing': cpp_content_attribute_value_name( interface, extended_attributes.get('ReflectMissing')), 'reflect_only': reflect_only, # [RuntimeEnabled] if not in origin trial 'runtime_enabled_feature_name': v8_utilities.runtime_enabled_feature_name(attribute, runtime_features), # [SecureContext] 'secure_context_test': v8_utilities.secure_context(attribute, interface), 'use_output_parameter_for_result': idl_type.use_output_parameter_for_result, 'world_suffixes': ( ['', 'ForMainWorld'] if 'PerWorldBindings' in extended_attributes else ['']), # [PerWorldBindings] } if not has_custom_getter(attribute): getter_context(interface, attribute, context) if not has_custom_setter(attribute) and has_setter(interface, attribute): setter_context(interface, attribute, interfaces, context) # [RuntimeCallStatsCounter] runtime_call_stats_context(interface, attribute, context) # [CrossOrigin] is incompatible with a number of other attributes, so check # for them here. if is_cross_origin: if context['has_cross_origin_setter'] and context['has_custom_setter']: raise Exception( '[CrossOrigin] and [Custom] are incompatible on the same setter: %s.%s', interface.name, attribute.name) if context['is_per_world_bindings']: raise Exception( '[CrossOrigin] and [PerWorldBindings] are incompatible: %s.%s', interface.name, attribute.name) if context['constructor_type']: raise Exception( '[CrossOrigin] cannot be used for constructors: %s.%s', interface.name, attribute.name) return context
def setter_context(interface, attribute, interfaces, context): if 'PutForwards' in attribute.extended_attributes: # Make sure the target interface and attribute exist. target_interface_name = attribute.idl_type.base_type target_attribute_name = attribute.extended_attributes['PutForwards'] interface = interfaces[target_interface_name] try: next(candidate for candidate in interface.attributes if candidate.name == target_attribute_name) except StopIteration: raise Exception('[PutForward] target not found:\n' 'Attribute "%s" is not present in interface "%s"' % (target_attribute_name, target_interface_name)) context['target_attribute_name'] = target_attribute_name return if ('Replaceable' in attribute.extended_attributes): # Create the property, and early-return if an exception is thrown. # Subsequent cleanup code may not be prepared to handle a pending # exception. context['cpp_setter'] = ( 'if (info.Holder()->CreateDataProperty(' + 'info.GetIsolate()->GetCurrentContext(), ' + 'property_name, v8_value).IsNothing())' + '\n return') return extended_attributes = attribute.extended_attributes idl_type = attribute.idl_type # [RaisesException], [RaisesException=Setter] is_setter_raises_exception = ( 'RaisesException' in extended_attributes and extended_attributes['RaisesException'] in [None, 'Setter']) has_type_checking_interface = idl_type.is_wrapper_type use_common_reflection_setter = False # Enable use_common_reflection_setter if # * extended_attributes is [CEReactions, Reflect] or # [CEReactions, Reflect, RuntimeEnabled], # * the type is boolean, DOMString, or DOMString?, and # * the interface inherits from 'Element'. if ('Reflect' in extended_attributes and 'CEReactions' in extended_attributes and str(idl_type) in ('boolean', 'DOMString', 'DOMString?') and inherits_interface(interface.name, 'Element')): if (len(extended_attributes) == 2 or (len(extended_attributes) == 3 and 'RuntimeEnabled' in extended_attributes)): use_common_reflection_setter = True context.update({ 'has_setter_exception_state': is_setter_raises_exception or has_type_checking_interface or idl_type.v8_conversion_needs_exception_state, 'has_type_checking_interface': has_type_checking_interface, 'is_setter_call_with_execution_context': has_extended_attribute_value(attribute, 'SetterCallWith', 'ExecutionContext'), 'is_setter_call_with_script_state': has_extended_attribute_value(attribute, 'SetterCallWith', 'ScriptState'), 'is_setter_raises_exception': is_setter_raises_exception, 'use_common_reflection_setter': use_common_reflection_setter, 'v8_value_to_local_cpp_value': idl_type.v8_value_to_local_cpp_value( extended_attributes, 'v8_value', 'cpp_value', code_generation_target='attribute_set'), }) # setter_expression() depends on context values we set above. context['cpp_setter'] = setter_expression(interface, attribute, context)
def attribute_context(interface, attribute, interfaces): """Creates a Jinja template context for an attribute of an interface. Args: interface: An interface which |attribute| belongs to attribute: An attribute to create the context for interfaces: A dict which maps an interface name to the definition which can be referred if needed Returns: A Jinja template context for |attribute| """ idl_type = attribute.idl_type base_idl_type = idl_type.base_type extended_attributes = attribute.extended_attributes idl_type.add_includes_for_type(extended_attributes) if idl_type.enum_values: includes.add('core/inspector/ConsoleMessage.h') # [CheckSecurity] is_cross_origin = 'CrossOrigin' in extended_attributes is_check_security_for_receiver = (has_extended_attribute_value( interface, 'CheckSecurity', 'Receiver') and is_cross_origin) is_check_security_for_return_value = (has_extended_attribute_value( attribute, 'CheckSecurity', 'ReturnValue')) if is_check_security_for_receiver or is_check_security_for_return_value: includes.add('bindings/core/v8/BindingSecurity.h') # [CrossOrigin] if has_extended_attribute_value(attribute, 'CrossOrigin', 'Setter'): includes.add('bindings/core/v8/V8CrossOriginSetterInfo.h') # [Constructor] # TODO(yukishiino): Constructors are much like methods although constructors # are not methods. Constructors must be data-type properties, and we can # support them as a kind of methods. constructor_type = idl_type.constructor_type_name if is_constructor_attribute( attribute) else None # [CEReactions] is_ce_reactions = 'CEReactions' in extended_attributes if is_ce_reactions: includes.add('core/dom/custom/CEReactionsScope.h') # [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/V0CustomElementProcessingStack.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) # [SaveSameObject] is_save_same_object = ('SameObject' in attribute.extended_attributes and 'SaveSameObject' in attribute.extended_attributes) if is_save_same_object: includes.add('bindings/core/v8/V8PrivateProperty.h') if (base_idl_type == 'EventHandler' and interface.name in ['Window', 'WorkerGlobalScope'] and attribute.name == 'onerror'): includes.add('bindings/core/v8/V8ErrorHandler.h') cached_attribute_validation_method = extended_attributes.get( 'CachedAttribute') keep_alive_for_gc = is_keep_alive_for_gc(interface, attribute) if cached_attribute_validation_method or keep_alive_for_gc: includes.add('bindings/core/v8/V8HiddenValue.h') # [CachedAccessor] is_cached_accessor = 'CachedAccessor' in extended_attributes if is_cached_accessor: includes.add('bindings/core/v8/V8PrivateProperty.h') context = { 'access_control_list': access_control_list(interface, 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_world_check': v8_utilities.activity_logging_world_check(attribute), # [ActivityLogging] 'cached_attribute_validation_method': cached_attribute_validation_method, 'constructor_type': constructor_type, 'cpp_name': cpp_name(attribute), 'cpp_type': idl_type.cpp_type, 'cpp_type_initializer': idl_type.cpp_type_initializer, 'deprecate_as': v8_utilities.deprecate_as(attribute), # [DeprecateAs] 'enum_type': idl_type.enum_type, 'enum_values': idl_type.enum_values, 'exposed_test': v8_utilities.exposed(attribute, interface), # [Exposed] 'has_cross_origin_getter': has_extended_attribute_value(attribute, 'CrossOrigin', None) or has_extended_attribute_value(attribute, 'CrossOrigin', 'Getter'), 'has_cross_origin_setter': has_extended_attribute_value(attribute, 'CrossOrigin', 'Setter'), 'has_custom_getter': has_custom_getter(attribute), 'has_custom_setter': has_custom_setter(attribute), 'has_setter': has_setter(interface, attribute), 'idl_type': str(idl_type), # need trailing [] on array for Dictionary::ConversionContext::setConversionType 'is_cached_accessor': is_cached_accessor, 'is_call_with_execution_context': has_extended_attribute_value(attribute, 'CallWith', 'ExecutionContext'), 'is_call_with_script_state': has_extended_attribute_value(attribute, 'CallWith', 'ScriptState'), 'is_ce_reactions': is_ce_reactions, 'is_check_security_for_receiver': is_check_security_for_receiver, 'is_check_security_for_return_value': is_check_security_for_return_value, 'is_custom_element_callbacks': is_custom_element_callbacks, # TODO(yukishiino): Make all DOM attributes accessor-type properties. 'is_data_type_property': is_data_type_property(interface, attribute), 'is_getter_raises_exception': # [RaisesException] 'RaisesException' in extended_attributes and extended_attributes['RaisesException'] in (None, 'Getter'), 'is_keep_alive_for_gc': keep_alive_for_gc, 'is_lenient_this': 'LenientThis' in extended_attributes, 'is_nullable': idl_type.is_nullable, 'is_explicit_nullable': idl_type.is_explicit_nullable, 'is_partial_interface_member': 'PartialInterfaceImplementedAs' in extended_attributes, 'is_per_world_bindings': 'PerWorldBindings' in extended_attributes, 'is_put_forwards': 'PutForwards' in extended_attributes, 'is_read_only': attribute.is_read_only, 'is_reflect': is_reflect, 'is_replaceable': 'Replaceable' in attribute.extended_attributes, 'is_save_same_object': is_save_same_object, 'is_static': attribute.is_static, 'is_url': 'URL' in extended_attributes, 'is_unforgeable': is_unforgeable(interface, attribute), 'on_instance': v8_utilities.on_instance(interface, attribute), 'on_interface': v8_utilities.on_interface(interface, attribute), 'on_prototype': v8_utilities.on_prototype(interface, attribute), 'origin_trial_enabled_function': v8_utilities.origin_trial_enabled_function_name(attribute), # [OriginTrialEnabled] 'origin_trial_feature_name': v8_utilities.origin_trial_feature_name(attribute), # [OriginTrialEnabled] 'use_output_parameter_for_result': idl_type.use_output_parameter_for_result, 'measure_as': v8_utilities.measure_as(attribute, interface), # [MeasureAs] 'name': attribute.name, 'property_attributes': property_attributes(interface, attribute), 'reflect_empty': extended_attributes.get('ReflectEmpty'), 'reflect_invalid': extended_attributes.get('ReflectInvalid', ''), 'reflect_missing': extended_attributes.get('ReflectMissing'), 'reflect_only': extended_attribute_value_as_list(attribute, 'ReflectOnly'), 'runtime_enabled_feature_name': v8_utilities.runtime_enabled_feature_name(attribute), # [RuntimeEnabled] 'secure_context_test': v8_utilities.secure_context(attribute, interface), # [SecureContext] 'cached_accessor_name': '%s%sCachedAccessor' % (interface.name, attribute.name.capitalize()), 'world_suffixes': ( ['', 'ForMainWorld'] if 'PerWorldBindings' in extended_attributes else ['']), # [PerWorldBindings] } if is_constructor_attribute(attribute): update_constructor_attribute_context(interface, attribute, context) if not has_custom_getter(attribute): getter_context(interface, attribute, context) if not has_custom_setter(attribute) and has_setter(interface, attribute): setter_context(interface, attribute, interfaces, context) # [CrossOrigin] is incompatible with a number of other attributes, so check # for them here. if is_cross_origin: if context['has_cross_origin_getter'] and context['has_custom_getter']: raise Exception( '[CrossOrigin] and [Custom] are incompatible on the same getter: %s.%s', interface.name, attribute.name) if context['has_cross_origin_setter'] and context['has_custom_setter']: raise Exception( '[CrossOrigin] and [Custom] are incompatible on the same setter: %s.%s', interface.name, attribute.name) if context['is_per_world_bindings']: raise Exception( '[CrossOrigin] and [PerWorldBindings] are incompatible: %s.%s', interface.name, attribute.name) if context['constructor_type']: raise Exception( '[CrossOrigin] cannot be used for constructors: %s.%s', interface.name, attribute.name) return context
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(extended_attributes) if idl_type.enum_values: includes.add('core/inspector/ConsoleMessage.h') # [CheckSecurity] is_do_not_check_security = 'DoNotCheckSecurity' in extended_attributes is_check_security_for_receiver = (has_extended_attribute_value( interface, 'CheckSecurity', 'Receiver') and not is_do_not_check_security) is_check_security_for_return_value = (has_extended_attribute_value( attribute, 'CheckSecurity', 'ReturnValue')) if is_check_security_for_receiver or is_check_security_for_return_value: includes.add('bindings/core/v8/BindingSecurity.h') # [Constructor] # TODO(yukishiino): Constructors are much like methods although constructors # are not methods. Constructors must be data-type properties, and we can # support them as a kind of methods. constructor_type = idl_type.constructor_type_name if is_constructor_attribute( attribute) else None # [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/CustomElementProcessingStack.h') # [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') includes.add('platform/ScriptForbiddenScope.h') # [OnlyExposedToPrivateScript] is_only_exposed_to_private_script = 'OnlyExposedToPrivateScript' in extended_attributes # [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) if (base_idl_type == 'EventHandler' and interface.name in ['Window', 'WorkerGlobalScope'] and attribute.name == 'onerror'): includes.add('bindings/core/v8/V8ErrorHandler.h') cached_attribute_validation_method = extended_attributes.get( 'CachedAttribute') keep_alive_for_gc = is_keep_alive_for_gc(interface, attribute) if cached_attribute_validation_method or keep_alive_for_gc: includes.add('bindings/core/v8/V8HiddenValue.h') if 'RuntimeEnabled' in extended_attributes: includes.add('platform/RuntimeEnabledFeatures.h') if 'OriginTrialEnabled' in extended_attributes: includes.add('core/inspector/ConsoleMessage.h') includes.add('core/origin_trials/OriginTrials.h') context = { 'access_control_list': access_control_list(interface, 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_world_check': v8_utilities.activity_logging_world_check(attribute), # [ActivityLogging] 'argument_cpp_type': idl_type.cpp_type_args(used_as_rvalue_type=True), 'cached_attribute_validation_method': cached_attribute_validation_method, 'constructor_type': constructor_type, 'cpp_name': cpp_name(attribute), 'cpp_type': idl_type.cpp_type, 'cpp_type_initializer': idl_type.cpp_type_initializer, 'deprecate_as': v8_utilities.deprecate_as(attribute), # [DeprecateAs] 'enum_type': idl_type.enum_type, 'enum_values': idl_type.enum_values, 'exposed_test': v8_utilities.exposed(attribute, interface), # [Exposed] 'has_custom_getter': has_custom_getter(attribute), 'has_custom_setter': has_custom_setter(attribute), 'has_setter': has_setter(attribute), 'idl_type': str(idl_type), # need trailing [] on array for Dictionary::ConversionContext::setConversionType 'is_origin_trial_enabled': v8_utilities.origin_trial_enabled_function(attribute) or v8_utilities.origin_trial_enabled_function(interface), # [OriginTrialEnabled] 'is_call_with_execution_context': has_extended_attribute_value(attribute, 'CallWith', 'ExecutionContext'), 'is_call_with_script_state': has_extended_attribute_value(attribute, 'CallWith', 'ScriptState'), 'is_check_security_for_receiver': is_check_security_for_receiver, 'is_check_security_for_return_value': is_check_security_for_return_value, 'is_custom_element_callbacks': is_custom_element_callbacks, # TODO(yukishiino): Make all DOM attributes accessor-type properties. 'is_data_type_property': constructor_type or interface.name == 'Window' or interface.name == 'Location', '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_keep_alive_for_gc': keep_alive_for_gc, 'is_lenient_this': 'LenientThis' in extended_attributes, 'is_nullable': idl_type.is_nullable, 'is_explicit_nullable': idl_type.is_explicit_nullable, 'is_partial_interface_member': 'PartialInterfaceImplementedAs' in extended_attributes, 'is_per_world_bindings': 'PerWorldBindings' in extended_attributes, 'is_put_forwards': 'PutForwards' 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': is_unforgeable(interface, attribute), 'on_instance': v8_utilities.on_instance(interface, attribute), 'on_interface': v8_utilities.on_interface(interface, attribute), 'on_prototype': v8_utilities.on_prototype(interface, attribute), 'origin_trial_enabled': v8_utilities.origin_trial_enabled_function(attribute), # [OriginTrialEnabled] 'origin_trial_enabled_per_interface': v8_utilities.origin_trial_enabled_function(interface), # [OriginTrialEnabled] 'origin_trial_name': extended_attributes.get('OriginTrialEnabled'), # [OriginTrialEnabled] 'use_output_parameter_for_result': idl_type.use_output_parameter_for_result, 'measure_as': v8_utilities.measure_as(attribute, interface), # [MeasureAs] 'name': attribute.name, 'only_exposed_to_private_script': is_only_exposed_to_private_script, 'private_script_v8_value_to_local_cpp_value': idl_type.v8_value_to_local_cpp_value( extended_attributes, 'v8Value', 'cppValue', bailout_return_value='false', isolate='scriptState->isolate()'), 'property_attributes': property_attributes(interface, attribute), 'reflect_empty': extended_attributes.get('ReflectEmpty'), 'reflect_invalid': extended_attributes.get('ReflectInvalid', ''), 'reflect_missing': extended_attributes.get('ReflectMissing'), 'reflect_only': extended_attribute_value_as_list(attribute, 'ReflectOnly'), 'runtime_enabled_function': v8_utilities.runtime_enabled_function_name(attribute), # [RuntimeEnabled] 'should_be_exposed_to_script': not (is_implemented_in_private_script and is_only_exposed_to_private_script), 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended_attributes else [''], # [PerWorldBindings] } if is_constructor_attribute(attribute): update_constructor_attribute_context(interface, attribute, context) if not has_custom_getter(attribute): getter_context(interface, attribute, context) if not has_custom_setter(attribute) and has_setter(attribute): setter_context(interface, attribute, context) 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