Exemple #1
0
def setter_expression(interface, attribute, context):
    extended_attributes = attribute.extended_attributes
    arguments = DartUtilities.call_with_arguments(
        extended_attributes.get('SetterCallWith') or
        extended_attributes.get('CallWith'))

    this_setter_base_name = v8_attributes.setter_base_name(interface, attribute, arguments)
    setter_name = DartUtilities.scoped_name(interface, attribute, this_setter_base_name)

    if ('PartialInterfaceImplementedAs' in extended_attributes and
        not attribute.is_static):
        arguments.append('*receiver')
    idl_type = attribute.idl_type
    if idl_type.base_type == 'EventHandler':
        getter_name = DartUtilities.scoped_name(interface, attribute, DartUtilities.cpp_name(attribute))
        context['event_handler_getter_expression'] = '%s(%s)' % (
            getter_name, ', '.join(arguments))
        # FIXME(vsm): Do we need to support this? If so, what's our analogue of
        # V8EventListenerList?
        arguments.append('nullptr')
    else:
        attribute_name = dart_types.check_reserved_name(attribute.name)
        arguments.append(attribute_name)
    if context['is_setter_raises_exception']:
        arguments.append('es')

    return '%s(%s)' % (setter_name, ', '.join(arguments))
Exemple #2
0
def attribute_context(interface, attribute):
    # Call v8's implementation.
    context = v8_attributes.attribute_context(interface, attribute)

    extended_attributes = attribute.extended_attributes

    # Augment's Dart's information to context.
    idl_type = attribute.idl_type
    base_idl_type = idl_type.base_type
    # TODO(terry): Work around for DOMString[] base should be IDLTypeArray
    if base_idl_type == None:
        # Returns Array or Sequence.
        base_idl_type = idl_type.inner_name

    # [Custom]
    has_custom_getter = ('Custom' in extended_attributes and
                          extended_attributes['Custom'] in [None, 'Getter'])
    has_custom_setter = (not attribute.is_read_only and
                         (('Custom' in extended_attributes and
                          extended_attributes['Custom'] in [None, 'Setter'])))

    is_call_with_script_state = DartUtilities.has_extended_attribute_value(attribute, 'CallWith', 'ScriptState')

    is_auto_scope = not 'DartNoAutoScope' in extended_attributes

    context.update({
      'has_custom_getter': has_custom_getter,
      'has_custom_setter': has_custom_setter,
      'is_auto_scope': is_auto_scope,   # Used internally (outside of templates).
      'is_call_with_script_state': is_call_with_script_state,
      'auto_scope': DartUtilities.bool_to_cpp(is_auto_scope),
      'dart_type': dart_types.idl_type_to_dart_type(idl_type),
    })

    if v8_attributes.is_constructor_attribute(attribute):
        v8_attributes.constructor_getter_context(interface, attribute, context)
        return context
    if not v8_attributes.has_custom_getter(attribute):
        getter_context(interface, attribute, context)
    if (not attribute.is_read_only):
        # FIXME: We did not previously support the PutForwards attribute, so I am
        # disabling it here for now to get things compiling.
        # We may wish to revisit this.
        # if (not has_custom_setter(attribute) and
        # (not attribute.is_read_only or 'PutForwards' in extended_attributes)):
        setter_context(interface, attribute, context)

    native_entry_getter = \
        DartUtilities.generate_native_entry(
            interface.name, attribute.name, 'Getter', attribute.is_static, 0)
    native_entry_setter = \
        DartUtilities.generate_native_entry(
            interface.name, attribute.name, 'Setter', attribute.is_static, 1)
    context.update({
        'native_entry_getter': native_entry_getter,
        'native_entry_setter': native_entry_setter,
    })

    return context
def attribute_context(interface, attribute):
    # Call v8's implementation.
    context = v8_attributes.attribute_context(interface, attribute)

    extended_attributes = attribute.extended_attributes

    # Augment's Dart's information to context.
    idl_type = attribute.idl_type
    base_idl_type = idl_type.base_type
    # TODO(terry): Work around for DOMString[] base should be IDLTypeArray
    if base_idl_type == None:
        # Returns Array or Sequence.
        base_idl_type = idl_type.inner_name

    # [Custom]
    has_custom_getter = ('Custom' in extended_attributes and
                          extended_attributes['Custom'] in [None, 'Getter'])
    has_custom_setter = (not attribute.is_read_only and
                         (('Custom' in extended_attributes and
                          extended_attributes['Custom'] in [None, 'Setter'])))

    is_call_with_script_state = DartUtilities.has_extended_attribute_value(attribute, 'CallWith', 'ScriptState')

    is_auto_scope = not 'DartNoAutoScope' in extended_attributes

    context.update({
      'has_custom_getter': has_custom_getter,
      'has_custom_setter': has_custom_setter,
      'is_auto_scope': is_auto_scope,   # Used internally (outside of templates).
      'is_call_with_script_state': is_call_with_script_state,
      'auto_scope': DartUtilities.bool_to_cpp(is_auto_scope),
      'dart_type': dart_types.idl_type_to_dart_type(idl_type),
    })

    if v8_attributes.is_constructor_attribute(attribute):
        v8_attributes.constructor_getter_context(interface, attribute, context)
        return context
    if not v8_attributes.has_custom_getter(attribute):
        getter_context(interface, attribute, context)
    if (not attribute.is_read_only):
        # FIXME: We did not previously support the PutForwards attribute, so I am
        # disabling it here for now to get things compiling.
        # We may wish to revisit this.
        # if (not has_custom_setter(attribute) and
        # (not attribute.is_read_only or 'PutForwards' in extended_attributes)):
        setter_context(interface, attribute, context)

    native_entry_getter = \
        DartUtilities.generate_native_entry(
            interface.name, attribute.name, 'Getter', attribute.is_static, 0)
    native_entry_setter = \
        DartUtilities.generate_native_entry(
            interface.name, attribute.name, 'Setter', attribute.is_static, 1)
    context.update({
        'native_entry_getter': native_entry_getter,
        'native_entry_setter': native_entry_setter,
    })

    return context
Exemple #4
0
def method_context(interface, method):
    context = v8_methods.method_context(interface, method)

    arguments = method.arguments
    extended_attributes = method.extended_attributes
    idl_type = method.idl_type

