Пример #1
0
def callback_function_context(callback_function):
    includes.clear()
    includes.update(CALLBACK_FUNCTION_CPP_INCLUDES)
    idl_type = callback_function.idl_type
    idl_type_str = str(idl_type)

    for argument in callback_function.arguments:
        argument.idl_type.add_includes_for_type(
            callback_function.extended_attributes)

    context = {
        # While both |callback_function_name| and |cpp_class| are identical at
        # the moment, the two are being defined because their values may change
        # in the future (e.g. if we support [ImplementedAs=] in callback
        # functions).
        'callback_function_name': callback_function.name,
        'cpp_class': callback_function.name,
        'cpp_includes': sorted(includes),
        'forward_declarations': sorted(forward_declarations(callback_function)),
        'header_includes': sorted(CALLBACK_FUNCTION_H_INCLUDES),
        'idl_type': idl_type_str,
    }

    if idl_type_str != 'void':
        context.update({
            'return_cpp_type': idl_type.cpp_type + '&',
            'return_value': idl_type.v8_value_to_local_cpp_value(
                callback_function.extended_attributes,
                'v8ReturnValue', 'cppValue',
                isolate='script_state_->GetIsolate()',
                bailout_return_value='false'),
        })

    context.update(arguments_context(callback_function.arguments, context.get('return_cpp_type')))
    return context
def callback_function_context(callback_function):
    includes.clear()
    includes.update(CALLBACK_FUNCTION_CPP_INCLUDES)
    idl_type = callback_function.idl_type
    idl_type_str = str(idl_type)
    forward_declarations = []
    for argument in callback_function.arguments:
        if argument.idl_type.is_interface_type:
            forward_declarations.append(argument.idl_type)
        argument.idl_type.add_includes_for_type(callback_function.extended_attributes)

    context = {
        'cpp_class': callback_function.name,
        'cpp_includes': sorted(includes),
        'forward_declarations': sorted(forward_declarations),
        'header_includes': sorted(CALLBACK_FUNCTION_H_INCLUDES),
        'idl_type': idl_type_str,
    }

    if idl_type_str != 'void':
        context.update({
            'return_cpp_type': idl_type.cpp_type + '&',
            'return_value': idl_type.v8_value_to_local_cpp_value(
                callback_function.extended_attributes,
                'v8ReturnValue', 'cppValue',
                isolate='m_scriptState->isolate()',
                bailout_return_value='false'),
        })

    context.update(arguments_context(callback_function.arguments, context.get('return_cpp_type')))
    return context
def callback_interface_context(callback_interface, _):
    includes.clear()
    includes.update(CALLBACK_INTERFACE_CPP_INCLUDES)

    # https://heycam.github.io/webidl/#dfn-single-operation-callback-interface
    is_single_operation = True
    if (callback_interface.parent or
            len(callback_interface.attributes) > 0 or
            len(callback_interface.operations) == 0):
        is_single_operation = False
    else:
        operations = callback_interface.operations
        basis = operations[0]
        for op in operations[1:]:
            if op.name != basis.name:
                is_single_operation = False
                break

    return {
        'cpp_class': callback_interface.name,
        'forward_declarations': sorted(forward_declarations(callback_interface)),
        'header_includes': set(CALLBACK_INTERFACE_H_INCLUDES),
        'is_single_operation_callback_interface': is_single_operation,
        'methods': [method_context(operation)
                    for operation in callback_interface.operations],
        'v8_class': v8_utilities.v8_class_name(callback_interface),
    }
Пример #4
0
def callback_function_context(callback_function):
    includes.clear()
    includes.update(CALLBACK_FUNCTION_CPP_INCLUDES)
    idl_type = callback_function.idl_type
    idl_type_str = str(idl_type)

    for argument in callback_function.arguments:
        argument.idl_type.add_includes_for_type(
            callback_function.extended_attributes)

    context = {
        # While both |callback_function_name| and |cpp_class| are identical at
        # the moment, the two are being defined because their values may change
        # in the future (e.g. if we support [ImplementedAs=] in callback
        # functions).
        'callback_function_name': callback_function.name,
        'cpp_class': callback_function.name,
        'cpp_includes': sorted(includes),
        'forward_declarations': sorted(forward_declarations(callback_function)),
        'header_includes': sorted(CALLBACK_FUNCTION_H_INCLUDES),
        'idl_type': idl_type_str,
    }

    if idl_type_str != 'void':
        context.update({
            'return_cpp_type': idl_type.cpp_type + '&',
            'return_value': idl_type.v8_value_to_local_cpp_value(
                callback_function.extended_attributes,
                'v8ReturnValue', 'cppValue',
                isolate='script_state_->GetIsolate()',
                bailout_return_value='false'),
        })

    context.update(arguments_context(callback_function.arguments, context.get('return_cpp_type')))
    return context
Пример #5
0
def callback_function_context(callback_function):
    includes.clear()
    includes.update(CALLBACK_FUNCTION_CPP_INCLUDES)
    idl_type = callback_function.idl_type
    idl_type_str = str(idl_type)
    forward_declarations = []
    for argument in callback_function.arguments:
        if argument.idl_type.is_interface_type:
            forward_declarations.append(argument.idl_type)
        argument.idl_type.add_includes_for_type(callback_function.extended_attributes)

    context = {
        "cpp_class": callback_function.name,
        "cpp_includes": sorted(includes),
        "forward_declarations": sorted(forward_declarations),
        "header_includes": sorted(CALLBACK_FUNCTION_H_INCLUDES),
        "idl_type": idl_type_str,
    }

    if idl_type_str != "void":
        context.update(
            {
                "return_cpp_type": idl_type.cpp_type + "&",
                "return_value": idl_type.v8_value_to_local_cpp_value(
                    callback_function.extended_attributes,
                    "v8ReturnValue",
                    "cppValue",
                    isolate="scriptState->isolate()",
                    bailout_return_value="false",
                ),
            }
        )

    context.update(arguments_context(callback_function.arguments, context.get("return_cpp_type")))
    return context
Пример #6
0
def generate_interface(interface):
    includes.clear()
    includes.update(INTERFACE_CPP_INCLUDES)
    v8_class_name = v8_utilities.v8_class_name(interface)

    template_contents = {
        'cpp_class_name': cpp_name(interface),
        'header_includes': INTERFACE_H_INCLUDES,
        'interface_name': interface.name,
        'v8_class_name': v8_class_name,
    }

    template_contents.update({
        'constants': [generate_constant(constant) for constant in interface.constants],
        'do_not_check_constants': 'DoNotCheckConstants' in interface.extended_attributes,
    })

    attributes = [v8_attributes.generate_attribute(interface, attribute)
                  for attribute in interface.attributes]
    template_contents.update({
        'attributes': attributes,
        'has_constructor_attributes': any(attribute['is_constructor'] for attribute in attributes),
        'has_per_context_enabled_attributes': any(attribute['per_context_enabled_function_name'] for attribute in attributes),
        'has_replaceable_attributes': any(attribute['is_replaceable'] for attribute in attributes),
        'has_runtime_enabled_attributes': any(attribute['runtime_enabled_function_name'] for attribute in attributes),
    })

    template_contents['methods'] = [v8_methods.generate_method(method)
                                    for method in interface.operations]

    return template_contents
Пример #7
0
def dictionary_impl_context(dictionary, interfaces_info):
    def remove_duplicate_members(members):
        # When [ImplementedAs] is used, cpp_name can conflict. For example,
        # dictionary D { long foo; [ImplementedAs=foo, DeprecateAs=Foo] long oldFoo; };
        # This function removes such duplications, checking they have the same type.
        members_dict = {}
        for member in members:
            cpp_name = member['cpp_name']
            duplicated_member = members_dict.get(cpp_name)
            if duplicated_member and duplicated_member != member:
                raise Exception('Member name conflict: %s' % cpp_name)
            members_dict[cpp_name] = member
        return sorted(members_dict.values(), key=lambda member: member['cpp_name'])

    includes.clear()
    header_includes = set(['platform/heap/Handle.h'])
    members = [member_impl_context(member, interfaces_info, header_includes)
               for member in dictionary.members]
    members = remove_duplicate_members(members)
    context = {
        'header_includes': header_includes,
        'cpp_class': v8_utilities.cpp_name(dictionary),
        'members': members,
    }
    if dictionary.parent:
        context['parent_cpp_class'] = v8_utilities.cpp_name_from_interfaces_info(
            dictionary.parent, interfaces_info)
        parent_interface_info = interfaces_info.get(dictionary.parent)
        if parent_interface_info:
            context['header_includes'].add(
                parent_interface_info['include_path'])
    return context
Пример #8
0
def dictionary_impl_context(dictionary, interfaces_info):
    def remove_duplicate_members(members):
        # When [ImplementedAs] is used, cpp_name can conflict. For example,
        # dictionary D { long foo; [ImplementedAs=foo, DeprecateAs=Foo] long oldFoo; };
        # This function removes such duplications, checking they have the same type.
        members_dict = {}
        for member in members:
            cpp_name = member['cpp_name']
            duplicated_member = members_dict.get(cpp_name)
            if duplicated_member and duplicated_member != member:
                raise Exception('Member name conflict: %s' % cpp_name)
            members_dict[cpp_name] = member
        return sorted(members_dict.values(), key=lambda member: member['cpp_name'])

    includes.clear()
    header_includes = set(['platform/heap/Handle.h'])
    members = [member_impl_context(member, interfaces_info, header_includes)
               for member in dictionary.members]
    members = remove_duplicate_members(members)
    context = {
        'header_includes': header_includes,
        'cpp_class': v8_utilities.cpp_name(dictionary),
        'members': members,
    }
    if dictionary.parent:
        context['parent_cpp_class'] = v8_utilities.cpp_name_from_interfaces_info(
            dictionary.parent, interfaces_info)
        parent_interface_info = interfaces_info.get(dictionary.parent)
        if parent_interface_info:
            context['header_includes'].add(
                parent_interface_info['include_path'])
    return context
