def generate_setter(interface, attribute, contents): def target_attribute(): target_interface_name = attribute.idl_type target_attribute_name = extended_attributes['PutForwards'] target_interface = interfaces[target_interface_name] try: return next(attribute for attribute in target_interface.attributes if attribute.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 if 'PutForwards' in extended_attributes: # Use target attribute in place of original attribute attribute = target_attribute() contents.update({ 'cpp_setter': setter_expression(interface, attribute, contents), 'v8_value_to_local_cpp_value': v8_types.v8_value_to_local_cpp_value(attribute.idl_type, extended_attributes, 'jsValue', 'cppValue'), })
def generate_setter(interface, attribute, contents): def target_attribute(): target_interface_name = attribute.idl_type target_attribute_name = extended_attributes['PutForwards'] target_interface = interfaces[target_interface_name] try: return next(attribute for attribute in target_interface.attributes if attribute.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 if 'PutForwards' in extended_attributes: # Use target attribute in place of original attribute attribute = target_attribute() contents.update({ 'cpp_setter': setter_expression(interface, attribute, contents), 'v8_value_to_local_cpp_value': v8_types.v8_value_to_local_cpp_value( attribute.idl_type, extended_attributes, 'jsValue', 'cppValue'), })
def generate_setter(interface, attribute, contents): idl_type = attribute.idl_type extended_attributes = attribute.extended_attributes if v8_types.is_interface_type( idl_type) and not v8_types.array_type(idl_type): cpp_value = 'WTF::getPtr(cppValue)' else: cpp_value = 'cppValue' is_reflect = 'Reflect' in extended_attributes if is_reflect: includes.add('core/dom/custom/CustomElementCallbackDispatcher.h') contents.update({ 'cpp_setter': setter_expression(interface, attribute, contents), 'enum_validation_expression': v8_utilities.enum_validation_expression(idl_type), 'has_strict_type_checking': 'StrictTypeChecking' in extended_attributes and v8_types.is_interface_type(idl_type), 'is_reflect': is_reflect, 'v8_value_to_local_cpp_value': v8_types.v8_value_to_local_cpp_value(idl_type, extended_attributes, 'jsValue', 'cppValue'), })
def generate_setter(interface, attribute, contents): extended_attributes = attribute.extended_attributes if 'PutForwards' in extended_attributes: target_interface_name = attribute.idl_type target_attribute_name = extended_attributes['PutForwards'] target_interface = interfaces[target_interface_name] try: target_attribute = next(attribute for attribute in target_interface.attributes if attribute.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)) # For setter expression, overwrite attribute name and IDL type with # values of target attribute attribute.name = target_attribute_name attribute.idl_type = target_attribute.idl_type contents.update({ 'cpp_setter': setter_expression(interface, attribute, contents), 'v8_value_to_local_cpp_value': v8_types.v8_value_to_local_cpp_value( attribute.idl_type, extended_attributes, 'jsValue', 'cppValue'), })
def v8_value_to_local_cpp_value(argument, index): extended_attributes = argument.extended_attributes idl_type = argument.idl_type name = argument.name if argument.is_variadic: return 'V8TRYCATCH_VOID(Vector<{cpp_type}>, {name}, toNativeArguments<{cpp_type}>(info, {index}))'.format( cpp_type=v8_types.cpp_type(idl_type), name=name, index=index) if (argument.is_optional and idl_type == 'DOMString' and extended_attributes.get('Default') == 'NullString'): v8_value = 'argumentOrNull(info, %s)' % index else: v8_value = 'info[%s]' % index return v8_types.v8_value_to_local_cpp_value( idl_type, argument.extended_attributes, v8_value, name, index=index)
def v8_value_to_local_cpp_value(argument, index): extended_attributes = argument.extended_attributes idl_type = argument.idl_type name = argument.name if argument.is_variadic: return 'V8TRYCATCH_VOID(Vector<{cpp_type}>, {name}, toNativeArguments<{cpp_type}>(info, {index}))'.format( cpp_type=v8_types.cpp_type(idl_type), name=name, index=index) if (argument.is_optional and idl_type == 'DOMString' and extended_attributes.get('Default') == 'NullString'): v8_value = 'argumentOrNull(info, %s)' % index else: v8_value = 'info[%s]' % index return v8_types.v8_value_to_local_cpp_value(idl_type, argument.extended_attributes, v8_value, name, index=index)
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_strict_type_checking': 'StrictTypeChecking' in extended_attributes and v8_types.is_wrapper_type(idl_type), 'idl_type': idl_type, 'is_custom': 'Custom' in extended_attributes, 'has_exception_state': is_raises_exception or v8_types.is_integer_type(idl_type), 'is_raises_exception': is_raises_exception, 'name': cpp_name(setter), 'v8_value_to_local_cpp_value': v8_types.v8_value_to_local_cpp_value( idl_type, extended_attributes, 'jsValue', 'propertyValue'), }
def generate_setter(interface, attribute, contents): idl_type = attribute.idl_type extended_attributes = attribute.extended_attributes if v8_types.is_interface_type(idl_type) and not v8_types.array_type(idl_type): cpp_value = 'WTF::getPtr(cppValue)' else: cpp_value = 'cppValue' is_reflect = 'Reflect' in extended_attributes if is_reflect: includes.add('core/dom/custom/CustomElementCallbackDispatcher.h') contents.update({ 'cpp_setter': setter_expression(interface, attribute, contents), 'enum_validation_expression': v8_utilities.enum_validation_expression(idl_type), 'has_strict_type_checking': 'StrictTypeChecking' in extended_attributes and v8_types.is_interface_type(idl_type), 'is_reflect': is_reflect, 'v8_value_to_local_cpp_value': v8_types.v8_value_to_local_cpp_value( idl_type, extended_attributes, 'jsValue', 'cppValue'), })
def generate_attribute(interface, attribute): idl_type = attribute.idl_type extended_attributes = attribute.extended_attributes v8_types.add_includes_for_type(idl_type) # [CheckSecurity] is_check_security_for_node = 'CheckSecurity' in extended_attributes if is_check_security_for_node: includes.add('bindings/v8/BindingSecurity.h') # [Custom] has_custom_getter = ('Custom' in extended_attributes and extended_attributes['Custom'] in [None, 'Getter']) has_custom_setter = (not attribute.is_read_only and 'Custom' in extended_attributes and extended_attributes['Custom'] in [None, 'Setter']) # [RaisesException] is_getter_raises_exception = ( 'RaisesException' in extended_attributes and extended_attributes['RaisesException'] in [None, 'Getter']) if is_check_security_for_node or is_getter_raises_exception: includes.add('bindings/v8/ExceptionMessages.h') # [Reflect] is_reflect = 'Reflect' in extended_attributes if is_reflect: includes.add('core/dom/custom/CustomElementCallbackDispatcher.h') if (idl_type == 'EventHandler' and interface.name in ['Window', 'WorkerGlobalScope'] and attribute.name == 'onerror'): includes.add('bindings/v8/V8ErrorHandler.h') contents = { 'access_control_list': access_control_list(attribute), 'activity_logging_world_list_for_getter': v8_utilities.activity_logging_world_list(attribute, 'Getter'), # [ActivityLogging] 'activity_logging_world_list_for_setter': v8_utilities.activity_logging_world_list(attribute, 'Setter'), # [ActivityLogging] 'cached_attribute_validation_method': extended_attributes.get('CachedAttribute'), 'conditional_string': v8_utilities.conditional_string(attribute), 'constructor_type': v8_types.constructor_type(idl_type) if is_constructor_attribute(attribute) else None, 'cpp_name': cpp_name(attribute), 'cpp_type': v8_types.cpp_type(idl_type), 'deprecate_as': v8_utilities.deprecate_as(attribute), # [DeprecateAs] 'enum_validation_expression': v8_utilities.enum_validation_expression(idl_type), 'has_custom_getter': has_custom_getter, 'has_custom_setter': has_custom_setter, 'has_strict_type_checking': ( 'StrictTypeChecking' in extended_attributes and v8_types.is_interface_type(idl_type)), 'idl_type': idl_type, 'is_call_with_execution_context': v8_utilities.has_extended_attribute_value(attribute, 'CallWith', 'ExecutionContext'), 'is_check_security_for_node': is_check_security_for_node, 'is_expose_js_accessors': 'ExposeJSAccessors' in extended_attributes, 'is_getter_raises_exception': ( 'RaisesException' in extended_attributes and extended_attributes['RaisesException'] in [None, 'Getter']), 'is_initialized_by_event_constructor': 'InitializedByEventConstructor' in extended_attributes, 'is_keep_alive_for_gc': is_keep_alive_for_gc(attribute), 'is_nullable': attribute.is_nullable, 'is_per_world_bindings': 'PerWorldBindings' in extended_attributes, 'is_read_only': attribute.is_read_only, 'is_reflect': is_reflect, 'is_replaceable': 'Replaceable' in attribute.extended_attributes, 'is_setter_raises_exception': ( 'RaisesException' in extended_attributes and extended_attributes['RaisesException'] in [None, 'Setter']), 'is_static': attribute.is_static, 'is_unforgeable': 'Unforgeable' in extended_attributes, 'measure_as': v8_utilities.measure_as(attribute), # [MeasureAs] 'name': attribute.name, 'per_context_enabled_function': v8_utilities.per_context_enabled_function_name(attribute), # [PerContextEnabled] 'property_attributes': property_attributes(attribute), 'setter_callback': setter_callback_name(interface, attribute), 'v8_type': v8_types.v8_type(idl_type), 'runtime_enabled_function': v8_utilities.runtime_enabled_function_name(attribute), # [RuntimeEnabled] 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended_attributes else [''], # [PerWorldBindings] } if is_constructor_attribute(attribute): return contents if not has_custom_getter: generate_getter(interface, attribute, contents) if not(attribute.is_read_only or has_custom_setter): contents.update({ 'cpp_setter': setter_expression(interface, attribute, contents), 'v8_value_to_local_cpp_value': v8_types.v8_value_to_local_cpp_value( idl_type, extended_attributes, 'jsValue', 'cppValue'), }) return contents
def generate_attribute(interface, attribute): idl_type = attribute.idl_type extended_attributes = attribute.extended_attributes v8_types.add_includes_for_type(idl_type) # [CheckSecurity] is_check_security_for_node = 'CheckSecurity' in extended_attributes if is_check_security_for_node: includes.add('bindings/v8/BindingSecurity.h') # [Custom] has_custom_getter = ('Custom' in extended_attributes and extended_attributes['Custom'] in [None, 'Getter']) has_custom_setter = (not attribute.is_read_only and 'Custom' in extended_attributes and extended_attributes['Custom'] in [None, 'Setter']) # [Reflect] is_reflect = 'Reflect' in extended_attributes if is_reflect: includes.add('core/dom/custom/CustomElementCallbackDispatcher.h') if (idl_type == 'EventHandler' and interface.name in ['Window', 'WorkerGlobalScope'] and attribute.name == 'onerror'): includes.add('bindings/v8/V8ErrorHandler.h') contents = { 'access_control_list': access_control_list(attribute), 'activity_logging_world_list_for_getter': v8_utilities.activity_logging_world_list( attribute, 'Getter'), # [ActivityLogging] 'activity_logging_world_list_for_setter': v8_utilities.activity_logging_world_list( attribute, 'Setter'), # [ActivityLogging] 'cached_attribute_validation_method': extended_attributes.get('CachedAttribute'), 'conditional_string': v8_utilities.conditional_string(attribute), 'constructor_type': v8_types.constructor_type(idl_type) if is_constructor_attribute(attribute) else None, 'cpp_name': cpp_name(attribute), 'cpp_type': v8_types.cpp_type(idl_type), 'deprecate_as': v8_utilities.deprecate_as(attribute), # [DeprecateAs] 'enum_validation_expression': v8_utilities.enum_validation_expression(idl_type), 'has_custom_getter': has_custom_getter, 'has_custom_setter': has_custom_setter, 'has_strict_type_checking': ('StrictTypeChecking' in extended_attributes and v8_types.is_interface_type(idl_type)), 'idl_type': idl_type, 'is_call_with_execution_context': v8_utilities.has_extended_attribute_value(attribute, 'CallWith', 'ExecutionContext'), 'is_check_security_for_node': is_check_security_for_node, 'is_expose_js_accessors': 'ExposeJSAccessors' in extended_attributes, 'is_getter_raises_exception': ( # [RaisesException] 'RaisesException' in extended_attributes and extended_attributes['RaisesException'] in [None, 'Getter']), 'is_initialized_by_event_constructor': 'InitializedByEventConstructor' in extended_attributes, 'is_keep_alive_for_gc': is_keep_alive_for_gc(attribute), 'is_nullable': attribute.is_nullable, 'is_per_world_bindings': 'PerWorldBindings' in extended_attributes, 'is_read_only': attribute.is_read_only, 'is_reflect': is_reflect, 'is_replaceable': 'Replaceable' in attribute.extended_attributes, 'is_setter_raises_exception': ('RaisesException' in extended_attributes and extended_attributes['RaisesException'] in [None, 'Setter']), 'is_static': attribute.is_static, 'is_unforgeable': 'Unforgeable' in extended_attributes, 'measure_as': v8_utilities.measure_as(attribute), # [MeasureAs] 'name': attribute.name, 'per_context_enabled_function': v8_utilities.per_context_enabled_function_name( attribute), # [PerContextEnabled] 'property_attributes': property_attributes(attribute), 'setter_callback': setter_callback_name(interface, attribute), 'v8_type': v8_types.v8_type(idl_type), 'runtime_enabled_function': v8_utilities.runtime_enabled_function_name( attribute), # [RuntimeEnabled] 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended_attributes else [''], # [PerWorldBindings] } if is_constructor_attribute(attribute): return contents if not has_custom_getter: generate_getter(interface, attribute, contents) if not (attribute.is_read_only or has_custom_setter): contents.update({ 'cpp_setter': setter_expression(interface, attribute, contents), 'v8_value_to_local_cpp_value': v8_types.v8_value_to_local_cpp_value(idl_type, extended_attributes, 'jsValue', 'cppValue'), }) return contents