#    idl_type.add_includes_for_type()
    this_cpp_value = cpp_value(interface, method, len(arguments))

    if context['is_call_with_script_state']:
        includes.add('bindings/core/dart/DartScriptState.h')

    if idl_type.union_arguments and len(idl_type.union_arguments) > 0:
        this_cpp_type = []
        for cpp_type in idl_type.member_types:
            this_cpp_type.append("RefPtr<%s>" % cpp_type)
    else:
        this_cpp_type = idl_type.cpp_type

    is_auto_scope = not 'DartNoAutoScope' in extended_attributes

    arguments_data = [argument_context(interface, method, argument, index)
                      for index, argument in enumerate(arguments)]

    union_arguments = []
    if idl_type.union_arguments:
        union_arguments.extend([union_arg['cpp_value']
                                for union_arg in idl_type.union_arguments])

    is_custom = 'Custom' in extended_attributes or 'DartCustom' in extended_attributes

    context.update({
        'arguments': arguments_data,
        'cpp_type': this_cpp_type,
        'cpp_value': this_cpp_value,
        'dart_type': dart_types.idl_type_to_dart_type(idl_type),
        'dart_name': extended_attributes.get('DartName'),
        'has_exception_state':
            context['is_raises_exception'] or
            any(argument for argument in arguments
                if argument.idl_type.name == 'SerializedScriptValue' or
                   argument.idl_type.is_integer_type),
        'is_auto_scope': is_auto_scope,
        'auto_scope': DartUtilities.bool_to_cpp(is_auto_scope),
        'is_custom': is_custom,
        'is_custom_dart': 'DartCustom' in extended_attributes,
        'is_custom_dart_new': DartUtilities.has_extended_attribute_value(method, 'DartCustom', 'New'),
        # FIXME(terry): DartStrictTypeChecking no longer supported; TypeChecking is
        #               new extended attribute.
        'is_strict_type_checking':
            'DartStrictTypeChecking' in extended_attributes or
            'DartStrictTypeChecking' in interface.extended_attributes,
        'union_arguments': union_arguments,
        'dart_set_return_value': dart_set_return_value(interface.name, method, this_cpp_value),
    })
    return context
Exemple #5
0
def cpp_value(interface, method, number_of_arguments):
    def cpp_argument(argument):
        argument_name = dart_types.check_reserved_name(argument.name)
        idl_type = argument.idl_type

        if idl_type.is_typed_array_type:
            return '%s.get()' % argument_name

        # TODO(eseidel): This should check cpp_type.endswith('Handle')
        if idl_type.name == 'MojoDataPipeConsumer':
            return '%s.Pass()' % argument_name

        if idl_type.name == 'EventListener':
            if (interface.name == 'EventTarget'
                    and method.name == 'removeEventListener'):
                # FIXME: remove this special case by moving get() into
                # EventTarget::removeEventListener
                return '%s.get()' % argument_name
            return argument.name
        if idl_type.is_callback_interface:
            return '%s.release()' % argument_name
        return argument_name

    # Truncate omitted optional arguments
    arguments = method.arguments[:number_of_arguments]
    if method.is_constructor:
        call_with_values = interface.extended_attributes.get(
            'ConstructorCallWith')
    else:
        call_with_values = method.extended_attributes.get('CallWith')
    cpp_arguments = DartUtilities.call_with_arguments(call_with_values)
    if ('PartialInterfaceImplementedAs' in method.extended_attributes
            and not method.is_static):
        cpp_arguments.append('*receiver')

    cpp_arguments.extend(cpp_argument(argument) for argument in arguments)
    this_union_arguments = method.idl_type and method.idl_type.union_arguments
    if this_union_arguments:
        cpp_arguments.extend([
            member_argument['cpp_value']
            for member_argument in this_union_arguments
        ])

    if ('RaisesException' in method.extended_attributes or
        (method.is_constructor and DartUtilities.has_extended_attribute_value(
            interface, 'RaisesException', 'Constructor'))):
        cpp_arguments.append('es')

    if method.name == 'Constructor':
        base_name = 'create'
    elif method.name == 'NamedConstructor':
        base_name = 'createForJSConstructor'
    else:
        base_name = DartUtilities.cpp_name(method)
    cpp_method_name = DartUtilities.scoped_name(interface, method, base_name)
    return '%s(%s)' % (cpp_method_name, ', '.join(cpp_arguments))
Exemple #6
0
def cpp_value(interface, method, number_of_arguments):
    def cpp_argument(argument):
        argument_name = dart_types.check_reserved_name(argument.name)
        idl_type = argument.idl_type

        if idl_type.is_typed_array_type:
            return '%s.get()' % argument_name

        # TODO(eseidel): This should check cpp_type.endswith('Handle')
        if idl_type.name == 'MojoDataPipeConsumer':
            return '%s.Pass()' % argument_name

        if idl_type.name == 'EventListener':
            if (interface.name == 'EventTarget' and
                method.name == 'removeEventListener'):
                # FIXME: remove this special case by moving get() into
                # EventTarget::removeEventListener
                return '%s.get()' % argument_name
            return argument.name
        if idl_type.is_callback_interface:
            return '%s.release()' % argument_name
        return argument_name

    # Truncate omitted optional arguments
    arguments = method.arguments[:number_of_arguments]
    if method.is_constructor:
        call_with_values = interface.extended_attributes.get('ConstructorCallWith')
    else:
        call_with_values = method.extended_attributes.get('CallWith')
    cpp_arguments = DartUtilities.call_with_arguments(call_with_values)
    if ('PartialInterfaceImplementedAs' in method.extended_attributes and not method.is_static):
        cpp_arguments.append('*receiver')

    cpp_arguments.extend(cpp_argument(argument) for argument in arguments)
    this_union_arguments = method.idl_type and method.idl_type.union_arguments
    if this_union_arguments:
        cpp_arguments.extend([member_argument['cpp_value']
                              for member_argument in this_union_arguments])

    if ('RaisesException' in method.extended_attributes or
        (method.is_constructor and
         DartUtilities.has_extended_attribute_value(interface, 'RaisesException', 'Constructor'))):
        cpp_arguments.append('es')

    if method.name == 'Constructor':
        base_name = 'create'
    elif method.name == 'NamedConstructor':
        base_name = 'createForJSConstructor'
    else:
        base_name = DartUtilities.cpp_name(method)
    cpp_method_name = DartUtilities.scoped_name(interface, method, base_name)
    return '%s(%s)' % (cpp_method_name, ', '.join(cpp_arguments))
