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
Beispiel #2
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_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 create_interface_context(self, interface, component, interfaces):
        '''Creates a Jinja context which is based on an interface.'''

        assert component in ['core', 'modules']

        name = '%s%s' % (v8_utilities.cpp_name(interface),
                         'Partial' if interface.is_partial else '')

        # Constructors
        has_constructor_callback = False
        if not interface.is_partial:
            constructors = any(constructor.name == 'Constructor'
                               for constructor in interface.constructors)
            custom_constructors = interface.custom_constructors
            html_constructor = 'HTMLConstructor' in interface.extended_attributes
            has_constructor_callback = constructors or custom_constructors or html_constructor

        attributes = []
        methods = []
        has_cross_origin_indexed_getter = False
        has_cross_origin_named_enum = False
        has_cross_origin_named_getter = False
        has_cross_origin_named_setter = False
        has_origin_safe_method_setter = False
        has_security_check = False
        indexed_property_getter = None
        is_global = False
        named_property_getter = None
        component_info = self._info_provider.component_info
        if interface.name in SNAPSHOTTED_INTERFACES:
            attributes = [
                v8_attributes.attribute_context(interface, attribute,
                                                interfaces, component_info)
                for attribute in interface.attributes
            ]
            methods = v8_interface.methods_context(interface,
                                                   component_info)['methods']
            is_global = 'Global' in interface.extended_attributes

            named_property_getter = v8_interface.property_getter(
                interface.named_property_getter, ['name'])
            indexed_property_getter = v8_interface.property_getter(
                interface.indexed_property_getter, ['index'])

            if not interface.is_partial:
                has_origin_safe_method_setter = is_global and any(
                    method['is_check_security_for_receiver']
                    and not method['is_unforgeable'] for method in methods)
                has_security_check = ('CheckSecurity'
                                      in interface.extended_attributes
                                      and interface.name != 'EventTarget')
                has_cross_origin_named_getter = (
                    any(method['is_cross_origin'] for method in methods)
                    or any(attribute['has_cross_origin_getter']
                           for attribute in attributes))
                has_cross_origin_named_setter = any(
                    attribute['has_cross_origin_setter']
                    for attribute in attributes)
                has_cross_origin_indexed_getter = indexed_property_getter and indexed_property_getter[
                    'is_cross_origin']
                has_cross_origin_named_enum = has_cross_origin_named_getter or has_cross_origin_named_setter
                if named_property_getter and named_property_getter[
                        'is_cross_origin']:
                    has_cross_origin_named_getter = True

        return {
            'attributes':
            attributes,
            'component':
            component,
            'has_origin_safe_method_setter':
            has_origin_safe_method_setter,
            'has_constructor_callback':
            has_constructor_callback,
            'has_cross_origin_named_getter':
            has_cross_origin_named_getter,
            'has_cross_origin_named_setter':
            has_cross_origin_named_setter,
            'has_cross_origin_named_enumerator':
            has_cross_origin_named_enum,
            'has_cross_origin_indexed_getter':
            has_cross_origin_indexed_getter,
            'has_security_check':
            has_security_check,
            'indexed_property_getter':
            indexed_property_getter,
            'indexed_property_setter':
            v8_interface.property_setter(interface.indexed_property_setter,
                                         interface),
            'indexed_property_deleter':
            v8_interface.property_deleter(interface.indexed_property_deleter),
            'internal_namespace':
            v8_interface.internal_namespace(interface),
            'is_partial':
            interface.is_partial,
            'methods':
            methods,
            'name':
            name,
            'named_constructor':
            v8_interface.named_constructor_context(interface),
            'named_property_getter':
            named_property_getter,
            'named_property_setter':
            v8_interface.property_setter(interface.named_property_setter,
                                         interface),
            'named_property_deleter':
            v8_interface.property_deleter(interface.named_property_deleter),
            'v8_class':
            v8_utilities.v8_class_name_or_partial(interface),
        }
    def create_interface_context(self, interface, interfaces):
        '''Creates a Jinja context which is based on an interface.'''

        name = '%s%s' % (v8_utilities.cpp_name(interface), 'Partial' if interface.is_partial else '')

        # Constructors
        constructors = any(constructor.name == 'Constructor' for constructor in interface.constructors)
        custom_constructors = interface.custom_constructors
        html_constructor = 'HTMLConstructor' in interface.extended_attributes
        has_constructor_callback = constructors or custom_constructors or html_constructor

        attributes = []
        methods = []
        has_cross_origin_indexed_getter = False
        has_cross_origin_named_enum = False
        has_cross_origin_named_getter = False
        has_cross_origin_named_setter = False
        has_origin_safe_method_setter = False
        has_security_check = False
        indexed_property_getter = None
        is_global = False
        named_property_getter = None
        if interface.name in SNAPSHOTTED_INTERFACES:
            attributes = [v8_attributes.attribute_context(interface, attribute, interfaces)
                          for attribute in interface.attributes]
            methods = v8_interface.methods_context(interface)['methods']
            is_global = ('PrimaryGlobal' in interface.extended_attributes or
                         'Global' in interface.extended_attributes)

            named_property_getter = v8_interface.property_getter(
                interface.named_property_getter, ['name'])
            indexed_property_getter = v8_interface.property_getter(
                interface.indexed_property_getter, ['index'])

            if not interface.is_partial:
                has_origin_safe_method_setter = is_global and any(
                    method['is_check_security_for_receiver'] and not method['is_unforgeable']
                    for method in methods)
                has_security_check = ('CheckSecurity' in interface.extended_attributes and
                                      interface.name != 'EventTarget')
                has_cross_origin_named_getter = (any(method['is_cross_origin'] for method in methods) or
                                                 any(attribute['has_cross_origin_getter'] for attribute in attributes))
                has_cross_origin_named_setter = any(attribute['has_cross_origin_setter'] for attribute in attributes)
                has_cross_origin_indexed_getter = indexed_property_getter and indexed_property_getter['is_cross_origin']
                has_cross_origin_named_enum = has_cross_origin_named_getter or has_cross_origin_named_setter
                if named_property_getter and named_property_getter['is_cross_origin']:
                    has_cross_origin_named_getter = True

        return {
            'attributes': attributes,
            'has_origin_safe_method_setter': has_origin_safe_method_setter,
            'has_constructor_callback': has_constructor_callback,
            'has_cross_origin_named_getter': has_cross_origin_named_getter,
            'has_cross_origin_named_setter': has_cross_origin_named_setter,
            'has_cross_origin_named_enumerator': has_cross_origin_named_enum,
            'has_cross_origin_indexed_getter': has_cross_origin_indexed_getter,
            'has_security_check': has_security_check,
            'indexed_property_getter': indexed_property_getter,
            'indexed_property_setter': v8_interface.property_setter(interface.indexed_property_setter, interface),
            'indexed_property_deleter': v8_interface.property_deleter(interface.indexed_property_deleter),
            'is_array_buffer_or_view': interface.idl_type.is_array_buffer_or_view,
            'is_callback': interface.is_callback,
            'is_partial': interface.is_partial,
            'is_snapshotted': interface in SNAPSHOTTED_INTERFACES,
            'methods': methods,
            'name': name,
            'named_constructor': v8_interface.named_constructor_context(interface),
            'named_property_getter': named_property_getter,
            'named_property_setter': v8_interface.property_setter(interface.named_property_setter, interface),
            'named_property_deleter': v8_interface.property_deleter(interface.named_property_deleter),
            'v8_name': v8_utilities.v8_class_name_or_partial(interface),
        }