Пример #9
0
def dictionary_context(dictionary, interfaces_info):
    includes.clear()
    includes.update(DICTIONARY_CPP_INCLUDES)

    members = [member_context(dictionary, member)
               for member in sorted(dictionary.members,
                                    key=operator.attrgetter('name'))]

    for member in members:
        if member['runtime_enabled_function']:
            includes.add('platform/RuntimeEnabledFeatures.h')
            break

    cpp_class = v8_utilities.cpp_name(dictionary)
    context = {
        'cpp_class': cpp_class,
        'header_includes': set(DICTIONARY_H_INCLUDES),
        'members': members,
        'required_member_names': sorted([member.name
                                         for member in dictionary.members
                                         if member.is_required]),
        'use_permissive_dictionary_conversion': 'PermissiveDictionaryConversion' in dictionary.extended_attributes,
        'v8_class': v8_types.v8_type(cpp_class),
        'v8_original_class': v8_types.v8_type(dictionary.name),
    }
    if dictionary.parent:
        IdlType(dictionary.parent).add_includes_for_type()
        parent_cpp_class = v8_utilities.cpp_name_from_interfaces_info(
            dictionary.parent, interfaces_info)
        context.update({
            'parent_cpp_class': parent_cpp_class,
            'parent_v8_class': v8_types.v8_type(parent_cpp_class),
        })
    return context
Пример #10
0
def callback_function_context(callback_function):
    includes.clear()
    includes.update(CALLBACK_FUNCTION_CPP_INCLUDES)
    idl_type = callback_function.idl_type
    idl_type_str = str(idl_type)

    for argument in callback_function.arguments:
        argument.idl_type.add_includes_for_type(
            callback_function.extended_attributes)

    context = {
        # While both |callback_function_name| and |cpp_class| are identical at
        # the moment, the two are being defined because their values may change
        # in the future (e.g. if we support [ImplementedAs=] in callback
        # functions).
        'callback_function_name': callback_function.name,
        'cpp_class': 'V8%s' % callback_function.name,
        'cpp_includes': sorted(includes),
        'forward_declarations': sorted(forward_declarations(callback_function)),
        'header_includes': sorted(CALLBACK_FUNCTION_H_INCLUDES),
        'idl_type': idl_type_str,
        'is_treat_non_object_as_null': 'TreatNonObjectAsNull' in callback_function.extended_attributes,
        'native_value_traits_tag': v8_types.idl_type_to_native_value_traits_tag(idl_type),
        'return_cpp_type': idl_type.cpp_type,
    }

    context.update(arguments_context(callback_function.arguments))
    return context
Пример #11
0
def dictionary_context(dictionary, interfaces_info):
    includes.clear()
    includes.update(DICTIONARY_CPP_INCLUDES)
    cpp_class = v8_utilities.cpp_name(dictionary)
    context = {
        'cpp_class':
        cpp_class,
        'header_includes':
        set(DICTIONARY_H_INCLUDES),
        'members': [
            member_context(dictionary, member)
            for member in sorted(dictionary.members,
                                 key=operator.attrgetter('name'))
        ],
        'use_permissive_dictionary_conversion':
        'PermissiveDictionaryConversion' in dictionary.extended_attributes,
        'v8_class':
        v8_types.v8_type(cpp_class),
        'v8_original_class':
        v8_types.v8_type(dictionary.name),
    }
    if dictionary.parent:
        IdlType(dictionary.parent).add_includes_for_type()
        parent_cpp_class = v8_utilities.cpp_name_from_interfaces_info(
            dictionary.parent, interfaces_info)
        context.update({
            'parent_cpp_class': parent_cpp_class,
            'parent_v8_class': v8_types.v8_type(parent_cpp_class),
        })
    return context
def callback_function_context(callback_function):
    includes.clear()
    includes.update(CALLBACK_FUNCTION_CPP_INCLUDES)
    idl_type = callback_function.idl_type
    idl_type_str = str(idl_type)

    for argument in callback_function.arguments:
        argument.idl_type.add_includes_for_type(
            callback_function.extended_attributes)

    context = {
        # While both |callback_function_name| and |cpp_class| are identical at
        # the moment, the two are being defined because their values may change
        # in the future (e.g. if we support [ImplementedAs=] in callback
        # functions).
        'callback_function_name': callback_function.name,
        'cpp_class': 'V8%s' % callback_function.name,
        'cpp_includes': sorted(includes),
        'forward_declarations': sorted(forward_declarations(callback_function)),
        'header_includes': sorted(CALLBACK_FUNCTION_H_INCLUDES),
        'idl_type': idl_type_str,
        'return_cpp_type': idl_type.cpp_type,
        'this_include_header_name': to_snake_case('V8%s' % callback_function.name),
    }

    if idl_type_str != 'void':
        context.update({
            'return_value_conversion': idl_type.v8_value_to_local_cpp_value(
                callback_function.extended_attributes,
                'call_result', 'native_result', isolate='GetIsolate()',
                bailout_return_value='v8::Nothing<%s>()' % context['return_cpp_type']),
        })

    context.update(arguments_context(callback_function.arguments))
    return context
Пример #13
0
def dictionary_impl_context(dictionary, interfaces_info):
    includes.clear()
    header_includes = set(["platform/heap/Handle.h"])
    return {
        "header_includes": header_includes,
        "cpp_class": v8_utilities.cpp_name(dictionary),
        "members": [member_impl_context(member, interfaces_info, header_includes) for member in dictionary.members],
    }
def callback_interface_context(callback_interface):
    includes.clear()
    includes.update(CALLBACK_INTERFACE_CPP_INCLUDES)
    return {
        "cpp_class": callback_interface.name,
        "v8_class": v8_utilities.v8_class_name(callback_interface),
        "header_includes": set(CALLBACK_INTERFACE_H_INCLUDES),
        "methods": [method_context(operation) for operation in callback_interface.operations],
    }
Пример #15
0
def dictionary_context(dictionary):
    includes.clear()
    includes.update(DICTIONARY_CPP_INCLUDES)
    return {
        "cpp_class": v8_utilities.cpp_name(dictionary),
        "header_includes": set(DICTIONARY_H_INCLUDES),
        "members": [member_context(member) for member in sorted(dictionary.members, key=operator.attrgetter("name"))],
        "v8_class": v8_utilities.v8_class_name(dictionary),
    }
Пример #16
0
def dictionary_context(dictionary, interfaces_info):
    includes.clear()
    includes.update(DICTIONARY_CPP_INCLUDES)

    if 'RuntimeEnabled' in dictionary.extended_attributes:
        raise Exception('Dictionary cannot be RuntimeEnabled: %s' %
                        dictionary.name)

    members = [
        member_context(dictionary, member)
        for member in sorted(dictionary.members,
                             key=operator.attrgetter('name'))
    ]

    for member in members:
        if member['runtime_enabled_feature_name']:
            includes.add('platform/runtime_enabled_features.h')
            break

    has_origin_trial_members = False
    for member in members:
        if member['origin_trial_feature_name']:
            has_origin_trial_members = True
            includes.add('core/origin_trials/origin_trials.h')
            break

    cpp_class = v8_utilities.cpp_name(dictionary)
    context = {
        'cpp_class':
        cpp_class,
        'has_origin_trial_members':
        has_origin_trial_members,
        'header_includes':
        set(DICTIONARY_H_INCLUDES),
        'members':
        members,
        'required_member_names':
        sorted([
            member.name for member in dictionary.members if member.is_required
        ]),
        'use_permissive_dictionary_conversion':
        'PermissiveDictionaryConversion' in dictionary.extended_attributes,
        'v8_class':
        v8_types.v8_type(cpp_class),
        'v8_original_class':
        v8_types.v8_type(dictionary.name),
    }
    if dictionary.parent:
        IdlType(dictionary.parent).add_includes_for_type()
        parent_cpp_class = v8_utilities.cpp_name_from_interfaces_info(
            dictionary.parent, interfaces_info)
        context.update({
            'parent_cpp_class': parent_cpp_class,
            'parent_v8_class': v8_types.v8_type(parent_cpp_class),
        })
    return context
Пример #17
0
def dictionary_impl_context(dictionary, interfaces_info):
    includes.clear()
    header_includes = set(['platform/heap/Handle.h'])
    return {
        'header_includes': header_includes,
        'cpp_class': v8_utilities.cpp_name(dictionary),
        'members': [member_impl_context(member, interfaces_info,
                                        header_includes)
                    for member in dictionary.members],
    }
Пример #18
0
def dictionary_impl_context(dictionary, interfaces_info):
    includes.clear()
    header_includes = set(['platform/heap/Handle.h'])
    return {
        'header_includes': header_includes,
        'cpp_class': v8_utilities.cpp_name(dictionary),
        'members': [member_impl_context(member, interfaces_info,
                                        header_includes)
                    for member in dictionary.members],
    }
Пример #19
0
def callback_interface_context(callback_interface):
    includes.clear()
    includes.update(CALLBACK_INTERFACE_CPP_INCLUDES)
    return {
        'cpp_class': callback_interface.name,
        'v8_class': v8_utilities.v8_class_name(callback_interface),
        'header_includes': set(CALLBACK_INTERFACE_H_INCLUDES),
        'methods': [method_context(operation)
                    for operation in callback_interface.operations],
    }
Пример #20
0
def dictionary_context(dictionary):
    includes.clear()
    includes.update(DICTIONARY_CPP_INCLUDES)
    return {
        'cpp_class': v8_utilities.cpp_name(dictionary),
        'header_includes': set(DICTIONARY_H_INCLUDES),
        'members': [member_context(member)
                    for member in sorted(dictionary.members,
                                         key=operator.attrgetter('name'))],
        'v8_class': v8_utilities.v8_class_name(dictionary),
    }
