コード例 #1
0
    def test_split_add_event_listener(self):
        """Tests how EventTarget.addEventListener is split into respective
           overloads. From:

           void addEventListener(
                DOMString type,
                EventListener? listener,
                optional (AddEventListenerOptions or boolean) options)

           produces: """

        helper = IdlTestingHelper()
        type_dom_string = IdlType('DOMString')
        type_listener = IdlType('EventListener')
        type_options = IdlType('AddEventListenerOptions')
        type_boolean = IdlType('boolean')
        type_union = IdlUnionType([type_options, type_boolean])
        idl_operation = IdlOperation()
        idl_operation.arguments = [
            helper.make_stub_idl_argument('type', type_dom_string),
            helper.make_stub_idl_argument('listener', type_listener),
            helper.make_stub_idl_argument('options',
                                          type_union,
                                          is_optional=True)
        ]
        splitter = MethodOverloadSplitter(idl_operation)
        result = splitter.split_into_overloads()
        self.assertEqual(result,
                         [[type_dom_string, type_listener],
                          [type_dom_string, type_listener, type_options],
                          [type_dom_string, type_listener, type_boolean]])
コード例 #2
0
    def test_split_add_event_listener(self):
        """Tests how EventTarget.addEventListener is split into respective
           overloads. From:

           void addEventListener(
                DOMString type,
                EventListener? listener,
                optional (AddEventListenerOptions or boolean) options)

           produces: """

        helper = IdlTestingHelper()
        type_dom_string = IdlType('DOMString')
        type_listener = IdlType('EventListener')
        type_options = IdlType('AddEventListenerOptions')
        type_boolean = IdlType('boolean')
        type_union = IdlUnionType([type_options, type_boolean])
        idl_operation = IdlOperation()
        idl_operation.arguments = [
            helper.make_stub_idl_argument('type', type_dom_string),
            helper.make_stub_idl_argument('listener', type_listener),
            helper.make_stub_idl_argument('options', type_union,
                                          is_optional=True)]
        splitter = MethodOverloadSplitter(idl_operation)
        result = splitter.split_into_overloads()
        self.assertEqual(
            result,
            [[type_dom_string, type_listener],
             [type_dom_string, type_listener, type_options],
             [type_dom_string, type_listener, type_boolean]])
コード例 #3
0
    def test_split_into_overloads(self):
        helper = IdlTestingHelper()
        type_double = IdlType('double')
        type_foo = IdlType('foo')
        type_double_or_foo = IdlUnionType([type_double, type_foo])
        idl_operation = IdlOperation()

        idl_operation.arguments = []
        splitter = MethodOverloadSplitter(idl_operation)
        result = splitter.split_into_overloads()
        self.assertEqual(result, [[]])

        idl_operation.arguments = [
            helper.make_stub_idl_argument(None, type_double, True)
        ]
        splitter = MethodOverloadSplitter(idl_operation)
        result = splitter.split_into_overloads()
        self.assertEqual(result, [[], [type_double]])

        idl_operation.arguments = [
            helper.make_stub_idl_argument(None, type_double_or_foo)
        ]
        splitter = MethodOverloadSplitter(idl_operation)
        result = splitter.split_into_overloads()
        self.assertEqual(result, [[type_double], [type_foo]])
コード例 #4
0
    def test_split_into_overloads(self):
        helper = IdlTestingHelper()
        type_double = IdlType('double')
        type_foo = IdlType('foo')
        type_double_or_foo = IdlUnionType([type_double, type_foo])
        idl_operation = IdlOperation()

        idl_operation.arguments = []
        splitter = MethodOverloadSplitter(idl_operation)
        result = splitter.split_into_overloads()
        self.assertEqual(result, [[]])

        idl_operation.arguments = [
            helper.make_stub_idl_argument(None, type_double, True)
        ]
        splitter = MethodOverloadSplitter(idl_operation)
        result = splitter.split_into_overloads()
        self.assertEqual(result, [[], [type_double]])

        idl_operation.arguments = [
            helper.make_stub_idl_argument(None, type_double_or_foo)
        ]
        splitter = MethodOverloadSplitter(idl_operation)
        result = splitter.split_into_overloads()
        self.assertEqual(result, [[type_double], [type_foo]])
