def conditional_features_info(info_provider, reader, idl_filenames, target_component): """Read a set of IDL files and compile the mapping between interfaces and the conditional features defined on them. Returns a tuple (features_for_type, types_for_feature, includes): - features_for_type is a mapping of interface->feature - types_for_feature is the reverse mapping: feature->interface - includes is a set of header files which need to be included in the generated implementation code. """ features_for_type = defaultdict(set) types_for_feature = defaultdict(set) includes = set() for idl_filename in idl_filenames: interface = read_idl_file(reader, idl_filename) feature_names = get_conditional_feature_names_from_interface(interface) if feature_names: is_global = interface_is_global(interface) if interface.is_partial: # For partial interfaces, we need to generate different # includes if the parent interface is in a different # component. parent_interface_info = info_provider.interfaces_info[ interface.name] parent_interface = read_idl_file( reader, parent_interface_info.get('full_path')) is_global = is_global or interface_is_global(parent_interface) parent_component = idl_filename_to_component( parent_interface_info.get('full_path')) if interface.is_partial and target_component != parent_component: includes.add('bindings/%s/v8/V8%s.h' % (parent_component, interface.name)) includes.add('bindings/%s/v8/V8%sPartial.h' % (target_component, interface.name)) else: includes.add('bindings/%s/v8/V8%s.h' % (target_component, interface.name)) # If this is a partial interface in the same component as # its parent, then treat it as a non-partial interface. interface.is_partial = False interface_info = ConditionalInterfaceInfo( interface.name, v8_class_name(interface), v8_class_name_or_partial(interface), is_global) for feature_name in feature_names: features_for_type[interface_info].add(feature_name) types_for_feature[feature_name].add(interface_info) return features_for_type, types_for_feature, includes
def origin_trial_features_info(info_provider, reader, idl_filenames, target_component): """Read a set of IDL files and compile the mapping between interfaces and the conditional features defined on them. Returns a tuple (features_for_type, types_for_feature, includes): - features_for_type is a mapping of interface->feature - types_for_feature is the reverse mapping: feature->interface - includes is a set of header files which need to be included in the generated implementation code. """ features_for_type = defaultdict(set) types_for_feature = defaultdict(set) include_files = set() runtime_features = info_provider.component_info['runtime_enabled_features'] for idl_filename in idl_filenames: interface, includes = read_idl_file(reader, idl_filename) feature_names = get_origin_trial_feature_names_from_interface( interface, runtime_features) # If this interface is a mixin, we don't generate V8 bindings code for # it. if interface.is_mixin: continue # If this interface include another one, # it inherits any conditional features from it. for include in includes: assert include.interface == interface.name mixin, _ = read_idl_file( reader, info_provider.interfaces_info[include.mixin].get('full_path')) feature_names |= get_origin_trial_feature_names_from_interface( mixin, runtime_features) feature_names = list(feature_names) if feature_names: is_global = interface_is_global(interface) if interface.is_partial: # For partial interfaces, we need to generate different # |include_files| if the parent interface is in a different # component. parent_interface_info = \ info_provider.interfaces_info[interface.name] parent_interface, _ = read_idl_file( reader, parent_interface_info.get('full_path')) is_global = is_global or interface_is_global(parent_interface) parent_component = idl_filename_to_component( parent_interface_info.get('full_path')) if interface.is_partial and target_component != parent_component: include_files.add('bindings/%s/v8/%s' % (parent_component, binding_header_filename(interface.name))) include_files.add( 'bindings/%s/v8/%s' % (target_component, binding_header_filename(interface.name + 'Partial'))) else: include_files.add('bindings/%s/v8/%s' % (target_component, binding_header_filename(interface.name))) # If this is a partial interface in the same component as # its parent, then treat it as a non-partial interface. interface.is_partial = False interface_info = OriginTrialInterfaceInfo( interface.name, v8_class_name(interface), v8_class_name_or_partial(interface), is_global) for feature_name in feature_names: features_for_type[interface_info].add(feature_name) types_for_feature[feature_name].add(interface_info) return features_for_type, types_for_feature, include_files
def origin_trial_features_info(info_provider, reader, idl_filenames, target_component): """Read a set of IDL files and compile the mapping between interfaces and the conditional features defined on them. Returns a tuple (features_for_type, types_for_feature, includes): - features_for_type is a mapping of interface->feature - types_for_feature is the reverse mapping: feature->interface - includes is a set of header files which need to be included in the generated implementation code. """ features_for_type = defaultdict(set) types_for_feature = defaultdict(set) includes = set() # Gather interfaces which are implemented by other interfaces. implemented_interfaces = set() for name, interface_info in info_provider.interfaces_info.iteritems(): # Skip special entries such as 'dictionaries' or 'ancestors'. if name.lower() == name: continue implemented_interfaces.update(interface_info.get('implements_interfaces')) for idl_filename in idl_filenames: interface, implements = read_idl_file(reader, idl_filename) feature_names = get_origin_trial_feature_names_from_interface(interface) # If this interface is implemented by other interfaces, we don't generate # V8 bindings code for it. if interface.name in implemented_interfaces: continue # If this interface implements another one, # it inherits any conditional features from it. for implement in implements: assert implement.left_interface == interface.name implemented_interface, _ = read_idl_file( reader, info_provider.interfaces_info[implement.right_interface].get('full_path')) feature_names |= get_origin_trial_feature_names_from_interface(implemented_interface) feature_names = list(feature_names) if feature_names: is_global = interface_is_global(interface) if interface.is_partial: # For partial interfaces, we need to generate different # includes if the parent interface is in a different # component. parent_interface_info = info_provider.interfaces_info[interface.name] parent_interface, _ = read_idl_file( reader, parent_interface_info.get('full_path')) is_global = is_global or interface_is_global(parent_interface) parent_component = idl_filename_to_component( parent_interface_info.get('full_path')) if interface.is_partial and target_component != parent_component: includes.add('bindings/%s/v8/%s' % (parent_component, binding_header_filename(interface.name))) includes.add('bindings/%s/v8/%s' % (target_component, binding_header_filename(interface.name + 'Partial'))) else: includes.add('bindings/%s/v8/%s' % (target_component, binding_header_filename(interface.name))) # If this is a partial interface in the same component as # its parent, then treat it as a non-partial interface. interface.is_partial = False interface_info = OriginTrialInterfaceInfo(interface.name, v8_class_name(interface), v8_class_name_or_partial( interface), is_global) for feature_name in feature_names: features_for_type[interface_info].add(feature_name) types_for_feature[feature_name].add(interface_info) return features_for_type, types_for_feature, includes
def origin_trial_features_info(info_provider, reader, idl_filenames, target_component): """Read a set of IDL files and compile the mapping between interfaces and the conditional features defined on them. Returns a tuple (features_for_type, types_for_feature, includes): - features_for_type is a mapping of interface->feature - types_for_feature is the reverse mapping: feature->interface - includes is a set of header files which need to be included in the generated implementation code. """ features_for_type = defaultdict(set) types_for_feature = defaultdict(set) includes = set() for idl_filename in idl_filenames: interface, implements = read_idl_file(reader, idl_filename) feature_names = get_origin_trial_feature_names_from_interface( interface) # If this interface has NoInterfaceObject then we don't want to add # includes for it because it is a base interface to be implemented # by other interfaces, and does not generate an ECMAScript binding. if 'NoInterfaceObject' in interface.extended_attributes: continue # If this interface implements another one, # it inherits any conditional features from it. for implement in implements: assert implement.left_interface == interface.name implemented_interface, _ = read_idl_file( reader, info_provider.interfaces_info[ implement.right_interface].get('full_path')) feature_names |= get_origin_trial_feature_names_from_interface( implemented_interface) feature_names = list(feature_names) if feature_names: is_global = interface_is_global(interface) if interface.is_partial: # For partial interfaces, we need to generate different # includes if the parent interface is in a different # component. parent_interface_info = info_provider.interfaces_info[ interface.name] parent_interface, _ = read_idl_file( reader, parent_interface_info.get('full_path')) is_global = is_global or interface_is_global(parent_interface) parent_component = idl_filename_to_component( parent_interface_info.get('full_path')) if interface.is_partial and target_component != parent_component: includes.add('bindings/%s/v8/%s' % (parent_component, binding_header_basename(interface.name))) includes.add( 'bindings/%s/v8/%s' % (target_component, binding_header_basename(interface.name + 'Partial'))) else: includes.add('bindings/%s/v8/%s' % (target_component, binding_header_basename(interface.name))) # If this is a partial interface in the same component as # its parent, then treat it as a non-partial interface. interface.is_partial = False interface_info = OriginTrialInterfaceInfo( interface.name, v8_class_name(interface), v8_class_name_or_partial(interface), is_global) for feature_name in feature_names: features_for_type[interface_info].add(feature_name) types_for_feature[feature_name].add(interface_info) return features_for_type, types_for_feature, includes
def create_interface_context(self, interface, component, interfaces): '''Creates a Jinja context which is based on an interface.''' assert component in ['core', 'modules'] name = '%s%s' % (v8_utilities.cpp_name(interface), 'Partial' if interface.is_partial else '') # Constructors has_constructor_callback = False if not interface.is_partial: constructors = any(constructor.name == 'Constructor' for constructor in interface.constructors) custom_constructors = interface.custom_constructors html_constructor = 'HTMLConstructor' in interface.extended_attributes has_constructor_callback = constructors or custom_constructors or html_constructor attributes = [] methods = [] has_cross_origin_indexed_getter = False has_cross_origin_named_enum = False has_cross_origin_named_getter = False has_cross_origin_named_setter = False has_origin_safe_method_setter = False has_security_check = False indexed_property_getter = None is_global = False named_property_getter = None component_info = self._info_provider.component_info if interface.name in SNAPSHOTTED_INTERFACES: attributes = [ v8_attributes.attribute_context(interface, attribute, interfaces, component_info) for attribute in interface.attributes ] methods = v8_interface.methods_context(interface, component_info)['methods'] is_global = 'Global' in interface.extended_attributes named_property_getter = v8_interface.property_getter( interface.named_property_getter, ['name']) indexed_property_getter = v8_interface.property_getter( interface.indexed_property_getter, ['index']) if not interface.is_partial: has_origin_safe_method_setter = is_global and any( method['is_check_security_for_receiver'] and not method['is_unforgeable'] for method in methods) has_security_check = ('CheckSecurity' in interface.extended_attributes and interface.name != 'EventTarget') has_cross_origin_named_getter = ( any(method['is_cross_origin'] for method in methods) or any(attribute['has_cross_origin_getter'] for attribute in attributes)) has_cross_origin_named_setter = any( attribute['has_cross_origin_setter'] for attribute in attributes) has_cross_origin_indexed_getter = indexed_property_getter and indexed_property_getter[ 'is_cross_origin'] has_cross_origin_named_enum = has_cross_origin_named_getter or has_cross_origin_named_setter if named_property_getter and named_property_getter[ 'is_cross_origin']: has_cross_origin_named_getter = True return { 'attributes': attributes, 'component': component, 'has_origin_safe_method_setter': has_origin_safe_method_setter, 'has_constructor_callback': has_constructor_callback, 'has_cross_origin_named_getter': has_cross_origin_named_getter, 'has_cross_origin_named_setter': has_cross_origin_named_setter, 'has_cross_origin_named_enumerator': has_cross_origin_named_enum, 'has_cross_origin_indexed_getter': has_cross_origin_indexed_getter, 'has_security_check': has_security_check, 'indexed_property_getter': indexed_property_getter, 'indexed_property_setter': v8_interface.property_setter(interface.indexed_property_setter, interface), 'indexed_property_deleter': v8_interface.property_deleter(interface.indexed_property_deleter), 'internal_namespace': v8_interface.internal_namespace(interface), 'is_partial': interface.is_partial, 'methods': methods, 'name': name, 'named_constructor': v8_interface.named_constructor_context(interface), 'named_property_getter': named_property_getter, 'named_property_setter': v8_interface.property_setter(interface.named_property_setter, interface), 'named_property_deleter': v8_interface.property_deleter(interface.named_property_deleter), 'v8_class': v8_utilities.v8_class_name_or_partial(interface), }
def create_interface_context(self, interface, interfaces): '''Creates a Jinja context which is based on an interface.''' name = '%s%s' % (v8_utilities.cpp_name(interface), 'Partial' if interface.is_partial else '') # Constructors constructors = any(constructor.name == 'Constructor' for constructor in interface.constructors) custom_constructors = interface.custom_constructors html_constructor = 'HTMLConstructor' in interface.extended_attributes has_constructor_callback = constructors or custom_constructors or html_constructor attributes = [] methods = [] has_cross_origin_indexed_getter = False has_cross_origin_named_enum = False has_cross_origin_named_getter = False has_cross_origin_named_setter = False has_origin_safe_method_setter = False has_security_check = False indexed_property_getter = None is_global = False named_property_getter = None if interface.name in SNAPSHOTTED_INTERFACES: attributes = [v8_attributes.attribute_context(interface, attribute, interfaces) for attribute in interface.attributes] methods = v8_interface.methods_context(interface)['methods'] is_global = ('PrimaryGlobal' in interface.extended_attributes or 'Global' in interface.extended_attributes) named_property_getter = v8_interface.property_getter( interface.named_property_getter, ['name']) indexed_property_getter = v8_interface.property_getter( interface.indexed_property_getter, ['index']) if not interface.is_partial: has_origin_safe_method_setter = is_global and any( method['is_check_security_for_receiver'] and not method['is_unforgeable'] for method in methods) has_security_check = ('CheckSecurity' in interface.extended_attributes and interface.name != 'EventTarget') has_cross_origin_named_getter = (any(method['is_cross_origin'] for method in methods) or any(attribute['has_cross_origin_getter'] for attribute in attributes)) has_cross_origin_named_setter = any(attribute['has_cross_origin_setter'] for attribute in attributes) has_cross_origin_indexed_getter = indexed_property_getter and indexed_property_getter['is_cross_origin'] has_cross_origin_named_enum = has_cross_origin_named_getter or has_cross_origin_named_setter if named_property_getter and named_property_getter['is_cross_origin']: has_cross_origin_named_getter = True return { 'attributes': attributes, 'has_origin_safe_method_setter': has_origin_safe_method_setter, 'has_constructor_callback': has_constructor_callback, 'has_cross_origin_named_getter': has_cross_origin_named_getter, 'has_cross_origin_named_setter': has_cross_origin_named_setter, 'has_cross_origin_named_enumerator': has_cross_origin_named_enum, 'has_cross_origin_indexed_getter': has_cross_origin_indexed_getter, 'has_security_check': has_security_check, 'indexed_property_getter': indexed_property_getter, 'indexed_property_setter': v8_interface.property_setter(interface.indexed_property_setter, interface), 'indexed_property_deleter': v8_interface.property_deleter(interface.indexed_property_deleter), 'is_array_buffer_or_view': interface.idl_type.is_array_buffer_or_view, 'is_callback': interface.is_callback, 'is_partial': interface.is_partial, 'is_snapshotted': interface in SNAPSHOTTED_INTERFACES, 'methods': methods, 'name': name, 'named_constructor': v8_interface.named_constructor_context(interface), 'named_property_getter': named_property_getter, 'named_property_setter': v8_interface.property_setter(interface.named_property_setter, interface), 'named_property_deleter': v8_interface.property_deleter(interface.named_property_deleter), 'v8_name': v8_utilities.v8_class_name_or_partial(interface), }
def conditional_features_info(info_provider, reader, idl_filenames, target_component): """Read a set of IDL files and compile the mapping between interfaces and the conditional features defined on them. Returns a tuple (features_for_type, types_for_feature, includes): - features_for_type is a mapping of interface->feature - types_for_feature is the reverse mapping: feature->interface - includes is a set of header files which need to be included in the generated implementation code. """ features_for_type = defaultdict(set) types_for_feature = defaultdict(set) includes = set() for idl_filename in idl_filenames: interface, implements = read_idl_file(reader, idl_filename) feature_names = get_conditional_feature_names_from_interface(interface) # If this interface implements another one, # it inherits any conditional features from it. for implement in implements: assert implement.left_interface == interface.name implemented_interface, _ = read_idl_file( reader, info_provider.interfaces_info[implement.right_interface].get('full_path')) feature_names |= get_conditional_feature_names_from_interface(implemented_interface) feature_names = list(feature_names) if feature_names: is_global = interface_is_global(interface) if interface.is_partial: # For partial interfaces, we need to generate different # includes if the parent interface is in a different # component. parent_interface_info = info_provider.interfaces_info[interface.name] parent_interface, _ = read_idl_file( reader, parent_interface_info.get('full_path')) is_global = is_global or interface_is_global(parent_interface) parent_component = idl_filename_to_component( parent_interface_info.get('full_path')) if interface.is_partial and target_component != parent_component: includes.add('bindings/%s/v8/V8%s.h' % (parent_component, interface.name)) includes.add('bindings/%s/v8/V8%sPartial.h' % (target_component, interface.name)) else: includes.add('bindings/%s/v8/V8%s.h' % (target_component, interface.name)) # If this is a partial interface in the same component as # its parent, then treat it as a non-partial interface. interface.is_partial = False interface_info = ConditionalInterfaceInfo(interface.name, v8_class_name(interface), v8_class_name_or_partial( interface), is_global) for feature_name in feature_names: features_for_type[interface_info].add(feature_name) types_for_feature[feature_name].add(interface_info) return features_for_type, types_for_feature, includes