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_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 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') 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('bindings/core/v8/ScriptState.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(method, 'CheckSecurity', 'ReturnValue')) if is_check_security_for_receiver or is_check_security_for_return_value: includes.add('bindings/core/v8/BindingSecurity.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 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/SerializedScriptValueFactory.h') includes.add('core/dom/DOMArrayBuffer.h') includes.add('core/dom/MessagePort.h') includes.add('core/frame/ImageBitmap.h') conditional_string = v8_utilities.conditional_string(method) if conditional_string: includes.add('wtf/build_config.h') if 'LenientThis' in extended_attributes: raise Exception('[LenientThis] is not supported for operations.') if 'APIExperimentEnabled' in extended_attributes: includes.add('core/experiments/ExperimentalFeatures.h') includes.add('core/inspector/ConsoleMessage.h') 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] 'api_experiment_enabled': v8_utilities.api_experiment_enabled_function(method), # [APIExperimentEnabled] 'api_experiment_enabled_per_interface': v8_utilities.api_experiment_enabled_function(interface), # [APIExperimentEnabled] 'arguments': argument_contexts, 'argument_declarations_for_private_script': argument_declarations_for_private_script(interface, method), 'conditional_string': conditional_string, '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()), 'deprecate_as': v8_utilities.deprecate_as(method), # [DeprecateAs] 'exposed_test': v8_utilities.exposed(method, interface), # [Exposed] # TODO(yukishiino): Retire has_custom_registration flag. Should be # replaced with V8DOMConfiguration::PropertyLocationConfiguration. 'has_custom_registration': v8_utilities.has_extended_attribute( method, CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES), '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_api_experiment_enabled': v8_utilities.api_experiment_enabled_function(method) or v8_utilities.api_experiment_enabled_function(interface), # [APIExperimentEnabled] '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_check_security_for_receiver': is_check_security_for_receiver, 'is_check_security_for_return_value': is_check_security_for_return_value, '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_do_not_check_security': is_do_not_check_security, 'is_do_not_check_signature': 'DoNotCheckSignature' in extended_attributes, 'is_explicit_nullable': idl_type.is_explicit_nullable, 'is_implemented_in_private_script': is_implemented_in_private_script, '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), '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', isolate='scriptState->isolate()', bailout_return_value='false'), 'property_attributes': property_attributes(interface, method), 'returns_promise': method.returns_promise, 'runtime_enabled_function': v8_utilities.runtime_enabled_function_name(method), # [RuntimeEnabled] 'should_be_exposed_to_script': not (is_implemented_in_private_script and is_only_exposed_to_private_script), '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): 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") conditional_string = v8_utilities.conditional_string(attribute) if conditional_string: includes.add("wtf/build_config.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 "APIExperimentEnabled" in extended_attributes: includes.add("core/experiments/ExperimentalFeatures.h") includes.add("core/inspector/ConsoleMessage.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] "api_experiment_enabled": v8_utilities.api_experiment_enabled_function(attribute), # [APIExperimentEnabled] "api_experiment_enabled_per_interface": v8_utilities.api_experiment_enabled_function( interface ), # [APIExperimentEnabled] "api_experiment_name": extended_attributes.get("APIExperimentEnabled"), # [APIExperimentEnabled] "argument_cpp_type": idl_type.cpp_type_args(used_as_rvalue_type=True), "cached_attribute_validation_method": cached_attribute_validation_method, "conditional_string": conditional_string, "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_api_experiment_enabled": v8_utilities.api_experiment_enabled_function(attribute) or v8_utilities.api_experiment_enabled_function(interface), # [APIExperimentEnabled] "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" in extended_attributes # [RaisesException] 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), "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 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 'APIExperimentEnabled' in extended_attributes: includes.add('core/experiments/ExperimentalFeatures.h') includes.add('core/inspector/ConsoleMessage.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] 'api_experiment_enabled': v8_utilities.api_experiment_enabled_function(attribute), # [APIExperimentEnabled] 'api_experiment_enabled_per_interface': v8_utilities.api_experiment_enabled_function(interface), # [APIExperimentEnabled] 'api_experiment_name': extended_attributes.get('APIExperimentEnabled'), # [APIExperimentEnabled] '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_api_experiment_enabled': v8_utilities.api_experiment_enabled_function(attribute) or v8_utilities.api_experiment_enabled_function(interface), # [APIExperimentEnabled] '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), '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 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_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 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') 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('bindings/core/v8/ScriptState.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( method, 'CheckSecurity', 'ReturnValue')) if is_check_security_for_receiver or is_check_security_for_return_value: includes.add('bindings/core/v8/BindingSecurity.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 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/SerializedScriptValueFactory.h') includes.add('core/dom/DOMArrayBuffer.h') includes.add('core/dom/MessagePort.h') includes.add('core/frame/ImageBitmap.h') if 'LenientThis' in extended_attributes: raise Exception('[LenientThis] is not supported for operations.') if 'APIExperimentEnabled' in extended_attributes: includes.add('core/experiments/ExperimentalFeatures.h') includes.add('core/inspector/ConsoleMessage.h') 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] 'api_experiment_enabled': v8_utilities.api_experiment_enabled_function( method), # [APIExperimentEnabled] 'api_experiment_enabled_per_interface': v8_utilities.api_experiment_enabled_function( interface), # [APIExperimentEnabled] 'arguments': argument_contexts, 'argument_declarations_for_private_script': argument_declarations_for_private_script(interface, method), '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()), 'deprecate_as': v8_utilities.deprecate_as(method), # [DeprecateAs] 'exposed_test': v8_utilities.exposed(method, interface), # [Exposed] # TODO(yukishiino): Retire has_custom_registration flag. Should be # replaced with V8DOMConfiguration::PropertyLocationConfiguration. 'has_custom_registration': v8_utilities.has_extended_attribute( method, CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES), '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_api_experiment_enabled': v8_utilities.api_experiment_enabled_function(method) or v8_utilities.api_experiment_enabled_function( interface), # [APIExperimentEnabled] '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_check_security_for_receiver': is_check_security_for_receiver, 'is_check_security_for_return_value': is_check_security_for_return_value, '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_do_not_check_security': is_do_not_check_security, 'is_do_not_check_signature': 'DoNotCheckSignature' in extended_attributes, 'is_explicit_nullable': idl_type.is_explicit_nullable, 'is_implemented_in_private_script': is_implemented_in_private_script, '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), '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', isolate='scriptState->isolate()', bailout_return_value='false'), 'property_attributes': property_attributes(interface, method), 'returns_promise': method.returns_promise, 'runtime_enabled_function': v8_utilities.runtime_enabled_function_name(method), # [RuntimeEnabled] 'should_be_exposed_to_script': not (is_implemented_in_private_script and is_only_exposed_to_private_script), '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): 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 'APIExperimentEnabled' in extended_attributes: includes.add('core/experiments/ExperimentalFeatures.h') includes.add('core/inspector/ConsoleMessage.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] 'api_experiment_enabled': v8_utilities.api_experiment_enabled_function(attribute), # [APIExperimentEnabled] 'api_experiment_enabled_per_interface': v8_utilities.api_experiment_enabled_function(interface), # [APIExperimentEnabled] 'api_experiment_name': extended_attributes.get('APIExperimentEnabled'), # [APIExperimentEnabled] '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_api_experiment_enabled': v8_utilities.api_experiment_enabled_function(attribute) or v8_utilities.api_experiment_enabled_function(interface), # [APIExperimentEnabled] '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), '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