Esempio n. 1
0
def is_keep_alive_for_gc(interface, attribute):
    idl_type = attribute.idl_type
    base_idl_type = idl_type.base_type
    extended_attributes = attribute.extended_attributes
    return (
        # For readonly attributes, for performance reasons we keep the attribute
        # wrapper alive while the owner wrapper is alive, because the attribute
        # never changes.
        (
            attribute.is_read_only
            and idl_type.is_wrapper_type
            and
            # There are some exceptions, however:
            not (
                # Node lifetime is managed by object grouping.
                inherits_interface(interface.name, "Node")
                or inherits_interface(base_idl_type, "Node")
                or
                # A self-reference is unnecessary.
                attribute.name == "self"
                or
                # FIXME: Remove these hard-coded hacks.
                base_idl_type in ["EventTarget", "Window"]
                or base_idl_type.startswith(("HTML", "SVG"))
            )
        )
    )
Esempio n. 2
0
def v8_set_return_value(interface_name,
                        method,
                        cpp_value,
                        for_main_world=False):
    idl_type = method.idl_type
    extended_attributes = method.extended_attributes
    if not idl_type or idl_type.name == 'void':
        # Constructors and void methods don't have a return type
        return None

    release = False
    # [CallWith=ScriptState], [RaisesException]
    if (has_extended_attribute_value(method, 'CallWith', 'ScriptState')
            or 'RaisesException' in extended_attributes
            or idl_type.is_union_type):
        cpp_value = 'result'  # use local variable for value
        release = idl_type.release

    script_wrappable = 'impl' if inherits_interface(interface_name,
                                                    'Node') else ''
    return idl_type.v8_set_return_value(cpp_value,
                                        extended_attributes,
                                        script_wrappable=script_wrappable,
                                        release=release,
                                        for_main_world=for_main_world)
Esempio n. 3
0
def dart_set_return_value(interface_name,
                          method,
                          cpp_value,
                          for_main_world=False):
    idl_type = method.idl_type
    extended_attributes = method.extended_attributes
    if not idl_type or idl_type.name == 'void':
        # Constructors and void methods don't have a return type
        return None

    release = False

    if idl_type.is_union_type:
        release = idl_type.release

    # [CallWith=ScriptState], [RaisesException]


# TODO(terry): Disable ScriptState temporarily need to handle.
#    if (has_extended_attribute_value(method, 'CallWith', 'ScriptState') or
#        'RaisesException' in extended_attributes or
#        idl_type.is_union_type):
#        cpp_value = 'result'  # use local variable for value
#        release = idl_type.release

    auto_scope = not 'DartNoAutoScope' in extended_attributes
    script_wrappable = 'impl' if inherits_interface(interface_name,
                                                    'Node') else ''
    return idl_type.dart_set_return_value(cpp_value,
                                          extended_attributes,
                                          script_wrappable=script_wrappable,
                                          release=release,
                                          for_main_world=for_main_world,
                                          auto_scope=auto_scope)
Esempio n. 4
0
def v8_set_return_value(interface_name, method, cpp_value, for_main_world=False):
    idl_type = method.idl_type
    extended_attributes = method.extended_attributes
    if not idl_type or idl_type.name == "void":
        # Constructors and void methods don't have a return type
        return None

    if (
        "ImplementedInPrivateScript" in extended_attributes
        and not idl_type.is_wrapper_type
        and not idl_type.is_basic_type
    ):
        raise Exception("Private scripts supports only primitive types and DOM wrappers.")

    release = False
    # [CallWith=ScriptState], [RaisesException]
    if use_local_result(method):
        if idl_type.is_explicit_nullable:
            # result is of type Nullable<T>
            cpp_value = "result.get()"
        else:
            cpp_value = "result"
        release = idl_type.release

    script_wrappable = "impl" if inherits_interface(interface_name, "Node") else ""
    return idl_type.v8_set_return_value(
        cpp_value,
        extended_attributes,
        script_wrappable=script_wrappable,
        release=release,
        for_main_world=for_main_world,
    )
Esempio n. 5
0
def dart_set_return_value(interface_name, method, cpp_value, for_main_world=False):
    idl_type = method.idl_type
    extended_attributes = method.extended_attributes
    if not idl_type or idl_type.name == 'void':
        # Constructors and void methods don't have a return type
        return None

    release = False

    if idl_type.is_union_type:
        release = idl_type.release

    # [CallWith=ScriptState], [RaisesException]
# TODO(terry): Disable ScriptState temporarily need to handle.
#    if (has_extended_attribute_value(method, 'CallWith', 'ScriptState') or
#        'RaisesException' in extended_attributes or
#        idl_type.is_union_type):
#        cpp_value = 'result'  # use local variable for value
#        release = idl_type.release

    auto_scope = not 'DartNoAutoScope' in extended_attributes
    script_wrappable = 'impl' if inherits_interface(interface_name, 'Node') else ''
    return idl_type.dart_set_return_value(cpp_value, extended_attributes,
                                          script_wrappable=script_wrappable,
                                          release=release,
                                          for_main_world=for_main_world,
                                          auto_scope=auto_scope)