コード例 #5
0
def extended_attributes_to_constructors(extended_attributes):
    """Returns constructors and custom_constructors (lists of IdlOperations).

    Auxiliary function for interface_node_to_idl_interface.
    """
    constructors = []
    custom_constructors = []
    if 'Constructors' in extended_attributes:
        constructor_list = extended_attributes['Constructors']
        # If not overloaded, have index 0, otherwise index from 1
        overloaded_index = 0 if len(constructor_list) == 1 else 1
        for arguments_node in constructor_list:
            name = 'Constructor'
            arguments = arguments_node_to_arguments(arguments_node)
            constructor = IdlOperation(name=name,
                                       extended_attributes=extended_attributes,
                                       overloaded_index=overloaded_index,
                                       arguments=arguments)
            constructors.append(constructor)
            overloaded_index += 1

    if 'CustomConstructors' in extended_attributes:
        custom_constructor_list = extended_attributes['CustomConstructors']
        # If not overloaded, have index 0, otherwise index from 1
        overloaded_index = 0 if len(custom_constructor_list) == 1 else 1
        for arguments_node in custom_constructor_list:
            name = 'CustomConstructor'
            arguments = arguments_node_to_arguments(arguments_node)
            custom_constructor = IdlOperation(
                name=name,
                extended_attributes=extended_attributes,
                overloaded_index=overloaded_index,
                arguments=arguments)
            custom_constructors.append(custom_constructor)
            overloaded_index += 1

    if 'NamedConstructor' in extended_attributes:
        name = 'NamedConstructor'
        call_node = extended_attributes['NamedConstructor']
        extended_attributes['NamedConstructor'] = call_node.GetName()
        overloaded_index = None  # named constructors are not overloaded
        children = call_node.GetChildren()
        if len(children) != 1:
            raise ValueError('NamedConstructor node expects 1 child, got %s.' %
                             len(children))
        arguments_node = children[0]
        arguments = arguments_node_to_arguments(arguments_node)
        named_constructor = IdlOperation(
            name=name,
            extended_attributes=extended_attributes,
            overloaded_index=overloaded_index,
            arguments=arguments)
        # FIXME: should return named_constructor separately; appended for Perl
        constructors.append(named_constructor)

    return constructors, custom_constructors
コード例 #6
0
def extended_attributes_to_constructors(extended_attributes):
    """Returns constructors and custom_constructors (lists of IdlOperations).

    Auxiliary function for interface_node_to_idl_interface.
    """
    constructors = []
    custom_constructors = []
    if 'Constructors' in extended_attributes:
        constructor_list = extended_attributes['Constructors']
        # If not overloaded, have index 0, otherwise index from 1
        overloaded_index = 0 if len(constructor_list) == 1 else 1
        for arguments_node in constructor_list:
            name = 'Constructor'
            arguments = arguments_node_to_arguments(arguments_node)
            constructor = IdlOperation(name=name, extended_attributes=extended_attributes, overloaded_index=overloaded_index, arguments=arguments)
            constructors.append(constructor)
            overloaded_index += 1

        # Prefix 'CallWith' and 'RaisesException' with 'Constructor'
        # FIXME: Change extended attributes to include prefix explicitly.
        if 'CallWith' in extended_attributes:
            extended_attributes['ConstructorCallWith'] = extended_attributes['CallWith']
            del extended_attributes['CallWith']
        if 'RaisesException' in extended_attributes:
            extended_attributes['ConstructorRaisesException'] = extended_attributes['RaisesException']
            del extended_attributes['RaisesException']

    if 'CustomConstructors' in extended_attributes:
        custom_constructor_list = extended_attributes['CustomConstructors']
        # If not overloaded, have index 0, otherwise index from 1
        overloaded_index = 0 if len(custom_constructor_list) == 1 else 1
        for arguments_node in custom_constructor_list:
            name = 'CustomConstructor'
            arguments = arguments_node_to_arguments(arguments_node)
            custom_constructor = IdlOperation(name=name, extended_attributes=extended_attributes, overloaded_index=overloaded_index, arguments=arguments)
            custom_constructors.append(custom_constructor)
            overloaded_index += 1

    if 'NamedConstructor' in extended_attributes:
        name = 'NamedConstructor'
        call_node = extended_attributes['NamedConstructor']
        extended_attributes['NamedConstructor'] = call_node.GetName()
        overloaded_index = None  # named constructors are not overloaded
        children = call_node.GetChildren()
        if len(children) != 1:
            raise ValueError('NamedConstructor node expects 1 child, got %s.' % len(children))
        arguments_node = children[0]
        arguments = arguments_node_to_arguments(arguments_node)
        named_constructor = IdlOperation(name=name, extended_attributes=extended_attributes, overloaded_index=overloaded_index, arguments=arguments)
        constructors.append(named_constructor)

    return constructors, custom_constructors
コード例 #7
0
    def test_enumerate_argument_types(self):
        splitter = MethodOverloadSplitter(IdlOperation())
        nullable_and_primitive = IdlArgument()
        nullable_and_primitive.idl_type = IdlNullableType(IdlType('double'))
        with self.assertRaises(ValueError):
            splitter._enumerate_argument_types(nullable_and_primitive)

        argument = IdlArgument()
        foo_type = IdlType('Foo')
        bar_type = IdlType('Bar')

        argument.idl_type = foo_type
        self.assertEqual(splitter._enumerate_argument_types(argument),
                         [foo_type])

        argument.is_optional = True
        self.assertEqual(splitter._enumerate_argument_types(argument),
                         [None, foo_type])

        argument.is_optional = False
        argument.idl_type = IdlUnionType([foo_type, bar_type])
        self.assertEqual(splitter._enumerate_argument_types(argument),
                         [foo_type, bar_type])

        argument.is_optional = True
        self.assertEqual(splitter._enumerate_argument_types(argument),
                         [None, foo_type, bar_type])
