third_party/blink/renderer/bindings/scripts/web_idl/function_like.py
def are_distinguishable_types(idl_type1, idl_type2):
        """
        Returns True if the two given types are distinguishable.
        https://webidl.spec.whatwg.org/#dfn-distinguishable
        """
        assert isinstance(idl_type1, IdlType)
        assert isinstance(idl_type2, IdlType)

        # step 1. If one type includes a nullable type and the other type either
        #   includes a nullable type, is a union type with flattened member
        #   types including a dictionary type, or is a dictionary type, ...
        if ((idl_type1.does_include_nullable_type
             and idl_type2.does_include_nullable_or_dict)
                or (idl_type2.does_include_nullable_type
                    and idl_type1.does_include_nullable_or_dict)):
            return False

        type1 = idl_type1.unwrap()
        type2 = idl_type2.unwrap()

        # step 2. If both types are either a union type or nullable union type,
        #   ...
        if type1.is_union and type2.is_union:
            for member1 in type1.member_types:
                for member2 in type2.member_types:
                    if not OverloadGroup.are_distinguishable_types(
                            member1, member2):
                        return False
            return True

        # step 3. If one type is a union type or nullable union type, ...
        if type1.is_union or type2.is_union:
            union = type1 if type1.is_union else type2
            other = type2 if type1.is_union else type1
            for member in union.member_types:
                if not OverloadGroup.are_distinguishable_types(member, other):
                    return False
            return True

        # step 4. Consider the two "innermost" types ...
        def is_string_type(idl_type):
            return idl_type.is_string or idl_type.is_enumeration

        def is_interface_like(idl_type):
            return idl_type.is_interface or idl_type.is_buffer_source_type

        def is_dictionary_like(idl_type):
            return (idl_type.is_dictionary or idl_type.is_record
                    or idl_type.is_callback_interface)

        def is_sequence_like(idl_type):
            return idl_type.is_sequence or idl_type.is_frozen_array

        if not (type2.is_boolean or type2.is_numeric or type2.is_string
                or type2.is_object or type2.is_symbol
                or is_interface_like(type2) or type2.is_callback_function
                or is_dictionary_like(type2) or is_sequence_like(type2)):
            return False  # Out of the table

        if type1.is_boolean:
            return not type2.is_boolean
        if type1.is_numeric:
            return not type2.is_numeric
        if is_string_type(type1):
            return not is_string_type(type2)
        if type1.is_object:
            return (type2.is_boolean or type2.is_numeric
                    or is_string_type(type2) or type2.is_symbol)
        if type1.is_symbol:
            return not type2.is_symbol
        if is_interface_like(type1):
            if type2.is_object:
                return False
            if not is_interface_like(type2):
                return True
            # Additional requirements: The two identified interface-like types
            # are not the same, and no single platform object implements both
            # interface-like types.
            if type1.keyword_typename or type2.keyword_typename:
                return type1.keyword_typename != type2.keyword_typename
            interface1 = type1.type_definition_object
            interface2 = type2.type_definition_object
            return not (
                interface1 in interface2.inclusive_inherited_interfaces
                or interface2 in interface1.inclusive_inherited_interfaces)
        if type1.is_callback_function:
            return not (type2.is_object or type2.is_callback_function
                        or is_dictionary_like(type2))
        if is_dictionary_like(type1):
            return not (type2.is_object or type2.is_callback_function
                        or is_dictionary_like(type2))
        if is_sequence_like(type1):
            return not (type2.is_object or is_sequence_like(type2))
        return False

        Returns True if the two given types are distinguishable.
        https://webidl.spec.whatwg.org/#dfn-distinguishable
        
