def setter_base_name(interface, attribute, arguments): if 'ImplementedInPrivateScript' in attribute.extended_attributes: return '%sAttributeSetter' % uncapitalize(cpp_name(attribute)) if 'Reflect' not in attribute.extended_attributes: return 'set%s' % capitalize(cpp_name(attribute)) arguments.append(scoped_content_attribute_name(interface, attribute)) base_idl_type = attribute.idl_type.base_type if base_idl_type in CONTENT_ATTRIBUTE_SETTER_NAMES: return CONTENT_ATTRIBUTE_SETTER_NAMES[base_idl_type] return 'setAttribute'
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 ext_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, 'ext_set_return_value': idl_type.ext_set_return_value('result', extended_attributes=extended_attributes, script_wrappable='impl', release=idl_type.release), }
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_callback_interface or 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(ext_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 = ext_utilities.cpp_name(method) cpp_method_name = ext_utilities.scoped_name(interface, method, base_name) return '%s(%s)' % (cpp_method_name, ', '.join(cpp_arguments))
def setter_callback_name(interface, attribute): cpp_class_name = cpp_name(interface) extended_attributes = attribute.extended_attributes if (('Replaceable' in extended_attributes and 'PutForwards' not in extended_attributes) or is_constructor_attribute(attribute)): return '{0}V8Internal::{0}ForceSetAttributeOnThisCallback'.format(cpp_class_name) if attribute.is_read_only and 'PutForwards' not in extended_attributes: return '0' return '%sV8Internal::%sAttributeSetterCallback' % (cpp_class_name, attribute.name)
def dictionary_impl_context(dictionary, interfaces_info): includes.clear() header_includes = set(['platform/heap/Handle.h']) return { 'header_includes': header_includes, 'cpp_class': ext_utilities.cpp_name(dictionary), 'members': [member_impl_context(member, interfaces_info, header_includes) for member in dictionary.members], }
def dictionary_context(dictionary): includes.clear() includes.update(DICTIONARY_CPP_INCLUDES) return { 'cpp_class': ext_utilities.cpp_name(dictionary), 'header_includes': set(DICTIONARY_H_INCLUDES), 'members': [member_context(member) for member in sorted(dictionary.members, key=operator.attrgetter('name'))], 'ext_class': ext_utilities.ext_class_name(dictionary), }
def setter_callback_name(interface, attribute): cpp_class_name = cpp_name(interface) extended_attributes = attribute.extended_attributes if (('Replaceable' in extended_attributes and 'PutForwards' not in extended_attributes) or is_constructor_attribute(attribute)): return '{0}V8Internal::{0}ForceSetAttributeOnThisCallback'.format( cpp_class_name) if attribute.is_read_only and 'PutForwards' not in extended_attributes: return '0' return '%sV8Internal::%sAttributeSetterCallback' % (cpp_class_name, attribute.name)
def property_deleter(deleter): idl_type = deleter.idl_type if str(idl_type) != 'boolean': raise Exception( 'Only deleters with boolean type are allowed, but type is "%s"' % idl_type) extended_attributes = deleter.extended_attributes return { 'is_custom': 'Custom' in extended_attributes, 'is_raises_exception': 'RaisesException' in extended_attributes, 'name': cpp_name(deleter), }
def getter_base_name(interface, attribute, arguments): extended_attributes = attribute.extended_attributes if 'ImplementedInPrivateScript' in extended_attributes: return '%sAttributeGetter' % uncapitalize(cpp_name(attribute)) if 'Reflect' not in extended_attributes: return uncapitalize(cpp_name(attribute)) content_attribute_name = extended_attributes['Reflect'] or attribute.name.lower() if content_attribute_name in ['class', 'id', 'name']: # Special-case for performance optimization. return 'get%sAttribute' % content_attribute_name.capitalize() arguments.append(scoped_content_attribute_name(interface, attribute)) base_idl_type = attribute.idl_type.base_type if base_idl_type in CONTENT_ATTRIBUTE_GETTER_NAMES: return CONTENT_ATTRIBUTE_GETTER_NAMES[base_idl_type] if 'URL' in attribute.extended_attributes: return 'getURLAttribute' return 'fastGetAttribute'
def dictionary_impl_context(dictionary, interfaces_info): includes.clear() header_includes = set(['platform/heap/Handle.h']) return { 'header_includes': header_includes, 'cpp_class': ext_utilities.cpp_name(dictionary), 'members': [ member_impl_context(member, interfaces_info, header_includes) for member in dictionary.members ], }
def getter_base_name(interface, attribute, arguments): extended_attributes = attribute.extended_attributes if 'ImplementedInPrivateScript' in extended_attributes: return '%sAttributeGetter' % uncapitalize(cpp_name(attribute)) if 'Reflect' not in extended_attributes: return uncapitalize(cpp_name(attribute)) content_attribute_name = extended_attributes[ 'Reflect'] or attribute.name.lower() if content_attribute_name in ['class', 'id', 'name']: # Special-case for performance optimization. return 'get%sAttribute' % content_attribute_name.capitalize() arguments.append(scoped_content_attribute_name(interface, attribute)) base_idl_type = attribute.idl_type.base_type if base_idl_type in CONTENT_ATTRIBUTE_GETTER_NAMES: return CONTENT_ATTRIBUTE_GETTER_NAMES[base_idl_type] if 'URL' in attribute.extended_attributes: return 'getURLAttribute' return 'fastGetAttribute'
def dictionary_context(dictionary): includes.clear() includes.update(DICTIONARY_CPP_INCLUDES) return { 'cpp_class': ext_utilities.cpp_name(dictionary), 'header_includes': set(DICTIONARY_H_INCLUDES), 'members': [ member_context(member) for member in sorted(dictionary.members, key=operator.attrgetter('name')) ], 'ext_class': ext_utilities.ext_class_name(dictionary), }
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), 'ext_value_to_local_cpp_value': idl_type.ext_value_to_local_cpp_value( extended_attributes, 'v8Value', 'propertyValue'), }
def setter_expression(interface, attribute, context): extended_attributes = attribute.extended_attributes arguments = ext_utilities.call_with_arguments( extended_attributes.get('SetterCallWith') or extended_attributes.get('CallWith')) this_setter_base_name = setter_base_name(interface, attribute, arguments) setter_name = scoped_name(interface, attribute, this_setter_base_name) # 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 extended_attributes and not 'ImplementedInPrivateScript' in extended_attributes and not attribute.is_static): arguments.append('*impl') idl_type = attribute.idl_type if 'ImplementedInPrivateScript' in extended_attributes: arguments.append( 'toFrameIfNotDetached(info.GetIsolate()->GetCurrentContext())') arguments.append('impl') arguments.append('cppValue') elif idl_type.base_type == 'EventHandler': getter_name = scoped_name(interface, attribute, cpp_name(attribute)) context['event_handler_getter_expression'] = '%s(%s)' % ( getter_name, ', '.join(arguments)) if (interface.name in ['Window', 'WorkerGlobalScope'] and attribute.name == 'onerror'): includes.add('bindings/core/v8/V8ErrorHandler.h') arguments.append( 'V8EventListenerList::findOrCreateWrapper<V8ErrorHandler>(v8Value, true, ScriptState::current(info.GetIsolate()))' ) else: arguments.append( 'V8EventListenerList::getEventListener(ScriptState::current(info.GetIsolate()), v8Value, true, ListenerFindOrCreate)' ) elif idl_type.is_interface_type: # FIXME: should be able to eliminate WTF::getPtr in most or all cases arguments.append('WTF::getPtr(cppValue)') else: arguments.append('cppValue') if context['is_setter_raises_exception']: arguments.append('exceptionState') return '%s(%s)' % (setter_name, ', '.join(arguments))
def setter_expression(interface, attribute, context): extended_attributes = attribute.extended_attributes arguments = ext_utilities.call_with_arguments( extended_attributes.get('SetterCallWith') or extended_attributes.get('CallWith')) this_setter_base_name = setter_base_name(interface, attribute, arguments) setter_name = scoped_name(interface, attribute, this_setter_base_name) # 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 extended_attributes and not 'ImplementedInPrivateScript' in extended_attributes and not attribute.is_static): arguments.append('*impl') idl_type = attribute.idl_type if 'ImplementedInPrivateScript' in extended_attributes: arguments.append('toFrameIfNotDetached(info.GetIsolate()->GetCurrentContext())') arguments.append('impl') arguments.append('cppValue') elif idl_type.base_type == 'EventHandler': getter_name = scoped_name(interface, attribute, cpp_name(attribute)) context['event_handler_getter_expression'] = '%s(%s)' % ( getter_name, ', '.join(arguments)) if (interface.name in ['Window', 'WorkerGlobalScope'] and attribute.name == 'onerror'): includes.add('bindings/core/v8/V8ErrorHandler.h') arguments.append('V8EventListenerList::findOrCreateWrapper<V8ErrorHandler>(v8Value, true, ScriptState::current(info.GetIsolate()))') else: arguments.append('V8EventListenerList::getEventListener(ScriptState::current(info.GetIsolate()), v8Value, true, ListenerFindOrCreate)') elif idl_type.is_interface_type: # FIXME: should be able to eliminate WTF::getPtr in most or all cases arguments.append('WTF::getPtr(cppValue)') else: arguments.append('cppValue') if context['is_setter_raises_exception']: arguments.append('exceptionState') return '%s(%s)' % (setter_name, ', '.join(arguments))
def constructor_context(interface, constructor): arguments_need_try_catch = any(ext_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': [ext_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': ext_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.ext_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 attribute_context(interface, attribute): idl_type = attribute.idl_type base_idl_type = idl_type.base_type extended_attributes = attribute.extended_attributes idl_type.add_includes_for_type() # [CheckSecurity] is_check_security_for_node = 'CheckSecurity' in extended_attributes if is_check_security_for_node: includes.add('bindings/core/v8/BindingSecurity.h') # [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') # [PerWorldBindings] if 'PerWorldBindings' in extended_attributes: assert idl_type.is_wrapper_type or 'LogActivity' in extended_attributes, '[PerWorldBindings] should only be used with wrapper types: %s.%s' % (interface.name, attribute.name) # [TypeChecking] has_type_checking_unrestricted = ( (has_extended_attribute_value(interface, 'TypeChecking', 'Unrestricted') or has_extended_attribute_value(attribute, 'TypeChecking', 'Unrestricted')) and idl_type.name in ('Float', 'Double')) # [ImplementedInPrivateScript] is_implemented_in_private_script = 'ImplementedInPrivateScript' in extended_attributes if is_implemented_in_private_script: includes.add('bindings/core/v8/PrivateScriptRunner.h') includes.add('core/frame/LocalFrame.h') includes.add('platform/ScriptForbiddenScope.h') # [OnlyExposedToPrivateScript] is_only_exposed_to_private_script = 'OnlyExposedToPrivateScript' in extended_attributes if (base_idl_type == 'EventHandler' and interface.name in ['Window', 'WorkerGlobalScope'] and attribute.name == 'onerror'): includes.add('bindings/core/v8/V8ErrorHandler.h') context = { 'access_control_list': access_control_list(attribute), 'activity_logging_world_list_for_getter': ext_utilities.activity_logging_world_list(attribute, 'Getter'), # [ActivityLogging] 'activity_logging_world_list_for_setter': ext_utilities.activity_logging_world_list(attribute, 'Setter'), # [ActivityLogging] 'activity_logging_world_check': ext_utilities.activity_logging_world_check(attribute), # [ActivityLogging] 'argument_cpp_type': idl_type.cpp_type_args(used_as_rvalue_type=True), 'cached_attribute_validation_method': extended_attributes.get('CachedAttribute'), 'conditional_string': ext_utilities.conditional_string(attribute), 'constructor_type': idl_type.constructor_type_name if is_constructor_attribute(attribute) else None, 'cpp_name': cpp_name(attribute), 'cpp_type': idl_type.cpp_type, 'cpp_type_initializer': idl_type.cpp_type_initializer, 'deprecate_as': ext_utilities.deprecate_as(attribute), # [DeprecateAs] 'enum_validation_expression': idl_type.enum_validation_expression, 'exposed_test': ext_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': ext_utilities.has_extended_attribute_value(attribute, 'CallWith', 'ExecutionContext'), 'is_call_with_script_state': ext_utilities.has_extended_attribute_value(attribute, 'CallWith', 'ScriptState'), 'is_check_security_for_node': is_check_security_for_node, 'is_custom_element_callbacks': is_custom_element_callbacks, 'is_expose_js_accessors': 'ExposeJSAccessors' in extended_attributes, 'is_getter_raises_exception': # [RaisesException] 'RaisesException' in extended_attributes and extended_attributes['RaisesException'] in (None, 'Getter'), 'is_implemented_in_private_script': is_implemented_in_private_script, 'is_initialized_by_event_constructor': 'InitializedByEventConstructor' in extended_attributes, 'is_keep_alive_for_gc': is_keep_alive_for_gc(interface, attribute), 'is_nullable': idl_type.is_nullable, 'is_explicit_nullable': idl_type.is_explicit_nullable, 'is_partial_interface_member': 'PartialInterfaceImplementedAs' in extended_attributes, 'is_per_world_bindings': 'PerWorldBindings' in extended_attributes, 'is_read_only': attribute.is_read_only, 'is_reflect': is_reflect, 'is_replaceable': 'Replaceable' in attribute.extended_attributes, 'is_static': attribute.is_static, 'is_url': 'URL' in extended_attributes, 'is_unforgeable': 'Unforgeable' in extended_attributes, 'measure_as': ext_utilities.measure_as(attribute), # [MeasureAs] 'name': attribute.name, 'only_exposed_to_private_script': is_only_exposed_to_private_script, 'per_context_enabled_function': ext_utilities.per_context_enabled_function_name(attribute), # [PerContextEnabled] 'private_script_ext_value_to_local_cpp_value': idl_type.ext_value_to_local_cpp_value( extended_attributes, 'v8Value', 'cppValue', isolate='scriptState->isolate()', used_in_private_script=True), 'property_attributes': property_attributes(attribute), 'put_forwards': 'PutForwards' in extended_attributes, 'reflect_empty': extended_attributes.get('ReflectEmpty'), 'reflect_invalid': extended_attributes.get('ReflectInvalid', ''), 'reflect_missing': extended_attributes.get('ReflectMissing'), 'reflect_only': extended_attribute_value_as_list(attribute, 'ReflectOnly'), 'runtime_enabled_function': ext_utilities.runtime_enabled_function_name(attribute), # [RuntimeEnabled] 'setter_callback': setter_callback_name(interface, attribute), '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): 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 attribute_context(interface, attribute): idl_type = attribute.idl_type base_idl_type = idl_type.base_type extended_attributes = attribute.extended_attributes idl_type.add_includes_for_type() # [CheckSecurity] is_check_security_for_node = 'CheckSecurity' in extended_attributes if is_check_security_for_node: includes.add('bindings/core/v8/BindingSecurity.h') # [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') # [PerWorldBindings] if 'PerWorldBindings' in extended_attributes: assert idl_type.is_wrapper_type or 'LogActivity' in extended_attributes, '[PerWorldBindings] should only be used with wrapper types: %s.%s' % ( interface.name, attribute.name) # [TypeChecking] has_type_checking_unrestricted = (( has_extended_attribute_value(interface, 'TypeChecking', 'Unrestricted') or has_extended_attribute_value(attribute, 'TypeChecking', 'Unrestricted')) and idl_type.name in ('Float', 'Double')) # [ImplementedInPrivateScript] is_implemented_in_private_script = 'ImplementedInPrivateScript' in extended_attributes if is_implemented_in_private_script: includes.add('bindings/core/v8/PrivateScriptRunner.h') includes.add('core/frame/LocalFrame.h') includes.add('platform/ScriptForbiddenScope.h') # [OnlyExposedToPrivateScript] is_only_exposed_to_private_script = 'OnlyExposedToPrivateScript' in extended_attributes if (base_idl_type == 'EventHandler' and interface.name in ['Window', 'WorkerGlobalScope'] and attribute.name == 'onerror'): includes.add('bindings/core/v8/V8ErrorHandler.h') context = { 'access_control_list': access_control_list(attribute), 'activity_logging_world_list_for_getter': ext_utilities.activity_logging_world_list(attribute, 'Getter'), # [ActivityLogging] 'activity_logging_world_list_for_setter': ext_utilities.activity_logging_world_list(attribute, 'Setter'), # [ActivityLogging] 'activity_logging_world_check': ext_utilities.activity_logging_world_check(attribute), # [ActivityLogging] 'argument_cpp_type': idl_type.cpp_type_args(used_as_rvalue_type=True), 'cached_attribute_validation_method': extended_attributes.get('CachedAttribute'), 'conditional_string': ext_utilities.conditional_string(attribute), 'constructor_type': idl_type.constructor_type_name if is_constructor_attribute(attribute) else None, 'cpp_name': cpp_name(attribute), 'cpp_type': idl_type.cpp_type, 'cpp_type_initializer': idl_type.cpp_type_initializer, 'deprecate_as': ext_utilities.deprecate_as(attribute), # [DeprecateAs] 'enum_validation_expression': idl_type.enum_validation_expression, 'exposed_test': ext_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': ext_utilities.has_extended_attribute_value(attribute, 'CallWith', 'ExecutionContext'), 'is_call_with_script_state': ext_utilities.has_extended_attribute_value(attribute, 'CallWith', 'ScriptState'), 'is_check_security_for_node': is_check_security_for_node, 'is_custom_element_callbacks': is_custom_element_callbacks, 'is_expose_js_accessors': 'ExposeJSAccessors' in extended_attributes, 'is_getter_raises_exception': # [RaisesException] 'RaisesException' in extended_attributes and extended_attributes['RaisesException'] in (None, 'Getter'), 'is_implemented_in_private_script': is_implemented_in_private_script, 'is_initialized_by_event_constructor': 'InitializedByEventConstructor' in extended_attributes, 'is_keep_alive_for_gc': is_keep_alive_for_gc(interface, attribute), 'is_nullable': idl_type.is_nullable, 'is_explicit_nullable': idl_type.is_explicit_nullable, 'is_partial_interface_member': 'PartialInterfaceImplementedAs' in extended_attributes, 'is_per_world_bindings': 'PerWorldBindings' in extended_attributes, 'is_read_only': attribute.is_read_only, 'is_reflect': is_reflect, 'is_replaceable': 'Replaceable' in attribute.extended_attributes, 'is_static': attribute.is_static, 'is_url': 'URL' in extended_attributes, 'is_unforgeable': 'Unforgeable' in extended_attributes, 'measure_as': ext_utilities.measure_as(attribute), # [MeasureAs] 'name': attribute.name, 'only_exposed_to_private_script': is_only_exposed_to_private_script, 'per_context_enabled_function': ext_utilities.per_context_enabled_function_name(attribute), # [PerContextEnabled] 'private_script_ext_value_to_local_cpp_value': idl_type.ext_value_to_local_cpp_value( extended_attributes, 'v8Value', 'cppValue', isolate='scriptState->isolate()', used_in_private_script=True), 'property_attributes': property_attributes(attribute), 'put_forwards': 'PutForwards' in extended_attributes, 'reflect_empty': extended_attributes.get('ReflectEmpty'), 'reflect_invalid': extended_attributes.get('ReflectInvalid', ''), 'reflect_missing': extended_attributes.get('ReflectMissing'), 'reflect_only': extended_attribute_value_as_list(attribute, 'ReflectOnly'), 'runtime_enabled_function': ext_utilities.runtime_enabled_function_name(attribute), # [RuntimeEnabled] 'setter_callback': setter_callback_name(interface, attribute), '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): 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 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_callback_interface or 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(ext_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 = ext_utilities.cpp_name(method) cpp_method_name = ext_utilities.scoped_name(interface, method, base_name) return '%s(%s)' % (cpp_method_name, ', '.join(cpp_arguments))
def interface_context(interface): includes.clear() includes.update(INTERFACE_CPP_INCLUDES) header_includes = set(INTERFACE_H_INCLUDES) parent_interface = interface.parent if parent_interface: header_includes.update(ext_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/core/v8/ScriptController.h', 'bindings/core/v8/WindowProxy.h', 'core/frame/LocalFrame.h']) # [ActiveDOMObject] is_active_dom_object = 'ActiveDOMObject' in extended_attributes # [CheckSecurity] is_check_security = 'CheckSecurity' in extended_attributes if is_check_security: includes.add('bindings/core/v8/BindingSecurity.h') # [DependentLifetime] is_dependent_lifetime = 'DependentLifetime' in extended_attributes # [Iterable] iterator_method = None if 'Iterable' in extended_attributes: iterator_operation = IdlOperation(interface.idl_name) iterator_operation.name = 'iterator' iterator_operation.idl_type = IdlType('Iterator') iterator_operation.extended_attributes['RaisesException'] = None iterator_operation.extended_attributes['CallWith'] = 'ScriptState' iterator_method = ext_methods.method_context(interface, iterator_operation) # [MeasureAs] is_measure_as = 'MeasureAs' in extended_attributes if is_measure_as: includes.add('core/frame/UseCounter.h') # [SetWrapperReferenceFrom] reachable_node_function = extended_attributes.get('SetWrapperReferenceFrom') if reachable_node_function: includes.update(['bindings/core/v8/V8GCController.h', 'core/dom/Element.h']) # [SetWrapperReferenceTo] set_wrapper_reference_to_list = [{ 'name': argument.name, # FIXME: properly should be: # 'cpp_type': argument.idl_type.cpp_type_args(raw_type=True), # (if type is non-wrapper type like NodeFilter, normally RefPtr) # Raw pointers faster though, and NodeFilter hacky anyway. 'cpp_type': argument.idl_type.implemented_as + '*', 'idl_type': argument.idl_type, 'ext_type': ext_types.ext_type(argument.idl_type.name), } for argument in extended_attributes.get('SetWrapperReferenceTo', [])] for set_wrapper_reference_to in set_wrapper_reference_to_list: set_wrapper_reference_to['idl_type'].add_includes_for_type() # [NotScriptWrappable] is_script_wrappable = 'NotScriptWrappable' not in extended_attributes # [SpecialWrapFor] if 'SpecialWrapFor' in extended_attributes: special_wrap_for = extended_attribute_value_as_list(interface, 'SpecialWrapFor') else: special_wrap_for = [] for special_wrap_interface in special_wrap_for: ext_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) wrapper_class_id = ('NodeClassId' if inherits_interface(interface.name, 'Node') else 'ObjectClassId') context = { 'conditional_string': conditional_string(interface), # [Conditional] 'cpp_class': cpp_name(interface), 'gc_type': this_gc_type, # FIXME: Remove 'EventTarget' special handling, http://crbug.com/383699 'has_access_check_callbacks': (is_check_security and interface.name != 'Window' and interface.name != 'EventTarget'), 'has_custom_legacy_call_as_function': has_extended_attribute_value(interface, 'Custom', 'LegacyCallAsFunction'), # [Custom=LegacyCallAsFunction] 'has_custom_to_v8': has_extended_attribute_value(interface, 'Custom', 'ToV8'), # [Custom=ToV8] 'has_custom_wrap': has_extended_attribute_value(interface, 'Custom', 'Wrap'), # [Custom=Wrap] 'has_visit_dom_wrapper': has_visit_dom_wrapper, 'header_includes': header_includes, 'interface_name': interface.name, 'is_active_dom_object': is_active_dom_object, 'is_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'), 'is_script_wrappable': is_script_wrappable, 'iterator_method': iterator_method, 'lifetime': 'Dependent' if (has_visit_dom_wrapper or is_active_dom_object or is_dependent_lifetime) else 'Independent', 'measure_as': ext_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, 'ext_class': ext_utilities.ext_class_name(interface), 'wrapper_class_id': wrapper_class_id, } # Constructors constructors = [constructor_context(interface, constructor) for constructor in interface.constructors # FIXME: shouldn't put named constructors with constructors # (currently needed for Perl compatibility) # Handle named constructors separately if constructor.name == 'Constructor'] if len(constructors) > 1: context['constructor_overloads'] = overloads_context(constructors) # [CustomConstructor] custom_constructors = [{ # Only needed for computing interface length 'number_of_required_arguments': number_of_required_arguments(constructor), } for constructor in interface.custom_constructors] # [EventConstructor] has_event_constructor = 'EventConstructor' in extended_attributes any_type_attributes = [attribute for attribute in interface.attributes if attribute.idl_type.name == 'Any'] if has_event_constructor: includes.add('bindings/core/v8/Dictionary.h') if any_type_attributes: includes.add('bindings/core/v8/SerializedScriptValue.h') # [NamedConstructor] named_constructor = named_constructor_context(interface) if (constructors or custom_constructors or has_event_constructor or named_constructor): includes.add('bindings/core/v8/V8ObjectConstructor.h') includes.add('core/frame/LocalDOMWindow.h') context.update({ 'any_type_attributes': any_type_attributes, 'constructors': constructors, 'has_custom_constructor': bool(custom_constructors), 'has_event_constructor': has_event_constructor, 'interface_length': interface_length(interface, constructors + custom_constructors), 'is_constructor_raises_exception': extended_attributes.get('RaisesException') == 'Constructor', # [RaisesException=Constructor] 'named_constructor': named_constructor, }) constants = [constant_context(constant) for constant in interface.constants] # Constants context.update({ 'constants': constants, 'do_not_check_constants': 'DoNotCheckConstants' in extended_attributes, 'has_constant_configuration': any( not constant['runtime_enabled_function'] for constant in constants), }) # Attributes attributes = [ext_attributes.attribute_context(interface, attribute) for attribute in interface.attributes] context.update({ 'attributes': attributes, 'has_accessors': any(attribute['is_expose_js_accessors'] and attribute['should_be_exposed_to_script'] for attribute in attributes), 'has_attribute_configuration': any( not (attribute['is_expose_js_accessors'] or attribute['is_static'] or attribute['runtime_enabled_function'] or attribute['per_context_enabled_function']) and attribute['should_be_exposed_to_script'] for attribute in attributes), 'has_conditional_attributes': any(attribute['per_context_enabled_function'] or attribute['exposed_test'] for attribute in attributes), 'has_constructor_attributes': any(attribute['constructor_type'] for attribute in attributes), 'has_replaceable_attributes': any(attribute['is_replaceable'] for attribute in attributes), }) # Methods methods = [ext_methods.method_context(interface, method) for method in interface.operations if method.name] # Skip anonymous special operations (methods) compute_method_overloads_context(methods) # Stringifier if interface.stringifier: stringifier = interface.stringifier method = IdlOperation(interface.idl_name) method.name = 'toString' method.idl_type = IdlType('DOMString') method.extended_attributes.update(stringifier.extended_attributes) if stringifier.attribute: method.extended_attributes['ImplementedAs'] = stringifier.attribute.name elif stringifier.operation: method.extended_attributes['ImplementedAs'] = stringifier.operation.name methods.append(ext_methods.method_context(interface, method)) conditionally_enabled_methods = [] custom_registration_methods = [] method_configuration_methods = [] for method in methods: # Skip all but one method in each set of overloaded methods. if 'overload_index' in method and 'overloads' not in method: continue if 'overloads' in method: overloads = method['overloads'] per_context_enabled_function = overloads['per_context_enabled_function_all'] conditionally_exposed_function = overloads['exposed_test_all'] runtime_enabled_function = overloads['runtime_enabled_function_all'] has_custom_registration = overloads['has_custom_registration_all'] else: per_context_enabled_function = method['per_context_enabled_function'] conditionally_exposed_function = method['exposed_test'] runtime_enabled_function = method['runtime_enabled_function'] has_custom_registration = method['has_custom_registration'] if per_context_enabled_function or conditionally_exposed_function: conditionally_enabled_methods.append(method) continue if runtime_enabled_function or has_custom_registration: custom_registration_methods.append(method) continue if method['should_be_exposed_to_script']: method_configuration_methods.append(method) for method in methods: # The value of the Function object’s “length” property is a Number # determined as follows: # 1. Let S be the effective overload set for regular operations (if the # operation is a regular operation) or for static operations (if the # operation is a static operation) with identifier id on interface I and # with argument count 0. # 2. Return the length of the shortest argument list of the entries in S. # FIXME: This calculation doesn't take into account whether runtime # enabled overloads are actually enabled, so length may be incorrect. # E.g., [RuntimeEnabled=Foo] void f(); void f(long x); # should have length 1 if Foo is not enabled, but length 0 if it is. method['length'] = (method['overloads']['minarg'] if 'overloads' in method else method['number_of_required_arguments']) context.update({ 'conditionally_enabled_methods': conditionally_enabled_methods, 'custom_registration_methods': custom_registration_methods, 'has_origin_safe_method_setter': any( method['is_check_security_for_frame'] and not method['is_read_only'] for method in methods), 'has_private_script': any(attribute['is_implemented_in_private_script'] for attribute in attributes) or any(method['is_implemented_in_private_script'] for method in methods), 'method_configuration_methods': method_configuration_methods, 'methods': methods, }) context.update({ 'indexed_property_getter': indexed_property_getter(interface), 'indexed_property_setter': indexed_property_setter(interface), 'indexed_property_deleter': indexed_property_deleter(interface), 'is_override_builtins': 'OverrideBuiltins' in extended_attributes, 'named_property_getter': named_property_getter(interface), 'named_property_setter': named_property_setter(interface), 'named_property_deleter': named_property_deleter(interface), }) return context