def property_getter(getter, cpp_arguments):
    def is_null_expression(idl_type):
        if idl_type.is_union_type:
            return ' && '.join('!result%sEnabled' % i
                               for i, _ in enumerate(idl_type.member_types))
        if idl_type.name == 'String':
            # FIXME(vsm): This looks V8 specific.
            return 'result.isNull()'
        if idl_type.is_interface_type:
            return '!result'
        return ''

    context = v8_interface.property_getter(getter, [])

    idl_type = getter.idl_type
    extended_attributes = getter.extended_attributes
    is_raises_exception = 'RaisesException' in extended_attributes

    # FIXME: make more generic, so can use dart_methods.cpp_value
    cpp_method_name = 'receiver->%s' % DartUtilities.cpp_name(getter)

    if is_raises_exception:
        cpp_arguments.append('es')
    union_arguments = idl_type.union_arguments
    if union_arguments:
        cpp_arguments.extend([
            member_argument['cpp_value'] for member_argument in union_arguments
        ])

    cpp_value = '%s(%s)' % (cpp_method_name, ', '.join(cpp_arguments))

    context.update({
        'cpp_type':
        idl_type.cpp_type,
        'cpp_value':
        cpp_value,
        'is_null_expression':
        is_null_expression(idl_type),
        'is_raises_exception':
        is_raises_exception,
        'name':
        DartUtilities.cpp_name(getter),
        'union_arguments':
        union_arguments,
        'dart_set_return_value':
        idl_type.dart_set_return_value('result',
                                       extended_attributes=extended_attributes,
                                       script_wrappable='receiver',
                                       release=idl_type.release)
    })
    return context
 def add(prop, name, arity):
     if context[prop]:
         if "native_entries" not in context[prop]:
             context[prop].update({"native_entries": []})
         context[prop]["native_entries"].append(
             DartUtilities.generate_native_entry(interface.name, name, "Method", False, arity)
         )
def generate_method_native_entry(interface, method, count, kind):
    name = method.get('name')
    is_static = bool(method.get('is_static'))
    native_entry = \
        DartUtilities.generate_native_entry(interface.name, name,
                                            kind, is_static, count)
    return native_entry
Exemple #10
0
def generate_method_native_entry(interface, method, count, kind):
    name = method.get('name')
    is_static = bool(method.get('is_static'))
    native_entry = \
        DartUtilities.generate_native_entry(interface.name, name,
                                            kind, is_static, count)
    return native_entry
 def add(prop, name, arity):
     if context[prop]:
         if 'native_entries' not in context[prop]:
             context[prop].update({'native_entries': []})
         context[prop]['native_entries'].append(
             DartUtilities.generate_native_entry(interface.name, name,
                                                 'Method', False, arity))
Exemple #12
0
 def add(prop, name, arity):
     if context[prop]:
         if 'native_entries' not in context[prop]:
             context[prop].update({'native_entries': []})
         context[prop]['native_entries'].append(
             DartUtilities.generate_native_entry(
                 interface.name, name, 'Method', False, arity))
Exemple #13
0
def dart_set_return_value(idl_type,
                          cpp_value,
                          extended_attributes=None,
                          script_wrappable='',
                          release=False,
                          for_main_world=False,
                          auto_scope=True):
    """Returns a statement that converts a C++ value to a Dart value and sets it as a return value.

    """
    def dom_wrapper_conversion_type():
        if not script_wrappable:
            return 'DOMWrapperDefault'
        if for_main_world:
            return 'DOMWrapperForMainWorld'
        return 'DOMWrapperFast'

    idl_type, cpp_value = preprocess_idl_type_and_value(
        idl_type, cpp_value, extended_attributes)
    this_dart_conversion_type = idl_type.dart_conversion_type(
        extended_attributes)
    # SetReturn-specific overrides
    if this_dart_conversion_type in [
            'Date', 'EventHandler', 'ScriptPromise', 'ScriptValue',
            'SerializedScriptValue', 'array'
    ]:
        # Convert value to Dart and then use general Dart_SetReturnValue
        # FIXME(vsm): Why do we differ from V8 here? It doesn't have a
        # creation_context.
        creation_context = ''
        if this_dart_conversion_type == 'array':
            # FIXME: This is not right if the base type is a primitive, DOMString, etc.
            # What is the right check for base type?
            base_type = str(idl_type.element_type)
            if base_type not in DART_TO_CPP_VALUE:
                if base_type == 'None':
                    raise Exception('Unknown base type for ' + str(idl_type))
                creation_context = '<Dart%s>' % base_type
            if idl_type.is_nullable:
                creation_context = 'Nullable' + creation_context

        cpp_value = idl_type.cpp_value_to_dart_value(
            cpp_value,
            creation_context=creation_context,
            extended_attributes=extended_attributes)
    if this_dart_conversion_type == 'DOMWrapper':
        this_dart_conversion_type = dom_wrapper_conversion_type()

    format_string = DART_SET_RETURN_VALUE[this_dart_conversion_type]

    if release:
        cpp_value = '%s.release()' % cpp_value
    statement = format_string.format(
        cpp_value=cpp_value,
        implemented_as=idl_type.implemented_as,
        type_name=idl_type.name,
        script_wrappable=script_wrappable,
        auto_scope=DartUtilities.bool_to_cpp(auto_scope))
    return statement
Exemple #14
0
def dart_value_to_cpp_value(idl_type,
                            extended_attributes,
                            variable_name,
                            null_check,
                            has_type_checking_interface,
                            index,
                            auto_scope=True):
    # Composite types
    native_array_element_type = idl_type.native_array_element_type
    if native_array_element_type:
        return dart_value_to_cpp_value_array_or_sequence(
            native_array_element_type, variable_name, index)

    # Simple types
    idl_type = idl_type.preprocessed_type
    add_includes_for_type(idl_type)
    base_idl_type = idl_type.base_type

    if 'EnforceRange' in extended_attributes:
        arguments = ', '.join(
            [variable_name, 'EnforceRange', 'exceptionState'])
    elif idl_type.is_integer_type:  # NormalConversion
        arguments = ', '.join([variable_name, 'es'])
    else:
        arguments = variable_name

    if base_idl_type in DART_TO_CPP_VALUE:
        cpp_expression_format = DART_TO_CPP_VALUE[base_idl_type]
    elif idl_type.is_typed_array_type:
        # FIXME(vsm): V8 generates a type check here as well. Do we need one?
        # FIXME(vsm): When do we call the externalized version? E.g., see
        # bindings/dart/custom/DartWaveShaperNodeCustom.cpp - it calls
        # DartUtilities::dartToExternalizedArrayBufferView instead.
        # V8 always converts null here
        cpp_expression_format = (
            'DartUtilities::dartTo{idl_type}WithNullCheck(args, {index}, exception)'
        )
    elif idl_type.is_callback_interface:
        cpp_expression_format = (
            'Dart{idl_type}::create{null_check}(args, {index}, exception)')
    else:
        cpp_expression_format = (
            'Dart{idl_type}::toNative{null_check}(args, {index}, exception)')

    # We allow the calling context to force a null check to handle
    # some cases that require calling context info.  V8 handles all
    # of this differently, and we may wish to reconsider this approach
    check_string = ''
    if null_check or allow_null(idl_type, extended_attributes,
                                has_type_checking_interface):
        check_string = 'WithNullCheck'
    elif allow_empty(idl_type, extended_attributes):
        check_string = 'WithEmptyCheck'
    return cpp_expression_format.format(
        null_check=check_string,
        arguments=arguments,
        index=index,
        idl_type=base_idl_type,
        auto_scope=DartUtilities.bool_to_cpp(auto_scope))