Esempio n. 6
0
def ext_set_return_value(interface_name,
                         method,
                         cpp_value,
                         for_main_world=False):
    idl_type = method.idl_type
    extended_attributes = method.extended_attributes
    if not idl_type or idl_type.name == 'void':
        # Constructors and void methods don't have a return type
        return None

    if ('ImplementedInPrivateScript' in extended_attributes
            and not idl_type.is_wrapper_type and not idl_type.is_basic_type):
        raise Exception(
            'Private scripts supports only primitive types and DOM wrappers.')

    release = False
    # [CallWith=ScriptState], [RaisesException]
    if use_local_result(method):
        if idl_type.is_explicit_nullable:
            # result is of type Nullable<T>
            cpp_value = 'result.get()'
        else:
            cpp_value = 'result'
        release = idl_type.release

    script_wrappable = 'impl' if inherits_interface(interface_name,
                                                    'Node') else ''
    return idl_type.ext_set_return_value(cpp_value,
                                         extended_attributes,
                                         script_wrappable=script_wrappable,
                                         release=release,
                                         for_main_world=for_main_world)
Esempio n. 7
0
def v8_set_return_value(interface_name,
                        method,
                        cpp_value,
                        for_main_world=False):
    idl_type = method.idl_type
    extended_attributes = method.extended_attributes
    if not idl_type or idl_type.name == 'void':
        # Constructors and void methods don't have a return type
        return None

    # [CallWith=ScriptState], [RaisesException]
    if use_local_result(method):
        if idl_type.is_explicit_nullable:
            # result is of type Nullable<T>
            cpp_value = 'result.Get()'
        else:
            cpp_value = 'result'

    script_wrappable = 'impl' if inherits_interface(interface_name,
                                                    'Node') else ''
    return idl_type.v8_set_return_value(cpp_value,
                                        extended_attributes,
                                        script_wrappable=script_wrappable,
                                        for_main_world=for_main_world,
                                        is_static=method.is_static)
Esempio n. 8
0
def is_keep_alive_for_gc(interface, attribute):
    idl_type = attribute.idl_type
    base_idl_type = idl_type.base_type
    extended_attributes = attribute.extended_attributes
    return (
        # For readonly attributes, for performance reasons we keep the attribute
        # wrapper alive while the owner wrapper is alive, because the attribute
        # never changes.
        (
            attribute.is_read_only and idl_type.is_wrapper_type and
            # There are some exceptions, however:
            not (
                # Node lifetime is managed by object grouping.
                inherits_interface(interface.name, 'Node')
                or inherits_interface(base_idl_type, 'Node') or
                # A self-reference is unnecessary.
                attribute.name == 'self' or
                # FIXME: Remove these hard-coded hacks.
                base_idl_type in ['EventTarget', 'Window']
                or base_idl_type.startswith(('HTML', 'SVG')))))
Esempio n. 9
0
def v8_set_return_value(interface_name, method, cpp_value, for_main_world=False):
    idl_type = method.idl_type
    extended_attributes = method.extended_attributes
    if idl_type.name == 'void':
        return None

    release = False
    # [CallWith=ScriptState], [RaisesException]
    if (has_extended_attribute_value(method, 'CallWith', 'ScriptState') or
        'RaisesException' in extended_attributes or
        idl_type.is_union_type):
        cpp_value = 'result'  # use local variable for value
        release = idl_type.release

    script_wrappable = 'imp' if inherits_interface(interface_name, 'Node') else ''
    return idl_type.v8_set_return_value(cpp_value, extended_attributes, script_wrappable=script_wrappable, release=release, for_main_world=for_main_world)
Esempio n. 10
0
def v8_set_return_value(interface_name, method, cpp_value, for_main_world=False):
    idl_type = method.idl_type
    extended_attributes = method.extended_attributes
    if not idl_type or idl_type.name == 'void':
        # Constructors and void methods don't have a return type
        return None

    # [CallWith=ScriptState], [RaisesException]
    if use_local_result(method):
        if idl_type.is_explicit_nullable:
            # result is of type Nullable<T>
            cpp_value = 'result.Get()'
        else:
            cpp_value = 'result'

    script_wrappable = 'impl' if inherits_interface(interface_name, 'Node') else ''
    return idl_type.v8_set_return_value(cpp_value, extended_attributes, script_wrappable=script_wrappable, for_main_world=for_main_world, is_static=method.is_static)
Esempio n. 11
0
def v8_set_return_value(interface_name, method, cpp_value, for_main_world=False):
    idl_type = method.idl_type
    extended_attributes = method.extended_attributes
    if not idl_type or idl_type.name == 'void':
        # Constructors and void methods don't have a return type
        return None

    if ('ImplementedInPrivateScript' in extended_attributes and
            not idl_type.is_wrapper_type and
            not idl_type.is_basic_type):
        raise Exception('Private scripts supports only primitive types and DOM wrappers.')

    # [CallWith=ScriptState], [RaisesException]
    if use_local_result(method):
        if idl_type.is_explicit_nullable:
            # result is of type Nullable<T>
            cpp_value = 'result.get()'
        else:
            cpp_value = 'result'

    script_wrappable = 'impl' if inherits_interface(interface_name, 'Node') else ''
    return idl_type.v8_set_return_value(cpp_value, extended_attributes, script_wrappable=script_wrappable, for_main_world=for_main_world, is_static=method.is_static)