def private_script_interface_context(private_script_interface):
    includes.clear()
    includes.update(BLINK_IN_JS_INTERFACE_CPP_INCLUDES)
    return {
        'cpp_class': private_script_interface.name,
        'forward_declarations': forward_declarations(private_script_interface),
        'header_includes': set(BLINK_IN_JS_INTERFACE_H_INCLUDES),
        'methods': [method_context(operation)
                    for operation in private_script_interface.operations],
        'v8_class': v8_utilities.v8_class_name(private_script_interface),
    }
Пример #22
0
def dictionary_context(dictionary):
    includes.clear()
    includes.update(DICTIONARY_CPP_INCLUDES)
    return {
        'cpp_class': v8_utilities.cpp_name(dictionary),
        'header_includes': set(DICTIONARY_H_INCLUDES),
        'members': [member_context(member)
                    for member in sorted(dictionary.members,
                                         key=operator.attrgetter('name'))],
        'v8_class': v8_utilities.v8_class_name(dictionary),
    }
Пример #23
0
def generate_callback_interface(callback_interface):
    includes.clear()
    includes.update(CALLBACK_INTERFACE_CPP_INCLUDES)
    return {
        'conditional_string': v8_utilities.conditional_string(callback_interface),
        'cpp_class': callback_interface.name,
        'v8_class': v8_utilities.v8_class_name(callback_interface),
        'header_includes': set(CALLBACK_INTERFACE_H_INCLUDES),
        'methods': [generate_method(operation)
                    for operation in callback_interface.operations],
    }
def legacy_callback_interface_context(callback_interface, _):
    includes.clear()
    includes.update(LEGACY_CALLBACK_INTERFACE_CPP_INCLUDES)
    return {
        # TODO(bashi): Fix crbug.com/630986, and add 'methods'.
        'constants': [constant_context(constant, callback_interface)
                      for constant in callback_interface.constants],
        'cpp_class': callback_interface.name,
        'header_includes': set(LEGACY_CALLBACK_INTERFACE_H_INCLUDES),
        'interface_name': callback_interface.name,
        'v8_class': v8_utilities.v8_class_name(callback_interface),
    }
def generate_callback_interface(callback_interface):
    includes.clear()
    includes.update(CALLBACK_INTERFACE_CPP_INCLUDES)

    methods = [generate_method(operation) for operation in callback_interface.operations]
    template_contents = {
        'cpp_class_name': callback_interface.name,
        'v8_class_name': v8_class_name(callback_interface),
        'header_includes': CALLBACK_INTERFACE_H_INCLUDES,
        'methods': methods,
    }
    return template_contents
Пример #26
0
def legacy_callback_interface_context(callback_interface, _):
    includes.clear()
    includes.update(LEGACY_CALLBACK_INTERFACE_CPP_INCLUDES)
    return {
        # TODO(bashi): Fix crbug.com/630986, and add 'methods'.
        'constants': [constant_context(constant, callback_interface)
                      for constant in callback_interface.constants],
        'cpp_class': callback_interface.name,
        'header_includes': set(CALLBACK_INTERFACE_H_INCLUDES),
        'interface_name': callback_interface.name,
        'v8_class': v8_utilities.v8_class_name(callback_interface),
    }
Пример #27
0
def callback_interface_context(callback_interface, _):
    is_legacy_callback_interface = len(callback_interface.constants) > 0

    includes.clear()
    includes.update(CALLBACK_INTERFACE_CPP_INCLUDES)
    if is_legacy_callback_interface:
        includes.update(LEGACY_CALLBACK_INTERFACE_CPP_INCLUDES)

    header_includes = set(CALLBACK_INTERFACE_H_INCLUDES)
    if is_legacy_callback_interface:
        header_includes.update(LEGACY_CALLBACK_INTERFACE_H_INCLUDES)

    # https://heycam.github.io/webidl/#dfn-single-operation-callback-interface
    is_single_operation = True
    if (callback_interface.parent or len(callback_interface.attributes) > 0
            or len(callback_interface.operations) == 0):
        is_single_operation = False
    else:
        operations = callback_interface.operations
        basis = operations[0]
        for op in operations[1:]:
            if op.name != basis.name:
                is_single_operation = False
                break

    return {
        'constants': [
            constant_context(constant, callback_interface)
            for constant in callback_interface.constants
        ],
        'cpp_class':
        callback_interface.name,
        'do_not_check_constants':
        'DoNotCheckConstants' in callback_interface.extended_attributes,
        'forward_declarations':
        sorted(forward_declarations(callback_interface)),
        'header_includes':
        header_includes,
        'interface_name':
        callback_interface.name,
        'is_legacy_callback_interface':
        is_legacy_callback_interface,
        'is_single_operation_callback_interface':
        is_single_operation,
        'methods': [
            method_context(operation)
            for operation in callback_interface.operations
        ],
        'v8_class':
        v8_utilities.v8_class_name(callback_interface),
    }
Пример #28
0
def generate_callback_interface(callback_interface):
    includes.clear()
    includes.update(CALLBACK_INTERFACE_CPP_INCLUDES)
    name = callback_interface.name

    methods = [generate_method(operation)
               for operation in callback_interface.operations]
    template_contents = {
        'cpp_class': name,
        'dart_class': dart_types.dart_type(callback_interface.name),
        'header_includes': set(CALLBACK_INTERFACE_H_INCLUDES),
        'methods': methods,
    }
    return template_contents
Пример #29
0
def generate_callback_interface(callback_interface):
    includes.clear()
    includes.update(CALLBACK_INTERFACE_CPP_INCLUDES)

    methods = [
        generate_method(operation)
        for operation in callback_interface.operations
    ]
    template_contents = {
        'cpp_class_name': callback_interface.name,
        'v8_class_name': v8_class_name(callback_interface),
        'header_includes': CALLBACK_INTERFACE_H_INCLUDES,
        'methods': methods,
    }
    return template_contents
Пример #30
0
def generate_callback_interface(callback_interface):
    includes.clear()
    includes.update(CALLBACK_INTERFACE_CPP_INCLUDES)
    name = callback_interface.name

    methods = [
        generate_method(operation)
        for operation in callback_interface.operations
    ]
    template_contents = {
        'cpp_class': name,
        'dart_class': dart_types.dart_type(callback_interface.name),
        'header_includes': set(CALLBACK_INTERFACE_H_INCLUDES),
        'methods': methods,
    }
    return template_contents
def generate_callback_interface(callback_interface):
    includes.clear()
    includes.update(CALLBACK_INTERFACE_CPP_INCLUDES)
    return {
        'conditional_string':
        v8_utilities.conditional_string(callback_interface),
        'cpp_class':
        callback_interface.name,
        'v8_class':
        v8_utilities.v8_class_name(callback_interface),
        'header_includes':
        set(CALLBACK_INTERFACE_H_INCLUDES),
        'methods': [
            generate_method(operation)
            for operation in callback_interface.operations
        ],
    }
Пример #32
0
def generate_interface(interface):
    includes.clear()
    includes.update(INTERFACE_CPP_INCLUDES)
    v8_class_name = v8_utilities.v8_class_name(interface)

    template_contents = {
        'cpp_class_name': cpp_name(interface),
        'header_includes': INTERFACE_H_INCLUDES,
        'interface_name': interface.name,
        'v8_class_name': v8_class_name,
    }

    template_contents.update({
        'constants':
        [generate_constant(constant) for constant in interface.constants],
        'do_not_check_constants':
        'DoNotCheckConstants' in interface.extended_attributes,
    })

    attributes = [
        v8_attributes.generate_attribute(interface, attribute)
        for attribute in interface.attributes
    ]
    template_contents.update({
        'attributes':
        attributes,
        'has_constructor_attributes':
        any(attribute['is_constructor'] for attribute in attributes),
        'has_per_context_enabled_attributes':
        any(attribute['per_context_enabled_function_name']
            for attribute in attributes),
        'has_replaceable_attributes':
        any(attribute['is_replaceable'] for attribute in attributes),
        'has_runtime_enabled_attributes':
        any(attribute['runtime_enabled_function_name']
            for attribute in attributes),
    })

    template_contents['methods'] = [
        v8_methods.generate_method(method) for method in interface.operations
    ]

    return template_contents
Пример #33
0
def dictionary_context(dictionary, interfaces_info):
    includes.clear()
    includes.update(DICTIONARY_CPP_INCLUDES)
    cpp_class = v8_utilities.cpp_name(dictionary)
    context = {
        "cpp_class": cpp_class,
        "header_includes": set(DICTIONARY_H_INCLUDES),
        "members": [
            member_context(dictionary, member) for member in sorted(dictionary.members, key=operator.attrgetter("name"))
        ],
        "use_permissive_dictionary_conversion": "PermissiveDictionaryConversion" in dictionary.extended_attributes,
        "v8_class": v8_types.v8_type(cpp_class),
        "v8_original_class": v8_types.v8_type(dictionary.name),
    }
    if dictionary.parent:
        IdlType(dictionary.parent).add_includes_for_type()
        parent_cpp_class = v8_utilities.cpp_name_from_interfaces_info(dictionary.parent, interfaces_info)
        context.update({"parent_cpp_class": parent_cpp_class, "parent_v8_class": v8_types.v8_type(parent_cpp_class)})
    return context