コード例 #8
0
def operation_node_to_idl_operation(node):
    name = node.GetName()
    # FIXME: AST should use None internally
    if name == '_unnamed_':
        name = None

    is_static = node.GetProperty('STATIC') or False
    specials = []
    property_dictionary = node.GetProperties()
    for special_keyword in SPECIAL_KEYWORD_LIST:
        if special_keyword in property_dictionary:
            specials.append(special_keyword.lower())

    extended_attributes = None
    arguments = []
    return_type = None
    children = node.GetChildren()
    for child in children:
        child_class = child.GetClass()
        if child_class == 'Arguments':
            arguments = arguments_node_to_arguments(child)
        elif child_class == 'Type':
            return_type = type_node_to_type(child)
        elif child_class == 'ExtAttributes':
            extended_attributes = ext_attributes_node_to_extended_attributes(
                child)
        else:
            raise ValueError('Unrecognized node class: %s' % child_class)

    return IdlOperation(name=name,
                        idl_type=return_type,
                        extended_attributes=extended_attributes,
                        is_static=is_static,
                        arguments=arguments,
                        specials=specials)
コード例 #9
0
    def test_update_argument_lists(self):
        splitter = MethodOverloadSplitter(IdlOperation())
        foo_type = IdlType('Foo')
        bar_type = IdlType('Bar')
        baz_type = IdlType('Baz')
        qux_type = IdlType('Qux')

        result = splitter._update_argument_lists([[]], [foo_type])
        self.assertEqual(result, [[foo_type]])

        result = splitter._update_argument_lists([[]], [foo_type, bar_type])
        self.assertEqual(result, [[foo_type], [bar_type]])

        existing_list = [[foo_type]]
        result = splitter._update_argument_lists(existing_list, [bar_type])
        self.assertEqual(result, [[foo_type, bar_type]])

        existing_list = [[foo_type]]
        result = splitter._update_argument_lists(existing_list,
                                                 [None, bar_type])
        self.assertEqual(result, [[foo_type], [foo_type, bar_type]])

        existing_list = [[foo_type]]
        result = splitter._update_argument_lists(existing_list,
                                                 [bar_type, baz_type])
        self.assertEqual(result, [[foo_type, bar_type], [foo_type, baz_type]])

        existing_list = [[foo_type], [qux_type]]
        result = splitter._update_argument_lists(existing_list,
                                                 [bar_type, baz_type])
        self.assertEqual(result, [
            [foo_type, bar_type],
            [foo_type, baz_type],
            [qux_type, bar_type],
            [qux_type, baz_type],
        ])

        existing_list = [[foo_type], [qux_type]]
        result = splitter._update_argument_lists(existing_list,
                                                 [None, bar_type, baz_type])
        self.assertEqual(result, [
            [foo_type],
            [foo_type, bar_type],
            [foo_type, baz_type],
            [qux_type],
            [qux_type, bar_type],
            [qux_type, baz_type],
        ])

        existing_list = [[foo_type, qux_type]]
        result = splitter._update_argument_lists(existing_list,
                                                 [bar_type, baz_type])
        self.assertEqual(result, [
            [foo_type, qux_type, bar_type],
            [foo_type, qux_type, baz_type],
        ])
コード例 #10
0
def exception_operation_node_to_idl_operation(node):
    # Needed to handle one case in DOMException.idl:
    # // Override in a Mozilla compatible format
    # [NotEnumerable] DOMString toString();
    # FIXME: can we remove this? replace with a stringifier?
    extended_attributes = {}
    name = node.GetName()
    children = node.GetChildren()
    if len(children) < 1 or len(children) > 2:
        raise ValueError('ExceptionOperation node with %s children, expected 1 or 2' % len(children))

    type_node = children[0]
    return_type = type_node_to_type(type_node)

    if len(children) > 1:
        ext_attributes_node = children[1]
        extended_attributes = ext_attributes_node_to_extended_attributes(ext_attributes_node)

    return IdlOperation(name=name, idl_type=return_type, extended_attributes=extended_attributes)
コード例 #11
0
ファイル: v8_interface.py プロジェクト: 335969568/Blink-1
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
コード例 #12
0
 def make_stub_idl_operation(self, name, return_type):
     idl_operation_stub = IdlOperation()
     idl_operation_stub.name = name
     idl_operation_stub.idl_type = IdlType(return_type)
     return idl_operation_stub
コード例 #13
0
ファイル: v8_interface.py プロジェクト: takaaptech/sky_engine
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
コード例 #14
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
コード例 #15
0
 def make_stub_idl_operation(self, name, return_type):
     idl_operation_stub = IdlOperation()
     idl_operation_stub.name = name
     idl_operation_stub.idl_type = IdlType(return_type)
     return idl_operation_stub