Esempio n. 12
0
def v8_set_return_value(interface_name, method, cpp_value, for_main_world=False):
    idl_type = method.idl_type
    extended_attributes = method.extended_attributes
    if not idl_type or idl_type.name == 'void':
        # Constructors and void methods don't have a return type
        return None

    if ('ImplementedInPrivateScript' in extended_attributes and
        not idl_type.is_wrapper_type and
        not idl_type.is_basic_type):
        raise Exception('Private scripts supports only primitive types and DOM wrappers.')

    release = False
    # [CallWith=ScriptState], [RaisesException]
    if (has_extended_attribute_value(method, 'CallWith', 'ScriptState') or
        'ImplementedInPrivateScript' in extended_attributes or
        'RaisesException' in extended_attributes or
        idl_type.is_union_type):
        cpp_value = 'result'  # use local variable for value
        release = idl_type.release

    script_wrappable = 'impl' if inherits_interface(interface_name, 'Node') else ''
    return idl_type.v8_set_return_value(cpp_value, extended_attributes, script_wrappable=script_wrappable, release=release, for_main_world=for_main_world)
Esempio n. 13
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
Esempio n. 14
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
Esempio n. 15
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
Esempio n. 16
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
Esempio n. 17
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
Esempio n. 18
0
def setter_context(interface, attribute, interfaces, context):
    if 'PutForwards' in attribute.extended_attributes:
        # Make sure the target interface and attribute exist.
        target_interface_name = attribute.idl_type.base_type
        target_attribute_name = attribute.extended_attributes['PutForwards']
        interface = interfaces[target_interface_name]
        try:
            next(candidate for candidate in interface.attributes
                 if candidate.name == target_attribute_name)
        except StopIteration:
            raise Exception('[PutForward] target not found:\n'
                            'Attribute "%s" is not present in interface "%s"' %
                            (target_attribute_name, target_interface_name))
        context['target_attribute_name'] = target_attribute_name
        return

    if ('Replaceable' in attribute.extended_attributes):
        # Create the property, and early-return if an exception is thrown.
        # Subsequent cleanup code may not be prepared to handle a pending
        # exception.
        context['cpp_setter'] = (
            'if (info.Holder()->CreateDataProperty(' +
            'info.GetIsolate()->GetCurrentContext(), ' +
            'property_name, v8_value).IsNothing())' + '\n  return')
        return

    extended_attributes = attribute.extended_attributes
    idl_type = attribute.idl_type

    # [RaisesException], [RaisesException=Setter]
    is_setter_raises_exception = (
        'RaisesException' in extended_attributes
        and extended_attributes['RaisesException'] in [None, 'Setter'])

    has_type_checking_interface = idl_type.is_wrapper_type

    use_common_reflection_setter = False
    # Enable use_common_reflection_setter if
    #  * extended_attributes is [CEReactions, Reflect] or
    #    [CEReactions, Reflect, RuntimeEnabled],
    #  * the type is boolean, DOMString, or DOMString?, and
    #  * the interface inherits from 'Element'.
    if ('Reflect' in extended_attributes
            and 'CEReactions' in extended_attributes
            and str(idl_type) in ('boolean', 'DOMString', 'DOMString?')
            and inherits_interface(interface.name, 'Element')):
        if (len(extended_attributes) == 2
                or (len(extended_attributes) == 3
                    and 'RuntimeEnabled' in extended_attributes)):
            use_common_reflection_setter = True

    context.update({
        'has_setter_exception_state':
        is_setter_raises_exception or has_type_checking_interface
        or idl_type.v8_conversion_needs_exception_state,
        'has_type_checking_interface':
        has_type_checking_interface,
        'is_setter_call_with_execution_context':
        has_extended_attribute_value(attribute, 'SetterCallWith',
                                     'ExecutionContext'),
        'is_setter_call_with_script_state':
        has_extended_attribute_value(attribute, 'SetterCallWith',
                                     'ScriptState'),
        'is_setter_raises_exception':
        is_setter_raises_exception,
        'use_common_reflection_setter':
        use_common_reflection_setter,
        'v8_value_to_local_cpp_value':
        idl_type.v8_value_to_local_cpp_value(
            extended_attributes,
            'v8_value',
            'cpp_value',
            code_generation_target='attribute_set'),
    })

    # setter_expression() depends on context values we set above.
    context['cpp_setter'] = setter_expression(interface, attribute, context)
Esempio n. 19
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
Esempio n. 20
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
Esempio n. 21
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
Esempio n. 22
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
Esempio n. 23
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