Exemple #15
0
def getter_expression(interface, attribute, context):
    v8_attributes.getter_expression(interface, attribute, context)

    arguments = []
    this_getter_base_name = v8_attributes.getter_base_name(interface, attribute, arguments)
    getter_name = DartUtilities.scoped_name(interface, attribute, this_getter_base_name)

    arguments.extend(DartUtilities.call_with_arguments(
        attribute.extended_attributes.get('CallWith')))
    if ('PartialInterfaceImplementedAs' in attribute.extended_attributes and
        not attribute.is_static):
        # Pass by reference.
        arguments.append('*receiver')

    if attribute.idl_type.is_explicit_nullable:
        arguments.append('is_null')
    if context['is_getter_raises_exception']:
        arguments.append('es')
    return '%s(%s)' % (getter_name, ', '.join(arguments))
def getter_expression(interface, attribute, context):
    v8_attributes.getter_expression(interface, attribute, context)

    arguments = []
    this_getter_base_name = v8_attributes.getter_base_name(interface, attribute, arguments)
    getter_name = DartUtilities.scoped_name(interface, attribute, this_getter_base_name)

    arguments.extend(DartUtilities.call_with_arguments(
        attribute.extended_attributes.get('CallWith')))
    if ('PartialInterfaceImplementedAs' in attribute.extended_attributes and
        not attribute.is_static):
        # Pass by reference.
        arguments.append('*receiver')

    if attribute.idl_type.is_explicit_nullable:
        arguments.append('is_null')
    if context['is_getter_raises_exception']:
        arguments.append('es')
    return '%s(%s)' % (getter_name, ', '.join(arguments))
def setter_expression(interface, attribute, context):
    extended_attributes = attribute.extended_attributes
    arguments = DartUtilities.call_with_arguments(
        extended_attributes.get('SetterCallWith') or
        extended_attributes.get('CallWith'))

    this_setter_base_name = v8_attributes.setter_base_name(interface, attribute, arguments)
    setter_name = DartUtilities.scoped_name(interface, attribute, this_setter_base_name)

    if ('PartialInterfaceImplementedAs' in extended_attributes and
        not attribute.is_static):
        arguments.append('*receiver')
    idl_type = attribute.idl_type
    attribute_name = dart_types.check_reserved_name(attribute.name)
    arguments.append(attribute_name)
    if context['is_setter_raises_exception']:
        arguments.append('es')

    return '%s(%s)' % (setter_name, ', '.join(arguments))
Exemple #18
0
def generate_callback_interface(callback_interface):
    includes.clear()
    includes.update(CALLBACK_INTERFACE_CPP_INCLUDES)
    name = callback_interface.name

    methods = [
        generate_method(operation)
        for operation in callback_interface.operations
    ]
    template_contents = {
        'conditional_string':
        DartUtilities.conditional_string(callback_interface),
        'cpp_class': name,
        'dart_class': dart_types.dart_type(callback_interface.name),
        'v8_class': DartUtilities.v8_class_name(callback_interface),
        'header_includes': set(CALLBACK_INTERFACE_H_INCLUDES),
        'methods': methods,
    }
    return template_contents
Exemple #19
0
def property_setter(setter, cpp_arguments):
    context = v8_interface.property_setter(setter)

    idl_type = setter.idl_type
    extended_attributes = setter.extended_attributes
    is_raises_exception = 'RaisesException' in extended_attributes

    cpp_method_name = 'receiver->%s' % DartUtilities.cpp_name(setter)

    if is_raises_exception:
        cpp_arguments.append('es')

    cpp_value = '%s(%s)' % (cpp_method_name, ', '.join(cpp_arguments))
    context.update({
        'cpp_type': idl_type.cpp_type,
        'cpp_value': cpp_value,
        'is_raises_exception': is_raises_exception,
        'name': DartUtilities.cpp_name(setter)})
    return context
def property_getter(getter, cpp_arguments):
    def is_null_expression(idl_type):
        if idl_type.is_union_type:
            return " && ".join("!result%sEnabled" % i for i, _ in enumerate(idl_type.member_types))
        if idl_type.name == "String":
            # FIXME(vsm): This looks V8 specific.
            return "result.isNull()"
        if idl_type.is_interface_type:
            return "!result"
        return ""

    context = v8_interface.property_getter(getter, [])

    idl_type = getter.idl_type
    extended_attributes = getter.extended_attributes
    is_raises_exception = "RaisesException" in extended_attributes

    # FIXME: make more generic, so can use dart_methods.cpp_value
    cpp_method_name = "receiver->%s" % DartUtilities.cpp_name(getter)

    if is_raises_exception:
        cpp_arguments.append("es")
    union_arguments = idl_type.union_arguments
    if union_arguments:
        cpp_arguments.extend([member_argument["cpp_value"] for member_argument in union_arguments])

    cpp_value = "%s(%s)" % (cpp_method_name, ", ".join(cpp_arguments))

    context.update(
        {
            "cpp_type": idl_type.cpp_type,
            "cpp_value": cpp_value,
            "is_null_expression": is_null_expression(idl_type),
            "is_raises_exception": is_raises_exception,
            "name": DartUtilities.cpp_name(getter),
            "union_arguments": union_arguments,
            "dart_set_return_value": idl_type.dart_set_return_value(
                "result", extended_attributes=extended_attributes, script_wrappable="receiver", release=idl_type.release
            ),
        }
    )
    return context