Пример #34
0
 def _generate_container_code(self, union_type):
     includes.clear()
     union_type = union_type.resolve_typedefs(self.typedefs)
     header_template = self.jinja_env.get_template('union_container.h.tmpl')
     cpp_template = self.jinja_env.get_template('union_container.cc.tmpl')
     template_context = v8_union.container_context(union_type, self.info_provider)
     template_context['header_includes'].append(
         self.info_provider.include_path_for_export)
     template_context['exported'] = self.info_provider.specifier_for_export
     snake_base_name = to_snake_case(shorten_union_name(union_type))
     header_path = posixpath.join(self.output_dir, '%s.h' % snake_base_name)
     cpp_path = posixpath.join(self.output_dir, '%s.cc' % snake_base_name)
     this_include_header_path = self.normalize_this_header_path(header_path)
     template_context['this_include_header_path'] = this_include_header_path
     template_context['header_guard'] = to_header_guard(this_include_header_path)
     header_text, cpp_text = self.render_templates(
         [], header_template, cpp_template, template_context)
     return (
         (header_path, header_text),
         (cpp_path, cpp_text),
     )
Пример #35
0
def dictionary_context(dictionary, interfaces_info):
    includes.clear()
    includes.update(DICTIONARY_CPP_INCLUDES)
    cpp_class = v8_utilities.cpp_name(dictionary)
    context = {
        'cpp_class': cpp_class,
        'header_includes': set(DICTIONARY_H_INCLUDES),
        'members': [member_context(dictionary, member)
                    for member in sorted(dictionary.members,
                                         key=operator.attrgetter('name'))],
        'use_permissive_dictionary_conversion': 'PermissiveDictionaryConversion' in dictionary.extended_attributes,
        'v8_class': v8_types.v8_type(cpp_class),
        'v8_original_class': v8_types.v8_type(dictionary.name),
    }
    if dictionary.parent:
        IdlType(dictionary.parent).add_includes_for_type()
        parent_cpp_class = v8_utilities.cpp_name_from_interfaces_info(
            dictionary.parent, interfaces_info)
        context.update({
            'parent_cpp_class': parent_cpp_class,
            'parent_v8_class': v8_types.v8_type(parent_cpp_class),
        })
    return context