Returns True if the two given types are distinguishable.
Returns True if the two given types are distinguishable .
def are_distinguishable_types(idl_type1, idl_type2):
        assert isinstance(idl_type1, IdlType)
        assert isinstance(idl_type2, IdlType)
        if ((idl_type1.does_include_nullable_type
             and idl_type2.does_include_nullable_or_dict)
                or (idl_type2.does_include_nullable_type
                    and idl_type1.does_include_nullable_or_dict)):
            return False
        type1 = idl_type1.unwrap()
        type2 = idl_type2.unwrap()
        if type1.is_union and type2.is_union:
            for member1 in type1.member_types:
                for member2 in type2.member_types:
                    if not OverloadGroup.are_distinguishable_types(
                            member1, member2):
                        return False
            return True
        if type1.is_union or type2.is_union:
            union = type1 if type1.is_union else type2
            other = type2 if type1.is_union else type1
            for member in union.member_types:
                if not OverloadGroup.are_distinguishable_types(member, other):
                    return False
            return True
        def is_string_type(idl_type):
            return idl_type.is_string or idl_type.is_enumeration
        def is_interface_like(idl_type):
            return idl_type.is_interface or idl_type.is_buffer_source_type
        def is_dictionary_like(idl_type):
            return (idl_type.is_dictionary or idl_type.is_record
                    or idl_type.is_callback_interface)
        def is_sequence_like(idl_type):
            return idl_type.is_sequence or idl_type.is_frozen_array
        if not (type2.is_boolean or type2.is_numeric or type2.is_string
                or type2.is_object or type2.is_symbol
                or is_interface_like(type2) or type2.is_callback_function
                or is_dictionary_like(type2) or is_sequence_like(type2)):
            return False  
        if type1.is_boolean:
            return not type2.is_boolean
        if type1.is_numeric:
            return not type2.is_numeric
        if is_string_type(type1):
            return not is_string_type(type2)
        if type1.is_object:
            return (type2.is_boolean or type2.is_numeric
                    or is_string_type(type2) or type2.is_symbol)
        if type1.is_symbol:
            return not type2.is_symbol
        if is_interface_like(type1):
            if type2.is_object:
                return False
            if not is_interface_like(type2):
                return True
            if type1.keyword_typename or type2.keyword_typename:
                return type1.keyword_typename != type2.keyword_typename
            interface1 = type1.type_definition_object
            interface2 = type2.type_definition_object
            return not (
                interface1 in interface2.inclusive_inherited_interfaces
                or interface2 in interface1.inclusive_inherited_interfaces)
        if type1.is_callback_function:
            return not (type2.is_object or type2.is_callback_function
                        or is_dictionary_like(type2))
        if is_dictionary_like(type1):
            return not (type2.is_object or type2.is_callback_function
                        or is_dictionary_like(type2))
        if is_sequence_like(type1):
            return not (type2.is_object or is_sequence_like(type2))
        return False
def are_distinguishable_types ( idl_type1 , idl_type2 ) : assert isinstance ( idl_type1 , IdlType ) assert isinstance ( idl_type2 , IdlType ) if ( ( idl_type1 . does_include_nullable_type and idl_type2 . does_include_nullable_or_dict ) or ( idl_type2 . does_include_nullable_type and idl_type1 . does_include_nullable_or_dict ) ) : return False type1 = idl_type1 . unwrap ( ) type2 = idl_type2 . unwrap ( ) if type1 . is_union and type2 . is_union : for member1 in type1 . member_types : for member2 in type2 . member_types : if not OverloadGroup . are_distinguishable_types ( member1 , member2 ) : return False return True if type1 . is_union or type2 . is_union : union = type1 if type1 . is_union else type2 other = type2 if type1 . is_union else type1 for member in union . member_types : if not OverloadGroup . are_distinguishable_types ( member , other ) : return False return True def is_string_type ( idl_type ) : return idl_type . is_string or idl_type . is_enumeration def is_interface_like ( idl_type ) : return idl_type . is_interface or idl_type . is_buffer_source_type def is_dictionary_like ( idl_type ) : return ( idl_type . is_dictionary or idl_type . is_record or idl_type . is_callback_interface ) def is_sequence_like ( idl_type ) : return idl_type . is_sequence or idl_type . is_frozen_array if not ( type2 . is_boolean or type2 . is_numeric or type2 . is_string or type2 . is_object or type2 . is_symbol or is_interface_like ( type2 ) or type2 . is_callback_function or is_dictionary_like ( type2 ) or is_sequence_like ( type2 ) ) : return False if type1 . is_boolean : return not type2 . is_boolean if type1 . is_numeric : return not type2 . is_numeric if is_string_type ( type1 ) : return not is_string_type ( type2 ) if type1 . is_object : return ( type2 . is_boolean or type2 . is_numeric or is_string_type ( type2 ) or type2 . is_symbol ) if type1 . is_symbol : return not type2 . is_symbol if is_interface_like ( type1 ) : if type2 . is_object : return False if not is_interface_like ( type2 ) : return True if type1 . keyword_typename or type2 . keyword_typename : return type1 . keyword_typename != type2 . keyword_typename interface1 = type1 . type_definition_object interface2 = type2 . type_definition_object return not ( interface1 in interface2 . inclusive_inherited_interfaces or interface2 in interface1 . inclusive_inherited_interfaces ) if type1 . is_callback_function : return not ( type2 . is_object or type2 . is_callback_function or is_dictionary_like ( type2 ) ) if is_dictionary_like ( type1 ) : return not ( type2 . is_object or type2 . is_callback_function or is_dictionary_like ( type2 ) ) if is_sequence_like ( type1 ) : return not ( type2 . is_object or is_sequence_like ( type2 ) ) return False
Returns True if the two given types are distinguishable.
Returns True if the two given types are distinguishable .
"""
        Returns True if the two given types are distinguishable.
        https://webidl.spec.whatwg.org/#dfn-distinguishable
        """ # step 1. If one type includes a nullable type and the other type either #   includes a nullable type, is a union type with flattened member #   types including a dictionary type, or is a dictionary type, ... # step 2. If both types are either a union type or nullable union type, #   ... # step 3. If one type is a union type or nullable union type, ... # step 4. Consider the two "innermost" types ... # Out of the table # Additional requirements: The two identified interface-like types # are not the same, and no single platform object implements both # interface-like types.
idl_type1
idl_type2