Exemple #21
0
def property_getter(getter, cpp_arguments):
    def is_null_expression(idl_type):
        if idl_type.is_union_type:
            return ' && '.join('!result%sEnabled' % i
                               for i, _ in enumerate(idl_type.member_types))
        if idl_type.name == 'String':
            # FIXME(vsm): This looks V8 specific.
            return 'result.isNull()'
        if idl_type.is_interface_type:
            return '!result'
        return ''

    context = v8_interface.property_getter(getter, [])

    idl_type = getter.idl_type
    extended_attributes = getter.extended_attributes
    is_raises_exception = 'RaisesException' in extended_attributes

    # FIXME: make more generic, so can use dart_methods.cpp_value
    cpp_method_name = 'receiver->%s' % DartUtilities.cpp_name(getter)

    if is_raises_exception:
        cpp_arguments.append('es')
    union_arguments = idl_type.union_arguments
    if union_arguments:
        cpp_arguments.extend([member_argument['cpp_value']
                              for member_argument in union_arguments])

    cpp_value = '%s(%s)' % (cpp_method_name, ', '.join(cpp_arguments))

    context.update({
        'cpp_type': idl_type.cpp_type,
        'cpp_value': cpp_value,
        'is_null_expression': is_null_expression(idl_type),
        'is_raises_exception': is_raises_exception,
        'name': DartUtilities.cpp_name(getter),
        'union_arguments': union_arguments,
        'dart_set_return_value': idl_type.dart_set_return_value('result',
                                                                extended_attributes=extended_attributes,
                                                                script_wrappable='receiver',
                                                                release=idl_type.release)})
    return context
def property_setter(setter, cpp_arguments):
    context = v8_interface.property_setter(setter)

    idl_type = setter.idl_type
    extended_attributes = setter.extended_attributes
    is_raises_exception = 'RaisesException' in extended_attributes

    cpp_method_name = 'receiver->%s' % DartUtilities.cpp_name(setter)

    if is_raises_exception:
        cpp_arguments.append('es')

    cpp_value = '%s(%s)' % (cpp_method_name, ', '.join(cpp_arguments))
    context.update({
        'cpp_type': idl_type.cpp_type,
        'cpp_value': cpp_value,
        'is_raises_exception': is_raises_exception,
        'name': DartUtilities.cpp_name(setter)
    })
    return context
Exemple #23
0
def setter_context(interface, attribute, context):
    v8_attributes.setter_context(interface, attribute, context)

    def target_attribute():
        target_interface_name = attribute.idl_type.base_type
        target_attribute_name = extended_attributes['PutForwards']
        target_interface = interfaces[target_interface_name]
        try:
            return next(attribute for attribute in target_interface.attributes
                        if attribute.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))

    extended_attributes = attribute.extended_attributes

    if 'PutForwards' in extended_attributes:
        # Use target attribute in place of original attribute
        attribute = target_attribute()
        this_cpp_type = 'DartStringAdapter'
    else:
        this_cpp_type = context['cpp_type']

    idl_type = attribute.idl_type

    # TODO(terry): Should be able to eliminate suppress_setter as we move from
    #              IGNORE_MEMBERS to DartSuppress in the IDL.
    suppress = (suppress_setter(interface.name, attribute.name)
                or DartUtilities.has_extended_attribute_value(
                    attribute, 'DartSuppress', 'Setter'))
    context.update({
        'has_setter_exception_state':
        (context['is_setter_raises_exception']
         or context['has_type_checking_interface']
         or idl_type.is_integer_type),
        'is_setter_suppressed':
        suppress,
        'setter_lvalue':
        dart_types.check_reserved_name(attribute.name),
        'cpp_type':
        this_cpp_type,
        'local_cpp_type':
        idl_type.cpp_type_args(attribute.extended_attributes, raw_type=True),
        'dart_value_to_local_cpp_value':
        attribute.idl_type.dart_value_to_local_cpp_value(
            extended_attributes, attribute.name, False,
            context['has_type_checking_interface'], 1,
            context['is_auto_scope']),
    })

    # setter_expression() depends on context values we set above.
    context['cpp_setter'] = setter_expression(interface, attribute, context)
Exemple #24
0
def setter_expression(interface, attribute, context):
    extended_attributes = attribute.extended_attributes
    arguments = DartUtilities.call_with_arguments(
        extended_attributes.get('SetterCallWith')
        or extended_attributes.get('CallWith'))

    this_setter_base_name = v8_attributes.setter_base_name(
        interface, attribute, arguments)
    setter_name = DartUtilities.scoped_name(interface, attribute,
                                            this_setter_base_name)

    if ('PartialInterfaceImplementedAs' in extended_attributes
            and not attribute.is_static):
        arguments.append('*receiver')
    idl_type = attribute.idl_type
    attribute_name = dart_types.check_reserved_name(attribute.name)
    arguments.append(attribute_name)
    if context['is_setter_raises_exception']:
        arguments.append('es')

    return '%s(%s)' % (setter_name, ', '.join(arguments))
Exemple #25
0
def dart_value_to_cpp_value(idl_type, extended_attributes, variable_name,
                            null_check, has_type_checking_interface,
                            index, auto_scope=True):
    # Composite types
    native_array_element_type = idl_type.native_array_element_type
    if native_array_element_type:
        return dart_value_to_cpp_value_array_or_sequence(native_array_element_type, variable_name, index)

    # Simple types
    idl_type = idl_type.preprocessed_type
    add_includes_for_type(idl_type)
    base_idl_type = idl_type.base_type
    implemented_as = idl_type.implemented_as

    if 'EnforceRange' in extended_attributes:
        arguments = ', '.join([variable_name, 'EnforceRange', 'exceptionState'])
    elif idl_type.is_integer_type:  # NormalConversion
        arguments = ', '.join([variable_name, 'es'])
    else:
        arguments = variable_name

    if base_idl_type in CPP_SPECIAL_CONVERSION_RULES:
        implemented_as = CPP_SPECIAL_CONVERSION_RULES[base_idl_type]

    if base_idl_type in DART_TO_CPP_VALUE:
        cpp_expression_format = DART_TO_CPP_VALUE[base_idl_type]
    elif idl_type.is_typed_array_type:
        # FIXME(vsm): V8 generates a type check here as well. Do we need one?
        # FIXME(vsm): When do we call the externalized version? E.g., see
        # bindings/dart/custom/DartWaveShaperNodeCustom.cpp - it calls
        # DartUtilities::dartToExternalizedArrayBufferView instead.
        # V8 always converts null here
        cpp_expression_format = ('DartUtilities::dartTo{idl_type}WithNullCheck(args, {index}, exception)')
    elif idl_type.is_callback_interface:
        cpp_expression_format = ('Dart{idl_type}::create{null_check}(args, {index}, exception)')
    else:
        cpp_expression_format = ('DartConverter<{implemented_as}*>::FromArguments{null_check}(args, {index}, exception)')

    # We allow the calling context to force a null check to handle
    # some cases that require calling context info.  V8 handles all
    # of this differently, and we may wish to reconsider this approach
    check_string = ''
    if null_check or allow_null(idl_type, extended_attributes,
                                has_type_checking_interface):
        check_string = 'WithNullCheck'
    elif allow_empty(idl_type, extended_attributes):
        check_string = 'WithEmptyCheck'
    return cpp_expression_format.format(null_check=check_string,
                                        arguments=arguments,
                                        index=index,
                                        idl_type=base_idl_type,
                                        implemented_as=implemented_as,
                                        auto_scope=DartUtilities.bool_to_cpp(auto_scope))
