Beispiel #1
0
def union_arguments(idl_type):
    """Return list of ['result0Enabled', 'result0', 'result1Enabled', ...] for union types, for use in setting return value"""
    if not v8_types.is_union_type(idl_type):
        return None
    return [arg
            for i in range(len(idl_type.union_member_types))
            for arg in ['result%sEnabled' % i, 'result%s' % i]]
Beispiel #2
0
def v8_set_return_value(interface_name,
                        method,
                        cpp_value,
                        for_main_world=False):
    idl_type = method.idl_type
    extended_attributes = method.extended_attributes
    if idl_type == 'void':
        return None
    is_union_type = v8_types.is_union_type(idl_type)

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

        if is_union_type:
            release = [
                v8_types.is_interface_type(union_member_type)
                for union_member_type in idl_type.union_member_types
            ]
        else:
            release = v8_types.is_interface_type(idl_type)

    script_wrappable = 'imp' if v8_types.inherits_interface(
        interface_name, 'Node') else ''
    return v8_types.v8_set_return_value(idl_type,
                                        cpp_value,
                                        extended_attributes,
                                        script_wrappable=script_wrappable,
                                        release=release,
                                        for_main_world=for_main_world)
Beispiel #3
0
def union_arguments(idl_type):
    """Return list of ['result0Enabled', 'result0', 'result1Enabled', ...] for union types, for use in setting return value"""
    if not v8_types.is_union_type(idl_type):
        return None
    return [
        arg for i in range(len(idl_type.union_member_types))
        for arg in ['result%sEnabled' %
                    i, 'result%s' % i]
    ]
Beispiel #4
0
 def is_null_expression(idl_type):
     if v8_types.is_union_type(idl_type):
         return ' && '.join('!result%sEnabled' % i
                            for i, _ in
                            enumerate(idl_type.union_member_types))
     if idl_type == 'DOMString':
         return 'result.isNull()'
     if is_interface_type(idl_type):
         return '!result'
     return ''
Beispiel #5
0
def property_getter(getter, cpp_arguments):
    def is_null_expression(idl_type):
        if v8_types.is_union_type(idl_type):
            return ' && '.join('!result%sEnabled' % i
                               for i, _ in
                               enumerate(idl_type.union_member_types))
        if idl_type == 'DOMString':
            return 'result.isNull()'
        if is_interface_type(idl_type):
            return '!result'
        return ''

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

    if v8_types.is_union_type(idl_type):
        release = [v8_types.is_interface_type(union_member_type)
                   for union_member_type in idl_type.union_member_types]
    else:
        release = v8_types.is_interface_type(idl_type)

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

    if is_raises_exception:
        cpp_arguments.append('exceptionState')
    this_union_arguments = v8_methods.union_arguments(idl_type)
    if this_union_arguments:
        cpp_arguments.extend(this_union_arguments)

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

    return {
        'cpp_type': v8_types.cpp_type(idl_type),
        'cpp_value': cpp_value,
        'is_custom':
            'Custom' in extended_attributes and
            (not extended_attributes['Custom'] or
             has_extended_attribute_value(getter, 'Custom', 'PropertyGetter')),
        'is_custom_property_enumerator': has_extended_attribute_value(
            getter, 'Custom', 'PropertyEnumerator'),
        'is_custom_property_query': has_extended_attribute_value(
            getter, 'Custom', 'PropertyQuery'),
        'is_enumerable': 'NotEnumerable' not in extended_attributes,
        'is_null_expression': is_null_expression(idl_type),
        'is_raises_exception': is_raises_exception,
        'name': cpp_name(getter),
        'union_arguments': v8_methods.union_arguments(idl_type),
        'v8_set_return_value': v8_types.v8_set_return_value(idl_type, 'result', extended_attributes=extended_attributes, script_wrappable='imp', release=release),
    }
Beispiel #6
0
def v8_set_return_value(interface_name, method, cpp_value, for_main_world=False):
    idl_type = method.idl_type
    extended_attributes = method.extended_attributes
    if idl_type == 'void':
        return None
    is_union_type = v8_types.is_union_type(idl_type)

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

        if is_union_type:
            release = [v8_types.is_interface_type(union_member_type)
                       for union_member_type in idl_type.union_member_types]
        else:
            release = v8_types.is_interface_type(idl_type)

    script_wrappable = 'imp' if v8_types.inherits_interface(interface_name, 'Node') else ''
    return v8_types.v8_set_return_value(idl_type, cpp_value, extended_attributes, script_wrappable=script_wrappable, release=release, for_main_world=for_main_world)