Exemplo n.º 1
0
def argument_context(interface, method, argument, index):
    context = v8_methods.argument_context(interface, method, argument, index)

    extended_attributes = argument.extended_attributes
    idl_type = argument.idl_type
    this_cpp_value = cpp_value(interface, method, index)
    auto_scope = not 'DartNoAutoScope' in extended_attributes
    arg_index = index + 1 if not method.is_static else index
    preprocessed_type = str(idl_type.preprocessed_type)
    local_cpp_type = idl_type.cpp_type_args(argument.extended_attributes,
                                            raw_type=True)
    default_value = argument.default_cpp_value
    if context['has_default']:
        default_value = (argument.default_cpp_value or
                         dart_types.default_cpp_value_for_cpp_type(idl_type))
    dart_type = dart_types.idl_type_to_dart_type(idl_type)
    dart_default_value = dart_types.dart_default_value(dart_type, argument)
    context.update({
        'cpp_type':
        idl_type.cpp_type_args(extended_attributes=extended_attributes,
                               raw_type=True,
                               used_in_cpp_sequence=False),
        'dart_type':
        dart_type,
        'implemented_as':
        idl_type.implemented_as,
        'cpp_value':
        this_cpp_value,
        'local_cpp_type':
        local_cpp_type,
        # FIXME: check that the default value's type is compatible with the argument's
        'default_value':
        default_value,
        'is_named':
        'Named' in extended_attributes,
        'dart_default_value':
        dart_default_value,
        'enum_validation_expression':
        idl_type.enum_validation_expression,
        'preprocessed_type':
        preprocessed_type,
        'is_array_or_sequence_type':
        not not idl_type.native_array_element_type,
        'is_strict_type_checking':
        'DartStrictTypeChecking' in extended_attributes,
        'dart_set_return_value_for_main_world':
        dart_set_return_value(interface.name,
                              method,
                              this_cpp_value,
                              for_main_world=True),
        'dart_set_return_value':
        dart_set_return_value(interface.name, method, this_cpp_value),
        'arg_index':
        arg_index,
        'dart_value_to_local_cpp_value':
        dart_value_to_local_cpp_value(interface,
                                      context['has_type_checking_interface'],
                                      argument, arg_index, auto_scope),
    })
    return context
Exemplo n.º 2
0
def generate_arguments_contents(arguments, call_with_this_handle):
    def generate_argument(argument):
        creation_context = ''
        if argument.idl_type.native_array_element_type is not None:
            creation_context = '<Dart%s>' % argument.idl_type.native_array_element_type
        return {
            'handle': '%sHandle' % argument.name,
            'cpp_value_to_dart_value': argument.idl_type.cpp_value_to_dart_value(argument.name,
                                                                                 creation_context=creation_context),
        }

    argument_declarations = [
            '%s %s' % (argument.idl_type.callback_cpp_type, argument.name)
            for argument in arguments]
    if call_with_this_handle:
        argument_declarations.insert(0, 'ScriptValue thisValue')

    dart_argument_declarations = [
            '%s %s' % (dart_types.idl_type_to_dart_type(argument.idl_type), argument.name)
            for argument in arguments]
    return  {
        'argument_declarations': argument_declarations,
        'dart_argument_declarations': dart_argument_declarations,
        'arguments': [generate_argument(argument) for argument in arguments],
    }
Exemplo n.º 3
0
def generate_arguments_contents(arguments, call_with_this_handle):
    def generate_argument(argument):
        creation_context = ''
        if argument.idl_type.native_array_element_type is not None:
            creation_context = '<Dart%s>' % argument.idl_type.native_array_element_type
        return {
            'handle':
            '%sHandle' % argument.name,
            'cpp_value_to_dart_value':
            argument.idl_type.cpp_value_to_dart_value(
                argument.name, creation_context=creation_context),
        }

    argument_declarations = [
        '%s %s' % (argument.idl_type.callback_cpp_type, argument.name)
        for argument in arguments
    ]
    if call_with_this_handle:
        argument_declarations.insert(0, 'ScriptValue thisValue')

    dart_argument_declarations = [
        '%s %s' %
        (dart_types.idl_type_to_dart_type(argument.idl_type), argument.name)
        for argument in arguments
    ]
    return {
        'argument_declarations': argument_declarations,
        'dart_argument_declarations': dart_argument_declarations,
        'arguments': [generate_argument(argument) for argument in arguments],
    }
Exemplo n.º 4
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
Exemplo n.º 5
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
Exemplo n.º 6
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
Exemplo n.º 7
0
def argument_context(interface, method, argument, index):
    context = v8_methods.argument_context(interface, method, argument, index)

    extended_attributes = argument.extended_attributes
    idl_type = argument.idl_type
    this_cpp_value = cpp_value(interface, method, index)
    auto_scope = not 'DartNoAutoScope' in extended_attributes
    arg_index = index + 1 if not method.is_static else index
    preprocessed_type = str(idl_type.preprocessed_type)
    local_cpp_type = idl_type.cpp_type_args(argument.extended_attributes, raw_type=True)
    default_value = argument.default_cpp_value
    if context['has_default']:
        default_value = (argument.default_cpp_value or
            dart_types.default_cpp_value_for_cpp_type(idl_type))
    dart_type = dart_types.idl_type_to_dart_type(idl_type)
    dart_default_value = dart_types.dart_default_value(dart_type, argument)
    context.update({
        'cpp_type': idl_type.cpp_type_args(extended_attributes=extended_attributes,
                                           raw_type=True,
                                           used_in_cpp_sequence=False),
        'dart_type': dart_type,
        'implemented_as': idl_type.implemented_as,
        'cpp_value': this_cpp_value,
        'local_cpp_type': local_cpp_type,
        # FIXME: check that the default value's type is compatible with the argument's
        'default_value': default_value,
        'is_named': 'Named' in extended_attributes,
        'dart_default_value': dart_default_value,
        'enum_validation_expression': idl_type.enum_validation_expression,
        'preprocessed_type': preprocessed_type,
        'is_array_or_sequence_type': not not idl_type.native_array_element_type,
        'is_strict_type_checking': 'DartStrictTypeChecking' in extended_attributes,
        'dart_set_return_value_for_main_world': dart_set_return_value(interface.name, method,
                                                                      this_cpp_value, for_main_world=True),
        'dart_set_return_value': dart_set_return_value(interface.name, method, this_cpp_value),
        'arg_index': arg_index,
        'dart_value_to_local_cpp_value': dart_value_to_local_cpp_value(interface,
                                                                       context['has_type_checking_interface'],
                                                                       argument, arg_index, auto_scope),
    })
    return context
Exemplo n.º 8
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