Exemple #26
0
def setter_callback_name(interface, attribute):
    cpp_class_name = DartUtilities.cpp_name(interface)
    extended_attributes = attribute.extended_attributes
    if (('Replaceable' in extended_attributes and
         'PutForwards' not in extended_attributes) or
        v8_attributes.is_constructor_attribute(attribute)):
        # FIXME: rename to ForceSetAttributeOnThisCallback, since also used for Constructors
        return '{0}V8Internal::{0}ReplaceableAttributeSetterCallback'.format(cpp_class_name)
    # FIXME:disabling PutForwards for now since we didn't support it before
    #    if attribute.is_read_only and 'PutForwards' not in extended_attributes:
    if attribute.is_read_only:
        return '0'
    return '%sV8Internal::%sAttributeSetterCallback' % (cpp_class_name, attribute.name)
def setter_callback_name(interface, attribute):
    cpp_class_name = DartUtilities.cpp_name(interface)
    extended_attributes = attribute.extended_attributes
    if (('Replaceable' in extended_attributes and
         'PutForwards' not in extended_attributes) or
        v8_attributes.is_constructor_attribute(attribute)):
        # FIXME: rename to ForceSetAttributeOnThisCallback, since also used for Constructors
        return '{0}V8Internal::{0}ReplaceableAttributeSetterCallback'.format(cpp_class_name)
    # FIXME:disabling PutForwards for now since we didn't support it before
    #    if attribute.is_read_only and 'PutForwards' not in extended_attributes:
    if attribute.is_read_only:
        return '0'
    return '%sV8Internal::%sAttributeSetterCallback' % (cpp_class_name, attribute.name)
def property_setter(setter, cpp_arguments):
    context = v8_interface.property_setter(setter)

    idl_type = setter.idl_type
    extended_attributes = setter.extended_attributes
    is_raises_exception = "RaisesException" in extended_attributes

    cpp_method_name = "receiver->%s" % DartUtilities.cpp_name(setter)

    if is_raises_exception:
        cpp_arguments.append("es")

    cpp_value = "%s(%s)" % (cpp_method_name, ", ".join(cpp_arguments))
    context.update(
        {
            "cpp_type": idl_type.cpp_type,
            "cpp_value": cpp_value,
            "is_raises_exception": is_raises_exception,
            "name": DartUtilities.cpp_name(setter),
        }
    )
    return context
Exemple #29
0
def setter_expression(interface, attribute, context):
    extended_attributes = attribute.extended_attributes
    arguments = DartUtilities.call_with_arguments(
        extended_attributes.get('SetterCallWith')
        or extended_attributes.get('CallWith'))

    this_setter_base_name = v8_attributes.setter_base_name(
        interface, attribute, arguments)
    setter_name = DartUtilities.scoped_name(interface, attribute,
                                            this_setter_base_name)

    if ('PartialInterfaceImplementedAs' in extended_attributes
            and not attribute.is_static):
        arguments.append('*receiver')
    idl_type = attribute.idl_type
    if idl_type.base_type == 'EventHandler':
        getter_name = DartUtilities.scoped_name(
            interface, attribute, DartUtilities.cpp_name(attribute))
        context['event_handler_getter_expression'] = '%s(%s)' % (
            getter_name, ', '.join(arguments))
        # FIXME(vsm): Do we need to support this? If so, what's our analogue of
        # V8EventListenerList?
        arguments.append('nullptr')
        # if (interface.name in ['Window', 'WorkerGlobalScope'] and
        #    attribute.name == 'onerror'):
        #    includes.add('bindings/core/v8/V8ErrorHandler.h')
        #    arguments.append('V8EventListenerList::findOrCreateWrapper<V8ErrorHandler>(jsValue, true, info.GetIsolate())')
        # else:
        #    arguments.append('V8EventListenerList::getEventListener(jsValue, true, ListenerFindOrCreate)')
    else:
        attribute_name = dart_types.check_reserved_name(attribute.name)
        arguments.append(attribute_name)
    if context['is_setter_raises_exception']:
        arguments.append('es')

    return '%s(%s)' % (setter_name, ', '.join(arguments))
Exemple #30
0
def dart_set_return_value(idl_type, cpp_value,
                          extended_attributes=None, script_wrappable='',
                          release=False, for_main_world=False,
                          auto_scope=True):
    """Returns a statement that converts a C++ value to a Dart value and sets it as a return value.

    """
    def dom_wrapper_conversion_type():
        if not script_wrappable:
            return 'DOMWrapperDefault'
        if for_main_world:
            return 'DOMWrapperForMainWorld'
        return 'DOMWrapperFast'

    idl_type, cpp_value = preprocess_idl_type_and_value(idl_type, cpp_value, extended_attributes)
    this_dart_conversion_type = idl_type.dart_conversion_type(extended_attributes)
    # SetReturn-specific overrides
    if this_dart_conversion_type in ['Date', 'EventHandler', 'ScriptPromise', 'SerializedScriptValue', 'array']:
        # Convert value to Dart and then use general Dart_SetReturnValue
        # FIXME(vsm): Why do we differ from V8 here? It doesn't have a
        # creation_context.
        creation_context = ''
        if this_dart_conversion_type == 'array':
            # FIXME: This is not right if the base type is a primitive, DOMString, etc.
            # What is the right check for base type?
            base_type = str(idl_type.element_type)
            if base_type not in DART_TO_CPP_VALUE:
                if base_type == 'None':
                    raise Exception('Unknown base type for ' + str(idl_type))
                creation_context = '<Dart%s>' % base_type
            if idl_type.is_nullable:
                creation_context = 'Nullable' + creation_context

        cpp_value = idl_type.cpp_value_to_dart_value(cpp_value, creation_context=creation_context,
                                                     extended_attributes=extended_attributes)
    if this_dart_conversion_type == 'DOMWrapper':
        this_dart_conversion_type = dom_wrapper_conversion_type()

    format_string = DART_SET_RETURN_VALUE[this_dart_conversion_type]

    if release:
        cpp_value = '%s.release()' % cpp_value
    statement = format_string.format(cpp_value=cpp_value,
                                     implemented_as=idl_type.implemented_as,
                                     type_name=idl_type.name,
                                     script_wrappable=script_wrappable,
                                     auto_scope=DartUtilities.bool_to_cpp(auto_scope))
    return statement