Пример #36
0
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(v8_types.includes_for_interface(parent_interface))
    extended_attributes = interface.extended_attributes

    # [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 = v8_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,
        'v8_type': v8_types.v8_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

    # [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_check_security': is_check_security,
        'is_dependent_lifetime': is_dependent_lifetime,
        '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': v8_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,
        'v8_class': v8_utilities.v8_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]

    special_getter_constants = []
    runtime_enabled_constants = []
    constant_configuration_constants = []

    for constant in constants:
        if constant['measure_as'] or constant['deprecate_as']:
            special_getter_constants.append(constant)
            continue
        if constant['runtime_enabled_function']:
            runtime_enabled_constants.append(constant)
            continue
        constant_configuration_constants.append(constant)

    # Constants
    context.update({
        'constant_configuration_constants': constant_configuration_constants,
        'constants': constants,
        'do_not_check_constants': 'DoNotCheckConstants' in extended_attributes,
        'has_constant_configuration': any(
            not constant['runtime_enabled_function']
            for constant in constants),
        'runtime_enabled_constants': runtime_enabled_constants,
        'special_getter_constants': special_getter_constants,
    })

    # Attributes
    attributes = [v8_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 = [v8_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(v8_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
Пример #37
0
def interface_context(interface):
    context = v8_interface.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(
            dart_types.includes_for_interface(parent_interface))
    extended_attributes = interface.extended_attributes

    is_document = inherits_interface(interface.name, 'Document')
    if is_document:
        # FIXME(vsm): We probably need bindings/dart/DartController and
        # core/frame/LocalFrame.h here.
        includes.update(['DartDocument.h'])

    if inherits_interface(interface.name, 'DataTransferItemList'):
        # FIXME(jacobr): this is a hack.
        includes.update(['core/html/HTMLCollection.h'])

    if inherits_interface(interface.name, 'EventTarget'):
        includes.update(['bindings/core/dart/DartEventListener.h'])

    # [SetWrapperReferenceTo]
    set_wrapper_reference_to_list = [
        {
            'name': argument.name,
            # FIXME: properly should be:
            # 'cpp_type': argument.idl_type.cpp_type_args(used_as_rvalue_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,
            'v8_type': dart_types.v8_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()

    context.update({
        'conditional_string':
        DartUtilities.conditional_string(interface),  # [Conditional]
        'cpp_class':
        DartUtilities.cpp_name(interface),
        'header_includes':
        header_includes,
        'is_garbage_collected':
        context['gc_type'] == 'GarbageCollectedObject',
        'is_will_be_garbage_collected':
        context['gc_type'] == 'WillBeGarbageCollectedObject',
        'measure_as':
        DartUtilities.measure_as(interface),  # [MeasureAs]
        'pass_cpp_type':
        dart_types.cpp_template_type(
            dart_types.cpp_ptr_type('PassRefPtr', 'RawPtr',
                                    context['gc_type']),
            DartUtilities.cpp_name(interface)),
        'runtime_enabled_function':
        DartUtilities.runtime_enabled_function_name(
            interface),  # [RuntimeEnabled]
        'set_wrapper_reference_to_list':
        set_wrapper_reference_to_list,
        'dart_class':
        dart_types.dart_type(interface.name),
        'v8_class':
        DartUtilities.v8_class_name(interface),
    })

    # 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.update(
            {'constructor_overloads': overloads_context(constructors)})

    # [CustomConstructor]
    custom_constructors = [
        custom_constructor_context(interface, constructor)
        for constructor in interface.custom_constructors
    ]

    # [NamedConstructor]
    named_constructor = generate_named_constructor(interface)

    generate_method_native_entries(interface, constructors, 'Constructor')
    generate_method_native_entries(interface, custom_constructors,
                                   'Constructor')
    if named_constructor:
        generate_method_native_entries(interface, [named_constructor],
                                       'Constructor')
    event_constructor = None
    if context['has_event_constructor']:
        event_constructor = {
            'native_entries': [
                DartUtilities.generate_native_entry(interface.name, None,
                                                    'Constructor', False, 2)
            ],
        }

    if (context['constructors'] or custom_constructors
            or context['has_event_constructor'] or named_constructor):
        includes.add('core/frame/LocalDOMWindow.h')

    context.update({
        'constructors':
        constructors,
        'custom_constructors':
        custom_constructors,
        'event_constructor':
        event_constructor,
        'has_custom_constructor':
        bool(custom_constructors),
        'interface_length':
        v8_interface.interface_length(interface,
                                      constructors + custom_constructors),
        'is_constructor_call_with_document':
        DartUtilities.has_extended_attribute_value(
            interface, 'ConstructorCallWith',
            'Document'),  # [ConstructorCallWith=Document]
        'is_constructor_call_with_execution_context':
        DartUtilities.has_extended_attribute_value(
            interface, 'ConstructorCallWith',
            'ExecutionContext'),  # [ConstructorCallWith=ExeuctionContext]
        'named_constructor':
        named_constructor,
    })

    # Attributes
    attributes = [
        dart_attributes.attribute_context(interface, attribute)
        for attribute in interface.attributes
        # Skip attributes in the IGNORE_MEMBERS list or if an
        # extended attribute is in the IGNORE_EXTENDED_ATTRIBUTES.
        if
        (not _suppress_attribute(interface.name, attribute.name)
         and not v8_attributes.is_constructor_attribute(attribute)
         and not _suppress_extended_attributes(attribute.extended_attributes)
         and not ('DartSuppress' in attribute.extended_attributes and
                  attribute.extended_attributes.get('DartSuppress') == None))
    ]
    context.update({
        'attributes':
        attributes,
        'has_accessors':
        any(attribute['is_expose_js_accessors'] 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'])
            for attribute in attributes),
        'has_constructor_attributes':
        any(attribute['constructor_type'] for attribute in attributes),
        'has_per_context_enabled_attributes':
        any(attribute['per_context_enabled_function']
            for attribute in attributes),
        'has_replaceable_attributes':
        any(attribute['is_replaceable'] for attribute in attributes),
    })

    # Methods
    methods = [
        dart_methods.method_context(interface, method)
        for method in interface.operations
        # Skip anonymous special operations (methods name empty).
        # Skip methods in our IGNORE_MEMBERS list.
        # Skip methods w/ extended attributes in IGNORE_EXTENDED_ATTRIBUTES list.
        if
        (method.name and
         # detect unnamed getters from v8_interface.
         method.name != 'anonymousNamedGetter' and
         # TODO(terry): Eventual eliminate the IGNORE_MEMBERS in favor of DartSupress.
         not _suppress_method(interface.name, method.name)
         and not _suppress_extended_attributes(method.extended_attributes)
         and not 'DartSuppress' in method.extended_attributes)
    ]
    compute_method_overloads_context(methods)
    for method in methods:
        method['do_generate_method_configuration'] = (
            method['do_not_check_signature']
            and not method['per_context_enabled_function'] and
            # For overloaded methods, only generate one accessor
            ('overload_index' not in method or method['overload_index'] == 1))

    generate_method_native_entries(interface, methods, 'Method')

    context.update({
        'has_origin_safe_method_setter':
        any(method['is_check_security_for_frame']
            and not method['is_read_only'] for method in methods),
        'has_method_configuration':
        any(method['do_generate_method_configuration'] for method in methods),
        'has_per_context_enabled_methods':
        any(method['per_context_enabled_function'] for method in methods),
        'methods':
        methods,
    })

    context.update({
        'indexed_property_getter':
        indexed_property_getter(interface),
        'indexed_property_setter':
        indexed_property_setter(interface),
        'indexed_property_deleter':
        v8_interface.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':
        v8_interface.named_property_deleter(interface),
    })

    generate_native_entries_for_specials(interface, context)

    native_entries = generate_interface_native_entries(context)

    context.update({
        'native_entries': native_entries,
    })

    return context
Пример #38
0
def interface_context(interface):
    context = v8_interface.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(dart_types.includes_for_interface(parent_interface))
    extended_attributes = interface.extended_attributes

    if inherits_interface(interface.name, "EventTarget"):
        includes.update(["bindings/dart_event_listener.h"])

    # [SetWrapperReferenceTo]
    set_wrapper_reference_to_list = [
        {
            "name": argument.name,
            # FIXME: properly should be:
            # 'cpp_type': argument.idl_type.cpp_type_args(used_as_rvalue_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,
        }
        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()

    context.update(
        {
            "cpp_class": DartUtilities.cpp_name(interface),
            "header_includes": header_includes,
            "set_wrapper_reference_to_list": set_wrapper_reference_to_list,
            "dart_class": dart_types.dart_type(interface.name),
        }
    )

    # 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.update({"constructor_overloads": overloads_context(constructors)})

    # [CustomConstructor]
    custom_constructors = [
        custom_constructor_context(interface, constructor) for constructor in interface.custom_constructors
    ]

    # [NamedConstructor]
    named_constructor = generate_named_constructor(interface)

    generate_method_native_entries(interface, constructors, "Constructor")
    generate_method_native_entries(interface, custom_constructors, "Constructor")
    if named_constructor:
        generate_method_native_entries(interface, [named_constructor], "Constructor")
    event_constructor = None
    if context["has_event_constructor"]:
        event_constructor = {
            "native_entries": [DartUtilities.generate_native_entry(interface.name, None, "Constructor", False, 2)]
        }

    context.update(
        {
            "constructors": constructors,
            "custom_constructors": custom_constructors,
            "event_constructor": event_constructor,
            "has_custom_constructor": bool(custom_constructors),
            "interface_length": v8_interface.interface_length(interface, constructors + custom_constructors),
            "is_constructor_call_with_execution_context": DartUtilities.has_extended_attribute_value(
                interface, "ConstructorCallWith", "ExecutionContext"
            ),  # [ConstructorCallWith=ExeuctionContext]
            "named_constructor": named_constructor,
        }
    )

    # Attributes
    attributes = [
        dart_attributes.attribute_context(interface, attribute)
        for attribute in interface.attributes
        if not v8_attributes.is_constructor_attribute(attribute)
    ]
    context.update(
        {
            "attributes": 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 = [
        dart_methods.method_context(interface, method)
        for method in interface.operations
        # Skip anonymous special operations (methods name empty).
        if (
            method.name
            and
            # detect unnamed getters from v8_interface.
            method.name != "anonymousNamedGetter"
        )
    ]
    compute_method_overloads_context(methods)
    for method in methods:
        method["do_generate_method_configuration"] = (
            # For overloaded methods, only generate one accessor
            "overload_index" not in method or method["overload_index"] == 1
        )

    for method in methods:
        assert "overloads" not in method, "Dart does not support overloads, %s in %s" % (method["name"], interface.name)

    generate_method_native_entries(interface, methods, "Method")

    context.update(
        {
            "has_method_configuration": any(method["do_generate_method_configuration"] for method in methods),
            "methods": methods,
        }
    )

    context.update(
        {
            "indexed_property_getter": indexed_property_getter(interface),
            "indexed_property_setter": indexed_property_setter(interface),
            "indexed_property_deleter": v8_interface.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": v8_interface.named_property_deleter(interface),
        }
    )

    generate_native_entries_for_specials(interface, context)

    native_entries = generate_interface_native_entries(context)

    context.update({"native_entries": native_entries})

    return context
Пример #39
0
def generate_interface(interface):
    includes.clear()
    includes.update(INTERFACE_CPP_INCLUDES)
    header_includes = INTERFACE_H_INCLUDES

    parent_interface = interface.parent
    if parent_interface:
        header_includes.update(v8_types.includes_for_type(parent_interface))
    extended_attributes = interface.extended_attributes

    # [CheckSecurity]
    is_check_security = 'CheckSecurity' in extended_attributes
    if is_check_security:
        includes.update(['bindings/v8/BindingSecurity.h',
                         'bindings/v8/ExceptionState.h'])

    # [GenerateVisitDOMWrapper]
    generate_visit_dom_wrapper_function = extended_attributes.get('GenerateVisitDOMWrapper')
    if generate_visit_dom_wrapper_function:
        includes.update(['bindings/v8/V8GCController.h',
                         'core/dom/Element.h'])

    # [MeasureAs]
    is_measure_as = 'MeasureAs' in extended_attributes
    if is_measure_as:
        includes.add('core/frame/UseCounter.h')

    # [RaisesException=Constructor]
    is_constructor_raises_exception = extended_attributes.get('RaisesException') == 'Constructor'
    if is_constructor_raises_exception:
        includes.add('bindings/v8/ExceptionState.h')

    # [SpecialWrapFor]
    if 'SpecialWrapFor' in extended_attributes:
        special_wrap_for = extended_attributes['SpecialWrapFor'].split('|')
    else:
        special_wrap_for = []
    for special_wrap_interface in special_wrap_for:
        v8_types.add_includes_for_type(special_wrap_interface)

    # Constructors
    # [Constructor]
    has_constructor = 'Constructor' in extended_attributes
    if has_constructor:
        includes.add('bindings/v8/V8ObjectConstructor.h')

    # [EventConstructor]
    has_event_constructor = 'EventConstructor' in extended_attributes
    has_any_type_attributes = any(attribute
                                  for attribute in interface.attributes
                                  if attribute.idl_type == 'any')
    if has_event_constructor:
        includes.update(['bindings/v8/Dictionary.h',
                         'bindings/v8/V8ObjectConstructor.h'])
        if has_any_type_attributes:
            includes.add('bindings/v8/SerializedScriptValue.h')

    template_contents = {
        'conditional_string': conditional_string(interface),  # [Conditional]
        'constructor_arguments': constructor_arguments(interface),
        'cpp_class': cpp_name(interface),
        'generate_visit_dom_wrapper_function': generate_visit_dom_wrapper_function,
        'has_constructor': has_constructor,
        '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_event_constructor': has_event_constructor,
        'has_any_type_attributes': has_any_type_attributes,
        'has_visit_dom_wrapper': (
            # [Custom=Wrap], [GenerateVisitDOMWrapper]
            has_extended_attribute_value(interface, 'Custom', 'VisitDOMWrapper') or
            'GenerateVisitDOMWrapper' in extended_attributes),
        'header_includes': header_includes,
        'interface_name': interface.name,
        'is_active_dom_object': 'ActiveDOMObject' in extended_attributes,  # [ActiveDOMObject]
        'is_check_security': is_check_security,
        'is_constructor_call_with_document': has_extended_attribute_value(
            interface, 'ConstructorCallWith', 'Document'),  # [ConstructorCallWith=Document]
        'is_constructor_call_with_execution_context': has_extended_attribute_value(
            interface, 'ConstructorCallWith', 'ExecutionContext'),  # [ConstructorCallWith=ExeuctionContext]
        'is_constructor_raises_exception': is_constructor_raises_exception,
        'is_dependent_lifetime': 'DependentLifetime' in extended_attributes,  # [DependentLifetime]
        'length': 1 if has_event_constructor else 0,  # FIXME: more complex in general, see discussion of length in http://heycam.github.io/webidl/#es-interface-call
        'measure_as': v8_utilities.measure_as(interface),  # [MeasureAs]
        'parent_interface': parent_interface,
        'runtime_enabled_function': runtime_enabled_function_name(interface),  # [RuntimeEnabled]
        'special_wrap_for': special_wrap_for,
        'v8_class': v8_utilities.v8_class_name(interface),
    }

    template_contents.update({
        'constants': [generate_constant(constant) for constant in interface.constants],
        'do_not_check_constants': 'DoNotCheckConstants' in extended_attributes,
    })

    attributes = [v8_attributes.generate_attribute(interface, attribute)
                  for attribute in interface.attributes]
    template_contents.update({
        'attributes': attributes,
        'has_accessors': any(attribute['is_expose_js_accessors'] for attribute in attributes),
        'has_constructor_attributes': any(attribute['constructor_type'] for attribute in attributes),
        'has_per_context_enabled_attributes': any(attribute['per_context_enabled_function'] for attribute in attributes),
        'has_replaceable_attributes': any(attribute['is_replaceable'] for attribute in attributes),
    })

    methods = [v8_methods.generate_method(interface, method)
               for method in interface.operations]
    generate_overloads(methods)
    for method in methods:
        method['do_generate_method_configuration'] = (
            method['do_not_check_signature'] and
            not method['per_context_enabled_function'] and
            # For overloaded methods, only generate one accessor
            ('overload_index' not in method or method['overload_index'] == 1))

    template_contents.update({
        'has_origin_safe_method_setter': any(
            method['is_check_security_for_frame'] and not method['is_read_only']
            for method in methods),
        'has_method_configuration': any(method['do_generate_method_configuration'] for method in methods),
        'has_per_context_enabled_methods': any(method['per_context_enabled_function'] for method in methods),
        'methods': methods,
    })

    return template_contents
Пример #40
0
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(v8_types.includes_for_interface(parent_interface))
    extended_attributes = interface.extended_attributes

    # [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 = v8_methods.method_context(interface,
                                                    iterator_operation)

    # [SetWrapperReferenceFrom]
    reachable_node_function = extended_attributes.get('SetWrapperReferenceFrom')
    if reachable_node_function:
        includes.update(['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,
    } 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:
        v8_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)

    wrapper_class_id = ('NodeClassId' if inherits_interface(interface.name, 'Node') else 'ObjectClassId')

    context = {
        'cpp_class': cpp_name(interface),
        '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_dependent_lifetime': is_dependent_lifetime,
        'is_exception': interface.is_exception,
        'is_script_wrappable': is_script_wrappable,
        'iterator_method': iterator_method,
        'lifetime': 'Dependent'
            if (has_visit_dom_wrapper or
                is_dependent_lifetime)
            else 'Independent',
        'parent_interface': parent_interface,
        'reachable_node_function': reachable_node_function,
        'set_wrapper_reference_to_list': set_wrapper_reference_to_list,
        'special_wrap_for': special_wrap_for,
        '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']

    # [NamedConstructor]
    named_constructor = named_constructor_context(interface)

    if (constructors or custom_constructors or has_event_constructor or
        named_constructor):
        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,
        'has_constant_configuration': True,
    })

    # Attributes
    attributes = [v8_attributes.attribute_context(interface, attribute)
                  for attribute in interface.attributes]
    context.update({
        'attributes': attributes,
        'has_conditional_attributes': any(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 = [v8_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(v8_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']
            conditionally_exposed_function = overloads['exposed_test_all']
            has_custom_registration = overloads['has_custom_registration_all']
        else:
            conditionally_exposed_function = method['exposed_test']
            has_custom_registration = method['has_custom_registration']

        if conditionally_exposed_function:
            conditionally_enabled_methods.append(method)
            continue
        if has_custom_registration:
            custom_registration_methods.append(method)
            continue
        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,
        '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
Пример #41
0
def interface_context(interface):
    context = v8_interface.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(dart_types.includes_for_interface(parent_interface))
    extended_attributes = interface.extended_attributes

    if inherits_interface(interface.name, 'EventTarget'):
        includes.update(['bindings/dart_event_listener.h'])

    # [SetWrapperReferenceTo]
    set_wrapper_reference_to_list = [{
        'name': argument.name,
        # FIXME: properly should be:
        # 'cpp_type': argument.idl_type.cpp_type_args(used_as_rvalue_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,
    } 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()

    context.update({
        'cpp_class': DartUtilities.cpp_name(interface),
        'header_includes': header_includes,
         'set_wrapper_reference_to_list': set_wrapper_reference_to_list,
        'dart_class': dart_types.dart_type(interface.name),
    })

    # 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.update({'constructor_overloads': overloads_context(constructors)})

    # [CustomConstructor]
    custom_constructors = [custom_constructor_context(interface, constructor)
                           for constructor in interface.custom_constructors]

    # [NamedConstructor]
    named_constructor = generate_named_constructor(interface)

    generate_method_native_entries(interface, constructors, 'Constructor')
    generate_method_native_entries(interface, custom_constructors, 'Constructor')
    if named_constructor:
        generate_method_native_entries(interface, [named_constructor],
                                       'Constructor')
    event_constructor = None
    if context['has_event_constructor']:
        event_constructor = {
            'native_entries': [
                DartUtilities.generate_native_entry(
                    interface.name, None, 'Constructor', False, 2)],
        }

    if (context['constructors'] or custom_constructors or context['has_event_constructor'] or
        named_constructor):
        includes.add('core/frame/LocalDOMWindow.h')

    context.update({
        'constructors': constructors,
        'custom_constructors': custom_constructors,
        'event_constructor': event_constructor,
        'has_custom_constructor': bool(custom_constructors),
        'interface_length':
            v8_interface.interface_length(interface, constructors + custom_constructors),
        'is_constructor_call_with_document': DartUtilities.has_extended_attribute_value(
            interface, 'ConstructorCallWith', 'Document'),  # [ConstructorCallWith=Document]
        'is_constructor_call_with_execution_context': DartUtilities.has_extended_attribute_value(
            interface, 'ConstructorCallWith', 'ExecutionContext'),  # [ConstructorCallWith=ExeuctionContext]
        'named_constructor': named_constructor,
    })

    # Attributes
    attributes = [dart_attributes.attribute_context(interface, attribute)
                  for attribute in interface.attributes
                      if not v8_attributes.is_constructor_attribute(attribute)]
    context.update({
        'attributes': 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 = [dart_methods.method_context(interface, method)
               for method in interface.operations
               # Skip anonymous special operations (methods name empty).
               if (method.name and
                   # detect unnamed getters from v8_interface.
                   method.name != 'anonymousNamedGetter')]
    compute_method_overloads_context(methods)
    for method in methods:
        method['do_generate_method_configuration'] = (
            # For overloaded methods, only generate one accessor
            ('overload_index' not in method or method['overload_index'] == 1))

    for method in methods:
        assert 'overloads' not in method, 'Dart does not support overloads, %s in %s' % (method['name'], interface.name)

    generate_method_native_entries(interface, methods, 'Method')

    context.update({
        'has_method_configuration': any(method['do_generate_method_configuration'] for method in methods),
        'methods': methods,
    })

    context.update({
        'indexed_property_getter': indexed_property_getter(interface),
        'indexed_property_setter': indexed_property_setter(interface),
        'indexed_property_deleter': v8_interface.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': v8_interface.named_property_deleter(interface),
    })

    generate_native_entries_for_specials(interface, context)

    native_entries = generate_interface_native_entries(context)

    context.update({
        'native_entries': native_entries,
    })

    return context
Пример #42
0
def generate_interface(interface):
    includes.clear()
    includes.update(INTERFACE_CPP_INCLUDES)
    header_includes = set(INTERFACE_H_INCLUDES)

    parent_interface = interface.parent
    if parent_interface:
        header_includes.update(v8_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/v8/ScriptController.h',
                         'bindings/v8/V8WindowShell.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/v8/BindingSecurity.h')

    # [DependentLifetime]
    is_dependent_lifetime = 'DependentLifetime' in extended_attributes

    # [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/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(used_as_argument=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,
        'v8_type': v8_types.v8_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()

    # [SpecialWrapFor]
    if 'SpecialWrapFor' in extended_attributes:
        special_wrap_for = extended_attributes['SpecialWrapFor'].split('|')
    else:
        special_wrap_for = []
    for special_wrap_interface in special_wrap_for:
        v8_types.add_includes_for_interface(special_wrap_interface)

    # [WillBeGarbageCollected]
    is_will_be_garbage_collected = 'WillBeGarbageCollected' in extended_attributes

    # [Custom=Wrap], [SetWrapperReferenceFrom]
    has_visit_dom_wrapper = (
        has_extended_attribute_value(interface, 'Custom', 'VisitDOMWrapper') or
        reachable_node_function or
        set_wrapper_reference_to_list)

    template_contents = {
        'conditional_string': conditional_string(interface),  # [Conditional]
        'cpp_class': cpp_name(interface),
        '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_will_be_garbage_collected': is_will_be_garbage_collected,
        'is_node': inherits_interface(interface.name, 'Node'),
        'measure_as': v8_utilities.measure_as(interface),  # [MeasureAs]
        'parent_interface': parent_interface,
        'pass_ref_ptr': 'PassRefPtrWillBeRawPtr'
                        if is_will_be_garbage_collected else 'PassRefPtr',
        'reachable_node_function': reachable_node_function,
        'ref_ptr': 'RefPtrWillBeRawPtr'
                   if is_will_be_garbage_collected else 'RefPtr',
        '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,
        'v8_class': v8_utilities.v8_class_name(interface),
        'wrapper_configuration': 'WrapperConfiguration::Dependent'
            if (has_visit_dom_wrapper or
                is_active_dom_object or
                is_dependent_lifetime)
            else 'WrapperConfiguration::Independent',
    }

    # Constructors
    constructors = [generate_constructor(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']
    generate_constructor_overloads(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/v8/Dictionary.h')
        if any_type_attributes:
            includes.add('bindings/v8/SerializedScriptValue.h')

    # [NamedConstructor]
    named_constructor = generate_named_constructor(interface)

    if (constructors or custom_constructors or has_event_constructor or
        named_constructor):
        includes.add('bindings/v8/V8ObjectConstructor.h')
        includes.add('core/frame/DOMWindow.h')

    template_contents.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_call_with_document': has_extended_attribute_value(
            interface, 'ConstructorCallWith', 'Document'),  # [ConstructorCallWith=Document]
        'is_constructor_call_with_execution_context': has_extended_attribute_value(
            interface, 'ConstructorCallWith', 'ExecutionContext'),  # [ConstructorCallWith=ExeuctionContext]
        'is_constructor_raises_exception': extended_attributes.get('RaisesException') == 'Constructor',  # [RaisesException=Constructor]
        'named_constructor': named_constructor,
    })

    # Constants
    template_contents.update({
        'constants': [generate_constant(constant) for constant in interface.constants],
        'do_not_check_constants': 'DoNotCheckConstants' in extended_attributes,
    })

    # Attributes
    attributes = [v8_attributes.generate_attribute(interface, attribute)
                  for attribute in interface.attributes]
    template_contents.update({
        'attributes': attributes,
        'has_accessors': any(attribute['is_expose_js_accessors'] 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'])
             for attribute in attributes),
        'has_constructor_attributes': any(attribute['constructor_type'] for attribute in attributes),
        'has_per_context_enabled_attributes': any(attribute['per_context_enabled_function'] for attribute in attributes),
        'has_replaceable_attributes': any(attribute['is_replaceable'] for attribute in attributes),
    })

    # Methods
    methods = [v8_methods.generate_method(interface, method)
               for method in interface.operations
               if method.name]  # Skip anonymous special operations (methods)
    generate_overloads(methods)
    for method in methods:
        method['do_generate_method_configuration'] = (
            method['do_not_check_signature'] and
            not method['per_context_enabled_function'] and
            # For overloaded methods, only generate one accessor
            ('overload_index' not in method or method['overload_index'] == 1))

    template_contents.update({
        'has_origin_safe_method_setter': any(
            method['is_check_security_for_frame'] and not method['is_read_only']
            for method in methods),
        'has_method_configuration': any(method['do_generate_method_configuration'] for method in methods),
        'has_per_context_enabled_methods': any(method['per_context_enabled_function'] for method in methods),
        'methods': methods,
    })

    template_contents.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 template_contents
Пример #43
0
def generate_interface(interface):
    includes.clear()
    includes.update(INTERFACE_CPP_INCLUDES)
    header_includes = set(INTERFACE_H_INCLUDES)

    parent_interface = interface.parent
    if parent_interface:
        header_includes.update(
            v8_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/v8/ScriptController.h', 'bindings/v8/V8WindowShell.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/v8/BindingSecurity.h')

    # [DependentLifetime]
    is_dependent_lifetime = 'DependentLifetime' in extended_attributes

    # [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/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(used_as_argument=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,
            'v8_type': v8_types.v8_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()

    # [SpecialWrapFor]
    if 'SpecialWrapFor' in extended_attributes:
        special_wrap_for = extended_attributes['SpecialWrapFor'].split('|')
    else:
        special_wrap_for = []
    for special_wrap_interface in special_wrap_for:
        v8_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)

    template_contents = {
        'conditional_string':
        conditional_string(interface),  # [Conditional]
        'cpp_class':
        cpp_name(interface),
        'gc_type':
        this_gc_type,
        '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'),
        'measure_as':
        v8_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,
        'v8_class':
        v8_utilities.v8_class_name(interface),
        'wrapper_configuration':
        'WrapperConfiguration::Dependent' if
        (has_visit_dom_wrapper or is_active_dom_object
         or is_dependent_lifetime) else 'WrapperConfiguration::Independent',
    }

    # Constructors
    constructors = [
        generate_constructor(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:
        template_contents['constructor_overloads'] = generate_overloads(
            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/v8/Dictionary.h')
        if any_type_attributes:
            includes.add('bindings/v8/SerializedScriptValue.h')

    # [NamedConstructor]
    named_constructor = generate_named_constructor(interface)

    if (constructors or custom_constructors or has_event_constructor
            or named_constructor):
        includes.add('bindings/v8/V8ObjectConstructor.h')
        includes.add('core/frame/DOMWindow.h')

    template_contents.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_call_with_document':
        has_extended_attribute_value(
            interface, 'ConstructorCallWith',
            'Document'),  # [ConstructorCallWith=Document]
        'is_constructor_call_with_execution_context':
        has_extended_attribute_value(
            interface, 'ConstructorCallWith',
            'ExecutionContext'),  # [ConstructorCallWith=ExeuctionContext]
        'is_constructor_raises_exception':
        extended_attributes.get('RaisesException') ==
        'Constructor',  # [RaisesException=Constructor]
        'named_constructor':
        named_constructor,
    })

    # Constants
    template_contents.update({
        'constants':
        [generate_constant(constant) for constant in interface.constants],
        'do_not_check_constants':
        'DoNotCheckConstants' in extended_attributes,
    })

    # Attributes
    attributes = [
        v8_attributes.generate_attribute(interface, attribute)
        for attribute in interface.attributes
    ]
    template_contents.update({
        'attributes':
        attributes,
        'has_accessors':
        any(attribute['is_expose_js_accessors'] 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'])
            for attribute in attributes),
        'has_constructor_attributes':
        any(attribute['constructor_type'] for attribute in attributes),
        'has_per_context_enabled_attributes':
        any(attribute['per_context_enabled_function']
            for attribute in attributes),
        'has_replaceable_attributes':
        any(attribute['is_replaceable'] for attribute in attributes),
    })

    # Methods
    methods = [
        v8_methods.generate_method(interface, method)
        for method in interface.operations if method.name
    ]  # Skip anonymous special operations (methods)
    generate_method_overloads(methods)
    for method in methods:
        method['do_generate_method_configuration'] = (
            method['do_not_check_signature']
            and not method['per_context_enabled_function'] and
            # For overloaded methods, only generate one accessor
            ('overload_index' not in method or method['overload_index'] == 1))

    template_contents.update({
        'has_origin_safe_method_setter':
        any(method['is_check_security_for_frame']
            and not method['is_read_only'] for method in methods),
        'has_method_configuration':
        any(method['do_generate_method_configuration'] for method in methods),
        'has_per_context_enabled_methods':
        any(method['per_context_enabled_function'] for method in methods),
        'methods':
        methods,
    })

    template_contents.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 template_contents
Пример #44
0
def interface_context(interface):
    context = v8_interface.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(
            dart_types.includes_for_interface(parent_interface))
    extended_attributes = interface.extended_attributes

    if inherits_interface(interface.name, 'EventTarget'):
        includes.update(['bindings/dart_event_listener.h'])

    # [SetWrapperReferenceTo]
    set_wrapper_reference_to_list = [
        {
            'name': argument.name,
            # FIXME: properly should be:
            # 'cpp_type': argument.idl_type.cpp_type_args(used_as_rvalue_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,
        } 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()

    context.update({
        'cpp_class': DartUtilities.cpp_name(interface),
        'header_includes': header_includes,
        'set_wrapper_reference_to_list': set_wrapper_reference_to_list,
        'dart_class': dart_types.dart_type(interface.name),
    })

    # 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.update(
            {'constructor_overloads': overloads_context(constructors)})

    # [CustomConstructor]
    custom_constructors = [
        custom_constructor_context(interface, constructor)
        for constructor in interface.custom_constructors
    ]

    # [NamedConstructor]
    named_constructor = generate_named_constructor(interface)

    generate_method_native_entries(interface, constructors, 'Constructor')
    generate_method_native_entries(interface, custom_constructors,
                                   'Constructor')
    if named_constructor:
        generate_method_native_entries(interface, [named_constructor],
                                       'Constructor')
    event_constructor = None
    if context['has_event_constructor']:
        event_constructor = {
            'native_entries': [
                DartUtilities.generate_native_entry(interface.name, None,
                                                    'Constructor', False, 2)
            ],
        }

    context.update({
        'constructors':
        constructors,
        'custom_constructors':
        custom_constructors,
        'event_constructor':
        event_constructor,
        'has_custom_constructor':
        bool(custom_constructors),
        'interface_length':
        v8_interface.interface_length(interface,
                                      constructors + custom_constructors),
        'is_constructor_call_with_execution_context':
        DartUtilities.has_extended_attribute_value(
            interface, 'ConstructorCallWith',
            'ExecutionContext'),  # [ConstructorCallWith=ExeuctionContext]
        'named_constructor':
        named_constructor,
    })

    # Attributes
    attributes = [
        dart_attributes.attribute_context(interface, attribute)
        for attribute in interface.attributes
        if not v8_attributes.is_constructor_attribute(attribute)
    ]
    context.update({
        'attributes':
        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 = [
        dart_methods.method_context(interface, method)
        for method in interface.operations
        # Skip anonymous special operations (methods name empty).
        if (method.name and
            # detect unnamed getters from v8_interface.
            method.name != 'anonymousNamedGetter')
    ]
    compute_method_overloads_context(methods)
    for method in methods:
        method['do_generate_method_configuration'] = (
            # For overloaded methods, only generate one accessor
            ('overload_index' not in method or method['overload_index'] == 1))

    for method in methods:
        assert 'overloads' not in method, 'Dart does not support overloads, %s in %s' % (
            method['name'], interface.name)

    generate_method_native_entries(interface, methods, 'Method')

    context.update({
        'has_method_configuration':
        any(method['do_generate_method_configuration'] for method in methods),
        'methods':
        methods,
    })

    context.update({
        'indexed_property_getter':
        indexed_property_getter(interface),
        'indexed_property_setter':
        indexed_property_setter(interface),
        'indexed_property_deleter':
        v8_interface.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':
        v8_interface.named_property_deleter(interface),
    })

    generate_native_entries_for_specials(interface, context)

    native_entries = generate_interface_native_entries(context)

    context.update({
        'native_entries': native_entries,
    })

    return context
Пример #45
0
def generate_interface(interface):
    includes.clear()
    includes.update(INTERFACE_CPP_INCLUDES)
    header_includes = INTERFACE_H_INCLUDES

    parent_interface = interface.parent
    if parent_interface:
        header_includes.update(v8_types.includes_for_type(parent_interface))
    extended_attributes = interface.extended_attributes

    # [CheckSecurity]
    is_check_security = 'CheckSecurity' in extended_attributes
    if is_check_security:
        includes.add('bindings/v8/BindingSecurity.h')

    # [GenerateVisitDOMWrapper]
    generate_visit_dom_wrapper_function = extended_attributes.get(
        'GenerateVisitDOMWrapper')
    if generate_visit_dom_wrapper_function:
        includes.update(['bindings/v8/V8GCController.h', 'core/dom/Element.h'])

    # [MeasureAs]
    is_measure_as = 'MeasureAs' in extended_attributes
    if is_measure_as:
        includes.add('core/frame/UseCounter.h')

    # [SpecialWrapFor]
    if 'SpecialWrapFor' in extended_attributes:
        special_wrap_for = extended_attributes['SpecialWrapFor'].split('|')
    else:
        special_wrap_for = []
    for special_wrap_interface in special_wrap_for:
        v8_types.add_includes_for_type(special_wrap_interface)

    # Constructors
    constructors = [
        generate_constructor(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'
    ]
    generate_constructor_overloads(constructors)

    # [CustomConstructor]
    has_custom_constructor = 'CustomConstructor' in extended_attributes

    # [EventConstructor]
    has_event_constructor = 'EventConstructor' in extended_attributes
    any_type_attributes = [
        attribute for attribute in interface.attributes
        if attribute.idl_type == 'any'
    ]
    if has_event_constructor:
        includes.add('bindings/v8/Dictionary.h')
        if any_type_attributes:
            includes.add('bindings/v8/SerializedScriptValue.h')

    # [NamedConstructor]
    if 'NamedConstructor' in extended_attributes:
        # FIXME: parser should return named constructor separately;
        # included in constructors (and only name stored in extended attribute)
        # for Perl compatibility
        named_constructor = {'name': extended_attributes['NamedConstructor']}
    else:
        named_constructor = None

    if (constructors or has_custom_constructor or has_event_constructor
            or named_constructor):
        includes.add('bindings/v8/V8ObjectConstructor.h')

    template_contents = {
        'any_type_attributes':
        any_type_attributes,
        'conditional_string':
        conditional_string(interface),  # [Conditional]
        'constructors':
        constructors,
        'cpp_class':
        cpp_name(interface),
        'generate_visit_dom_wrapper_function':
        generate_visit_dom_wrapper_function,
        'has_custom_constructor':
        has_custom_constructor,
        '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_event_constructor':
        has_event_constructor,
        'has_visit_dom_wrapper': (
            # [Custom=Wrap], [GenerateVisitDOMWrapper]
            has_extended_attribute_value(interface, 'Custom',
                                         'VisitDOMWrapper')
            or 'GenerateVisitDOMWrapper' in extended_attributes),
        'header_includes':
        header_includes,
        'interface_length':
        interface_length(interface, constructors),
        'interface_name':
        interface.name,
        'is_active_dom_object':
        'ActiveDOMObject' in extended_attributes,  # [ActiveDOMObject]
        'is_check_security':
        is_check_security,
        'is_constructor_call_with_document':
        has_extended_attribute_value(
            interface, 'ConstructorCallWith',
            'Document'),  # [ConstructorCallWith=Document]
        'is_constructor_call_with_execution_context':
        has_extended_attribute_value(
            interface, 'ConstructorCallWith',
            'ExecutionContext'),  # [ConstructorCallWith=ExeuctionContext]
        'is_constructor_raises_exception':
        extended_attributes.get('RaisesException') ==
        'Constructor',  # [RaisesException=Constructor]
        'is_dependent_lifetime':
        'DependentLifetime' in extended_attributes,  # [DependentLifetime]
        'is_event_target':
        inherits_interface(interface, 'EventTarget'),
        'is_node':
        inherits_interface(interface, 'Node'),
        'measure_as':
        v8_utilities.measure_as(interface),  # [MeasureAs]
        'named_constructor':
        named_constructor,
        'parent_interface':
        parent_interface,
        'runtime_enabled_function':
        runtime_enabled_function_name(interface),  # [RuntimeEnabled]
        'special_wrap_for':
        special_wrap_for,
        'v8_class':
        v8_utilities.v8_class_name(interface),
    }

    template_contents.update({
        'constants':
        [generate_constant(constant) for constant in interface.constants],
        'do_not_check_constants':
        'DoNotCheckConstants' in extended_attributes,
    })

    attributes = [
        v8_attributes.generate_attribute(interface, attribute)
        for attribute in interface.attributes
    ]
    template_contents.update({
        'attributes':
        attributes,
        'has_accessors':
        any(attribute['is_expose_js_accessors'] for attribute in attributes),
        'has_constructor_attributes':
        any(attribute['constructor_type'] for attribute in attributes),
        'has_per_context_enabled_attributes':
        any(attribute['per_context_enabled_function']
            for attribute in attributes),
        'has_replaceable_attributes':
        any(attribute['is_replaceable'] for attribute in attributes),
    })

    methods = [
        v8_methods.generate_method(interface, method)
        for method in interface.operations
    ]
    generate_overloads(methods)
    for method in methods:
        method['do_generate_method_configuration'] = (
            method['do_not_check_signature']
            and not method['per_context_enabled_function'] and
            # For overloaded methods, only generate one accessor
            ('overload_index' not in method or method['overload_index'] == 1))

    template_contents.update({
        'has_origin_safe_method_setter':
        any(method['is_check_security_for_frame']
            and not method['is_read_only'] for method in methods),
        'has_method_configuration':
        any(method['do_generate_method_configuration'] for method in methods),
        'has_per_context_enabled_methods':
        any(method['per_context_enabled_function'] for method in methods),
        'methods':
        methods,
    })

    return template_contents
Пример #46
0
def generate_interface(interface):
    includes.clear()
    includes.update(INTERFACE_CPP_INCLUDES)
    header_includes = set(INTERFACE_H_INCLUDES)

    parent_interface = interface.parent
    if parent_interface:
        header_includes.update(v8_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/v8/ScriptController.h", "bindings/v8/V8WindowShell.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/v8/BindingSecurity.h")

    # [DependentLifetime]
    is_dependent_lifetime = "DependentLifetime" in extended_attributes

    # [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/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(used_as_argument=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,
            "v8_type": v8_types.v8_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()

    # [SpecialWrapFor]
    if "SpecialWrapFor" in extended_attributes:
        special_wrap_for = extended_attributes["SpecialWrapFor"].split("|")
    else:
        special_wrap_for = []
    for special_wrap_interface in special_wrap_for:
        v8_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)

    template_contents = {
        "conditional_string": conditional_string(interface),  # [Conditional]
        "cpp_class": cpp_name(interface),
        "gc_type": this_gc_type,
        "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"),
        "measure_as": v8_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,
        "v8_class": v8_utilities.v8_class_name(interface),
        "wrapper_configuration": "WrapperConfiguration::Dependent"
        if (has_visit_dom_wrapper or is_active_dom_object or is_dependent_lifetime)
        else "WrapperConfiguration::Independent",
    }

    # Constructors
    constructors = [
        generate_constructor(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:
        template_contents["constructor_overloads"] = generate_overloads(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/v8/Dictionary.h")
        if any_type_attributes:
            includes.add("bindings/v8/SerializedScriptValue.h")

    # [NamedConstructor]
    named_constructor = generate_named_constructor(interface)

    if constructors or custom_constructors or has_event_constructor or named_constructor:
        includes.add("bindings/v8/V8ObjectConstructor.h")
        includes.add("core/frame/DOMWindow.h")

    template_contents.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_call_with_document": has_extended_attribute_value(
                interface, "ConstructorCallWith", "Document"
            ),  # [ConstructorCallWith=Document]
            "is_constructor_call_with_execution_context": has_extended_attribute_value(
                interface, "ConstructorCallWith", "ExecutionContext"
            ),  # [ConstructorCallWith=ExeuctionContext]
            "is_constructor_raises_exception": extended_attributes.get("RaisesException")
            == "Constructor",  # [RaisesException=Constructor]
            "named_constructor": named_constructor,
        }
    )

    # Constants
    template_contents.update(
        {
            "constants": [generate_constant(constant) for constant in interface.constants],
            "do_not_check_constants": "DoNotCheckConstants" in extended_attributes,
        }
    )

    # Attributes
    attributes = [v8_attributes.generate_attribute(interface, attribute) for attribute in interface.attributes]
    template_contents.update(
        {
            "attributes": attributes,
            "has_accessors": any(attribute["is_expose_js_accessors"] 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"]
                )
                for attribute in attributes
            ),
            "has_constructor_attributes": any(attribute["constructor_type"] for attribute in attributes),
            "has_per_context_enabled_attributes": any(
                attribute["per_context_enabled_function"] for attribute in attributes
            ),
            "has_replaceable_attributes": any(attribute["is_replaceable"] for attribute in attributes),
        }
    )

    # Methods
    methods = [
        v8_methods.generate_method(interface, method) for method in interface.operations if method.name
    ]  # Skip anonymous special operations (methods)
    generate_method_overloads(methods)
    for method in methods:
        method["do_generate_method_configuration"] = (
            method["do_not_check_signature"]
            and not method["per_context_enabled_function"]
            and
            # For overloaded methods, only generate one accessor
            ("overload_index" not in method or method["overload_index"] == 1)
        )

    template_contents.update(
        {
            "has_origin_safe_method_setter": any(
                method["is_check_security_for_frame"] and not method["is_read_only"] for method in methods
            ),
            "has_method_configuration": any(method["do_generate_method_configuration"] for method in methods),
            "has_per_context_enabled_methods": any(method["per_context_enabled_function"] for method in methods),
            "methods": methods,
        }
    )

    template_contents.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 template_contents
Пример #47
0
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(
            v8_types.includes_for_interface(parent_interface))
    extended_attributes = interface.extended_attributes

    # [ActiveDOMObject]
    is_active_dom_object = 'ActiveDOMObject' in extended_attributes

    # [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 = v8_methods.method_context(interface,
                                                    iterator_operation)

    # [SetWrapperReferenceFrom]
    reachable_node_function = extended_attributes.get(
        'SetWrapperReferenceFrom')
    if reachable_node_function:
        includes.update(['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,
        } 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:
        v8_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)

    wrapper_class_id = ('NodeClassId' if inherits_interface(
        interface.name, 'Node') else 'ObjectClassId')

    context = {
        'cpp_class':
        cpp_name(interface),
        '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_dependent_lifetime':
        is_dependent_lifetime,
        'is_exception':
        interface.is_exception,
        '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',
        'parent_interface':
        parent_interface,
        'reachable_node_function':
        reachable_node_function,
        'set_wrapper_reference_to_list':
        set_wrapper_reference_to_list,
        'special_wrap_for':
        special_wrap_for,
        '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'
    ]

    # [NamedConstructor]
    named_constructor = named_constructor_context(interface)

    if (constructors or custom_constructors or has_event_constructor
            or named_constructor):
        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,
        'has_constant_configuration': True,
    })

    # Attributes
    attributes = [
        v8_attributes.attribute_context(interface, attribute)
        for attribute in interface.attributes
    ]
    context.update({
        'attributes':
        attributes,
        'has_conditional_attributes':
        any(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 = [
        v8_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(v8_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']
            conditionally_exposed_function = overloads['exposed_test_all']
            has_custom_registration = overloads['has_custom_registration_all']
        else:
            conditionally_exposed_function = method['exposed_test']
            has_custom_registration = method['has_custom_registration']

        if conditionally_exposed_function:
            conditionally_enabled_methods.append(method)
            continue
        if has_custom_registration:
            custom_registration_methods.append(method)
            continue
        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,
        '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