Exemple #31
0
def getter_context(interface, attribute, context):
    v8_attributes.getter_context(interface, attribute, context)

    idl_type = attribute.idl_type
    base_idl_type = idl_type.base_type
    extended_attributes = attribute.extended_attributes

    cpp_value = getter_expression(interface, attribute, context)
    # Normally we can inline the function call into the return statement to
    # avoid the overhead of using a Ref<> temporary, but for some cases
    # (nullable types, EventHandler, [CachedAttribute], or if there are
    # exceptions), we need to use a local variable.
    # FIXME: check if compilers are smart enough to inline this, and if so,
    # always use a local variable (for readability and CG simplicity).
    release = False
    if (idl_type.is_nullable or base_idl_type == 'EventHandler'
            or 'CachedAttribute' in extended_attributes
            or 'ReflectOnly' in extended_attributes
            or context['is_getter_raises_exception']):
        context['cpp_value_original'] = cpp_value
        cpp_value = 'result'
        # EventHandler has special handling
        if base_idl_type != 'EventHandler' and idl_type.is_interface_type:
            release = True

    dart_set_return_value = \
        idl_type.dart_set_return_value(cpp_value,
                                       extended_attributes=extended_attributes,
                                       script_wrappable='impl',
                                       release=release,
                                       for_main_world=False,
                                       auto_scope=context['is_auto_scope'])

    # TODO(terry): Should be able to eliminate suppress_getter as we move from
    #              IGNORE_MEMBERS to DartSuppress in the IDL.
    suppress = (suppress_getter(interface.name, attribute.name)
                or DartUtilities.has_extended_attribute_value(
                    attribute, 'DartSuppress', 'Getter'))

    context.update({
        'cpp_value': cpp_value,
        'dart_set_return_value': dart_set_return_value,
        'is_getter_suppressed': suppress,
    })
def generate_method(operation):
    extended_attributes = operation.extended_attributes
    idl_type = operation.idl_type
    idl_type_str = str(idl_type)
    if idl_type_str not in ['boolean', 'void']:
        raise Exception('We only support callbacks that return boolean or void values.')
    is_custom = 'Custom' in extended_attributes
    if not is_custom:
        add_includes_for_operation(operation)
    call_with = extended_attributes.get('CallWith')
    call_with_this_handle = DartUtilities.extended_attribute_value_contains(call_with, 'ThisValue')
    contents = {
        'call_with_this_handle': call_with_this_handle,
        'cpp_type': idl_type.callback_cpp_type,
        'custom': is_custom,
        'idl_type': idl_type_str,
        'name': operation.name,
    }
    contents.update(generate_arguments_contents(operation.arguments, call_with_this_handle))
    return contents
Exemple #33
0
def generate_method(operation):
    extended_attributes = operation.extended_attributes
    idl_type = operation.idl_type
    idl_type_str = str(idl_type)
    if idl_type_str not in ['boolean', 'void']:
        raise Exception(
            'We only support callbacks that return boolean or void values.')
    is_custom = 'Custom' in extended_attributes
    if not is_custom:
        add_includes_for_operation(operation)
    call_with = extended_attributes.get('CallWith')
    call_with_this_handle = DartUtilities.extended_attribute_value_contains(
        call_with, 'ThisValue')
    contents = {
        'call_with_this_handle': call_with_this_handle,
        'cpp_type': idl_type.callback_cpp_type,
        'custom': is_custom,
        'idl_type': idl_type_str,
        'name': operation.name,
    }
    contents.update(
        generate_arguments_contents(operation.arguments,
                                    call_with_this_handle))
    return contents
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
Exemple #35
0
def method_context(interface, method):
    context = v8_methods.method_context(interface, method)

    arguments = method.arguments
    extended_attributes = method.extended_attributes
    idl_type = method.idl_type

    #    idl_type.add_includes_for_type()
    this_cpp_value = cpp_value(interface, method, len(arguments))

    if context['is_call_with_script_state']:
        includes.add('bindings/core/dart/DartScriptState.h')

    if idl_type.union_arguments and len(idl_type.union_arguments) > 0:
        this_cpp_type = []
        for cpp_type in idl_type.member_types:
            # FIXMEDART: we shouldn't just assume RefPtr. We should append
            # WillBeGC as appropriate.
            this_cpp_type.append("RefPtr<%s>" % cpp_type)
    else:
        this_cpp_type = idl_type.cpp_type

    is_auto_scope = not 'DartNoAutoScope' in extended_attributes

    arguments_data = [
        argument_context(interface, method, argument, index)
        for index, argument in enumerate(arguments)
    ]

    union_arguments = []
    if idl_type.union_arguments:
        union_arguments.extend(
            [union_arg['cpp_value'] for union_arg in idl_type.union_arguments])

    is_custom = 'Custom' in extended_attributes or 'DartCustom' in extended_attributes

    context.update({
        'activity_logging_world_list':
        DartUtilities.activity_logging_world_list(method),  # [ActivityLogging]
        'arguments':
        arguments_data,
        'cpp_type':
        this_cpp_type,
        'cpp_value':
        this_cpp_value,
        'dart_name':
        extended_attributes.get('DartName'),
        'deprecate_as':
        DartUtilities.deprecate_as(method),  # [DeprecateAs]
        'do_not_check_signature':
        not (context['is_static']
             or DartUtilities.has_extended_attribute(method, [
                 'DoNotCheckSecurity', 'DoNotCheckSignature', 'NotEnumerable',
                 'ReadOnly', 'RuntimeEnabled', 'Unforgeable'
             ])),
        'has_exception_state':
        context['is_raises_exception']
        or context['is_check_security_for_frame']
        or any(argument for argument in arguments if argument.idl_type.name ==
               'SerializedScriptValue' or argument.idl_type.is_integer_type),
        'is_auto_scope':
        is_auto_scope,
        'auto_scope':
        DartUtilities.bool_to_cpp(is_auto_scope),
        'is_custom':
        is_custom,
        'is_custom_dart':
        'DartCustom' in extended_attributes,
        'is_custom_dart_new':
        DartUtilities.has_extended_attribute_value(method, 'DartCustom',
                                                   'New'),
        # FIXME(terry): DartStrictTypeChecking no longer supported; TypeChecking is
        #               new extended attribute.
        'is_strict_type_checking':
        'DartStrictTypeChecking' in extended_attributes
        or 'DartStrictTypeChecking' in interface.extended_attributes,
        'measure_as':
        DartUtilities.measure_as(method),  # [MeasureAs]
        'suppressed':
        (arguments and arguments[-1].is_variadic),  # FIXME: implement variadic
        'union_arguments':
        union_arguments,
        'dart_set_return_value':
        dart_set_return_value(interface.name, method, this_cpp_value),
    })
    return context
Exemple #36
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
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
Exemple #38
0
def interface_context(interface):
    context = v8_interface.interface_context(interface)

    includes.clear()

    includes.update(INTERFACE_CPP_INCLUDES)
    header_includes = set(INTERFACE_H_INCLUDES)

    parent_interface = interface.parent
    if parent_interface:
        header_includes.update(dart_types.includes_for_interface(parent_interface))
    extended_attributes = interface.extended_attributes

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

    # [SetWrapperReferenceTo]
    set_wrapper_reference_to_list = [{
        'name': argument.name,
        # FIXME: properly should be:
        # 'cpp_type': argument.idl_type.cpp_type_args(used_as_rvalue_type=True),
        # (if type is non-wrapper type like NodeFilter, normally RefPtr)
        # Raw pointers faster though, and NodeFilter hacky anyway.
        'cpp_type': argument.idl_type.implemented_as + '*',
        'idl_type': argument.idl_type,
    } for argument in extended_attributes.get('SetWrapperReferenceTo', [])]
    for set_wrapper_reference_to in set_wrapper_reference_to_list:
        set_wrapper_reference_to['idl_type'].add_includes_for_type()

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

    # Constructors
    constructors = [constructor_context(interface, constructor)
                    for constructor in interface.constructors
                    # FIXME: shouldn't put named constructors with constructors
                    # (currently needed for Perl compatibility)
                    # Handle named constructors separately
                    if constructor.name == 'Constructor']
    if len(constructors) > 1:
        context.update({'constructor_overloads': overloads_context(constructors)})

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

    # [NamedConstructor]
    named_constructor = generate_named_constructor(interface)

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

    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
Exemple #39
0
################################################################################
# Attribute configuration
################################################################################


# [Replaceable]
def setter_callback_name(interface, attribute):
    cpp_class_name = DartUtilities.cpp_name(interface)
    extended_attributes = attribute.extended_attributes
    if (('Replaceable' in extended_attributes
         and 'PutForwards' not in extended_attributes)
            or v8_attributes.is_constructor_attribute(attribute)):
        # FIXME: rename to ForceSetAttributeOnThisCallback, since also used for Constructors
        return '{0}V8Internal::{0}ReplaceableAttributeSetterCallback'.format(
            cpp_class_name)
    # FIXME:disabling PutForwards for now since we didn't support it before
    #    if attribute.is_read_only and 'PutForwards' not in extended_attributes:
    if attribute.is_read_only:
        return '0'
    return '%sV8Internal::%sAttributeSetterCallback' % (cpp_class_name,
                                                        attribute.name)


################################################################################
# Constructors
################################################################################

idl_types.IdlType.constructor_type_name = property(
    # FIXME: replace this with a [ConstructorAttribute] extended attribute
    lambda self: DartUtilities.strip_suffix(self.base_type, 'Constructor'))
    return '%s(%s)' % (setter_name, ', '.join(arguments))


################################################################################
# Attribute configuration
################################################################################

# [Replaceable]
def setter_callback_name(interface, attribute):
    cpp_class_name = DartUtilities.cpp_name(interface)
    extended_attributes = attribute.extended_attributes
    if (('Replaceable' in extended_attributes and
         'PutForwards' not in extended_attributes) or
        v8_attributes.is_constructor_attribute(attribute)):
        # FIXME: rename to ForceSetAttributeOnThisCallback, since also used for Constructors
        return '{0}V8Internal::{0}ReplaceableAttributeSetterCallback'.format(cpp_class_name)
    # FIXME:disabling PutForwards for now since we didn't support it before
    #    if attribute.is_read_only and 'PutForwards' not in extended_attributes:
    if attribute.is_read_only:
        return '0'
    return '%sV8Internal::%sAttributeSetterCallback' % (cpp_class_name, attribute.name)


################################################################################
# Constructors
################################################################################

idl_types.IdlType.constructor_type_name = property(
    # FIXME: replace this with a [ConstructorAttribute] extended attribute
    lambda self: DartUtilities.strip_suffix(self.base_type, 'Constructor'))
Exemple #41
0
def method_context(interface, method):
    context = v8_methods.method_context(interface, method)

    arguments = method.arguments
    extended_attributes = method.extended_attributes
    idl_type = method.idl_type

    #    idl_type.add_includes_for_type()
    this_cpp_value = cpp_value(interface, method, len(arguments))

    if context['is_call_with_script_state']:
        includes.add('bindings/core/dart/DartScriptState.h')

    if idl_type.union_arguments and len(idl_type.union_arguments) > 0:
        this_cpp_type = []
        for cpp_type in idl_type.member_types:
            this_cpp_type.append("RefPtr<%s>" % cpp_type)
    else:
        this_cpp_type = idl_type.cpp_type

    is_auto_scope = not 'DartNoAutoScope' in extended_attributes

    arguments_data = [
        argument_context(interface, method, argument, index)
        for index, argument in enumerate(arguments)
    ]

    union_arguments = []
    if idl_type.union_arguments:
        union_arguments.extend(
            [union_arg['cpp_value'] for union_arg in idl_type.union_arguments])

    is_custom = 'Custom' in extended_attributes or 'DartCustom' in extended_attributes

    context.update({
        'arguments':
        arguments_data,
        'cpp_type':
        this_cpp_type,
        'cpp_value':
        this_cpp_value,
        'dart_type':
        dart_types.idl_type_to_dart_type(idl_type),
        'dart_name':
        extended_attributes.get('DartName'),
        'has_exception_state':
        context['is_raises_exception']
        or any(argument for argument in arguments if argument.idl_type.name ==
               'SerializedScriptValue' or argument.idl_type.is_integer_type),
        'is_auto_scope':
        is_auto_scope,
        'auto_scope':
        DartUtilities.bool_to_cpp(is_auto_scope),
        'is_custom':
        is_custom,
        'is_custom_dart':
        'DartCustom' in extended_attributes,
        'is_custom_dart_new':
        DartUtilities.has_extended_attribute_value(method, 'DartCustom',
                                                   'New'),
        # FIXME(terry): DartStrictTypeChecking no longer supported; TypeChecking is
        #               new extended attribute.
        'is_strict_type_checking':
        'DartStrictTypeChecking' in extended_attributes
        or 'DartStrictTypeChecking' in interface.extended_attributes,
        'union_arguments':
        union_arguments,
        'dart_set_return_value':
        dart_set_return_value(interface.name, method, this_cpp_value),
    })
    return context