Ejemplo n.º 1
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)
Ejemplo n.º 2
0
def generate_setter(interface, attribute, contents):
    idl_type = attribute.idl_type
    extended_attributes = attribute.extended_attributes
    if v8_types.is_interface_type(
            idl_type) and not v8_types.array_type(idl_type):
        cpp_value = 'WTF::getPtr(cppValue)'
    else:
        cpp_value = 'cppValue'
    is_reflect = 'Reflect' in extended_attributes
    if is_reflect:
        includes.add('core/dom/custom/CustomElementCallbackDispatcher.h')
    contents.update({
        'cpp_setter':
        setter_expression(interface, attribute, contents),
        'enum_validation_expression':
        v8_utilities.enum_validation_expression(idl_type),
        'has_strict_type_checking':
        'StrictTypeChecking' in extended_attributes
        and v8_types.is_interface_type(idl_type),
        'is_reflect':
        is_reflect,
        'v8_value_to_local_cpp_value':
        v8_types.v8_value_to_local_cpp_value(idl_type, extended_attributes,
                                             'jsValue', 'cppValue'),
    })
Ejemplo n.º 3
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),
    }
Ejemplo n.º 4
0
def setter_expression(interface, attribute, contents):
    arguments = v8_utilities.call_with_arguments(
        attribute, attribute.extended_attributes.get('SetterCallWith'))

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

    idl_type = attribute.idl_type
    if idl_type == 'EventHandler':
        # FIXME: pass the isolate instead of the isolated world
        isolated_world = 'isolatedWorldForIsolate(info.GetIsolate())'
        arguments.extend([
            'V8EventListenerList::getEventListener(jsValue, true, ListenerFindOrCreate)',
            isolated_world
        ])
        contents['event_handler_getter_expression'] = 'imp->%s(%s)' % (
            cpp_name(attribute), isolated_world)
    elif v8_types.is_interface_type(
            idl_type) and not v8_types.array_type(idl_type):
        # FIXME: should be able to eliminate WTF::getPtr in most or all cases
        arguments.append('WTF::getPtr(cppValue)')
    else:
        arguments.append('cppValue')
    if contents['is_setter_raises_exception']:
        arguments.append('exceptionState')

    return '%s(%s)' % (setter_name, ', '.join(arguments))
Ejemplo n.º 5
0
def setter_expression(interface, attribute, contents):
    extended_attributes = attribute.extended_attributes
    arguments = v8_utilities.call_with_arguments(attribute, extended_attributes.get('SetterCallWith'))

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

    if ('ImplementedBy' in extended_attributes and
        not attribute.is_static):
        arguments.append('imp')
    idl_type = attribute.idl_type
    if idl_type == 'EventHandler':
        getter_name = v8_utilities.scoped_name(interface, attribute, cpp_name(attribute))
        contents['event_handler_getter_expression'] = '%s(%s)' % (
            getter_name, ', '.join(arguments))
        if (interface.name in ['Window', 'WorkerGlobalScope'] and
            attribute.name == 'onerror'):
            includes.add('bindings/v8/V8ErrorHandler.h')
            arguments.append('V8EventListenerList::findOrCreateWrapper<V8ErrorHandler>(jsValue, true, info.GetIsolate())')
        else:
            arguments.append('V8EventListenerList::getEventListener(jsValue, true, ListenerFindOrCreate)')
    elif v8_types.is_interface_type(idl_type) and not v8_types.array_type(idl_type):
        # FIXME: should be able to eliminate WTF::getPtr in most or all cases
        arguments.append('WTF::getPtr(cppValue)')
    else:
        arguments.append('cppValue')
    if contents['is_setter_raises_exception']:
        arguments.append('exceptionState')

    return '%s(%s)' % (setter_name, ', '.join(arguments))
Ejemplo n.º 6
0
def overload_check_argument(index, argument):
    cpp_value = 'info[%s]' % index
    idl_type = argument['idl_type']
    # FIXME: proper type checking, sharing code with attributes and methods
    if idl_type == 'DOMString' and argument['is_strict_type_checking']:
        return ' || '.join(['isUndefinedOrNull(%s)' % cpp_value,
                            '%s->IsString()' % cpp_value,
                            '%s->IsObject()' % cpp_value])
    if v8_types.array_or_sequence_type(idl_type):
        return '%s->IsArray()' % cpp_value
    if v8_types.is_callback_interface(idl_type):
        return ' || '.join(['%s->IsNull()' % cpp_value,
                            '%s->IsFunction()' % cpp_value])
    if v8_types.is_wrapper_type(idl_type):
        type_check = 'V8{idl_type}::hasInstance({cpp_value}, info.GetIsolate())'.format(idl_type=idl_type, cpp_value=cpp_value)
        if argument['is_nullable']:
            type_check = ' || '.join(['%s->IsNull()' % cpp_value, type_check])
        return type_check
    if v8_types.is_interface_type(idl_type):
        # Non-wrapper types are just objects: we don't distinguish type
        type_check = '%s->IsObject()' % cpp_value
        if argument['is_nullable']:
            type_check = ' || '.join(['%s->IsNull()' % cpp_value, type_check])
        return type_check
    return None
Ejemplo n.º 7
0
def setter_expression(interface, attribute, contents):
    extended_attributes = attribute.extended_attributes
    arguments = v8_utilities.call_with_arguments(attribute, extended_attributes.get('SetterCallWith'))

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

    if ('ImplementedBy' in extended_attributes and
        not attribute.is_static):
        arguments.append('imp')
    idl_type = attribute.idl_type
    if idl_type == 'EventHandler':
        # FIXME: pass the isolate instead of the isolated world
        isolated_world = 'isolatedWorldForIsolate(info.GetIsolate())'
        getter_name = v8_utilities.scoped_name(interface, attribute, cpp_name(attribute))
        getter_arguments = arguments + [isolated_world]
        contents['event_handler_getter_expression'] = '%s(%s)' % (
            getter_name, ', '.join(getter_arguments))
        arguments.extend(['V8EventListenerList::getEventListener(jsValue, true, ListenerFindOrCreate)', isolated_world])
    elif v8_types.is_interface_type(idl_type) and not v8_types.array_type(idl_type):
        # FIXME: should be able to eliminate WTF::getPtr in most or all cases
        arguments.append('WTF::getPtr(cppValue)')
    else:
        arguments.append('cppValue')
    if contents['is_setter_raises_exception']:
        arguments.append('exceptionState')

    return '%s(%s)' % (setter_name, ', '.join(arguments))
Ejemplo n.º 8
0
 def v8_set_return_value_statement():
     if contents['is_keep_alive_for_gc']:
         return 'v8SetReturnValue(info, wrapper)'
     if attribute.is_nullable and v8_types.is_interface_type(idl_type):
         set_cpp_value = 'jsValue.release()'
     else:
         set_cpp_value = cpp_value
     return v8_types.v8_set_return_value(idl_type, set_cpp_value, extended_attributes=extended_attributes, script_wrappable='imp')
def generate_setter(interface, attribute, contents):
    idl_type = attribute.idl_type
    extended_attributes = attribute.extended_attributes
    if v8_types.is_interface_type(idl_type) and not v8_types.array_type(idl_type):
        cpp_value = 'WTF::getPtr(cppValue)'
    else:
        cpp_value = 'cppValue'
    is_reflect = 'Reflect' in extended_attributes
    if is_reflect:
        includes.add('core/dom/custom/CustomElementCallbackDispatcher.h')
    contents.update({
        'cpp_setter': setter_expression(interface, attribute, contents),
        'enum_validation_expression': v8_utilities.enum_validation_expression(idl_type),
        'has_strict_type_checking': 'StrictTypeChecking' in extended_attributes and v8_types.is_interface_type(idl_type),
        'is_reflect': is_reflect,
        'v8_value_to_local_cpp_value': v8_types.v8_value_to_local_cpp_value(
            idl_type, extended_attributes, 'jsValue', 'cppValue'),
    })
Ejemplo n.º 10
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 ''
Ejemplo n.º 11
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)
Ejemplo n.º 12
0
def v8_set_return_value(interface_name, method, cpp_value):
    idl_type = method.idl_type
    extended_attributes = method.extended_attributes
    if idl_type == 'void':
        return None
    # [CallWith=ScriptState], [RaisesException]
    if (has_extended_attribute_value(method, 'CallWith', 'ScriptState') or
        'RaisesException' in extended_attributes):
        # use local variable for value
        if v8_types.is_interface_type(idl_type):
            cpp_value = 'result.release()'
        else:
            cpp_value = 'result'
    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)
Ejemplo n.º 13
0
def generate_getter(interface, attribute, contents):
    idl_type = attribute.idl_type
    extended_attributes = attribute.extended_attributes

    cpp_value = getter_expression(interface, attribute, contents)
    # 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 (attribute.is_nullable or idl_type == 'EventHandler'
            or 'CachedAttribute' in extended_attributes
            or contents['is_getter_raises_exception']):
        contents['cpp_value_original'] = cpp_value
        cpp_value = 'jsValue'
        # EventHandler has special handling
        if idl_type != 'EventHandler' and v8_types.is_interface_type(idl_type):
            release = True

    if 'ReflectOnly' in extended_attributes:
        contents['cpp_value_original'] = cpp_value
        # FIXME: rename to jsValue
        cpp_value = 'resultValue'

    def v8_set_return_value_statement(for_main_world=False):
        if contents['is_keep_alive_for_gc']:
            return 'v8SetReturnValue(info, wrapper)'
        return v8_types.v8_set_return_value(
            idl_type,
            cpp_value,
            extended_attributes=extended_attributes,
            script_wrappable='imp',
            release=release,
            for_main_world=for_main_world)

    contents.update({
        'cpp_value':
        cpp_value,
        'v8_set_return_value_for_main_world':
        v8_set_return_value_statement(for_main_world=True),
        'v8_set_return_value':
        v8_set_return_value_statement(),
    })
Ejemplo n.º 14
0
def overload_check_argument(index, argument):
    def null_or_optional_check():
        # If undefined is passed for an optional argument, the argument should
        # be treated as missing; otherwise undefined is not allowed.
        if argument['is_nullable']:
            if argument['is_optional']:
                return 'isUndefinedOrNull(%s)'
            return '%s->IsNull()'
        if argument['is_optional']:
            return '%s->IsUndefined()'
        return None

    cpp_value = 'info[%s]' % index
    idl_type = argument['idl_type']
    # FIXME: proper type checking, sharing code with attributes and methods
    if idl_type == 'DOMString' and argument['is_strict_type_checking']:
        return ' || '.join(['isUndefinedOrNull(%s)' % cpp_value,
                            '%s->IsString()' % cpp_value,
                            '%s->IsObject()' % cpp_value])
    if v8_types.array_or_sequence_type(idl_type):
        return '%s->IsArray()' % cpp_value
    if v8_types.is_callback_interface(idl_type):
        return ' || '.join(['%s->IsNull()' % cpp_value,
                            '%s->IsFunction()' % cpp_value])
    if v8_types.is_wrapper_type(idl_type):
        type_check = 'V8{idl_type}::hasInstance({cpp_value}, info.GetIsolate())'.format(idl_type=idl_type, cpp_value=cpp_value)
        if argument['is_nullable']:
            type_check = ' || '.join(['%s->IsNull()' % cpp_value, type_check])
        return type_check
    if is_interface_type(idl_type):
        # Non-wrapper types are just objects: we don't distinguish type
        # We only allow undefined for non-wrapper types (notably Dictionary),
        # as we need it for optional Dictionary arguments, but we don't want to
        # change behavior of existing bindings for other types.
        type_check = '%s->IsObject()' % cpp_value
        added_check_template = null_or_optional_check()
        if added_check_template:
            type_check = ' || '.join([added_check_template % cpp_value,
                                      type_check])
        return type_check
    return None
def setter_expression(interface, attribute, contents):
    arguments = v8_utilities.call_with_arguments(attribute, attribute.extended_attributes.get('SetterCallWith'))

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

    idl_type = attribute.idl_type
    if idl_type == 'EventHandler':
        # FIXME: move V8EventListenerList.h to INCLUDES_FOR_TYPE
        includes.add('bindings/v8/V8EventListenerList.h')
        # FIXME: pass the isolate instead of the isolated world
        isolated_world = 'isolatedWorldForIsolate(info.GetIsolate())'
        arguments.extend(['V8EventListenerList::getEventListener(jsValue, true, ListenerFindOrCreate)', isolated_world])
        contents['event_handler_getter_expression'] = 'imp->%s(%s)' % (cpp_name(attribute), isolated_world)
    elif v8_types.is_interface_type(idl_type) and not v8_types.array_type(idl_type):
        # FIXME: should be able to eliminate WTF::getPtr in most or all cases
        arguments.append('WTF::getPtr(cppValue)')
    else:
        arguments.append('cppValue')
    if contents['is_setter_raises_exception']:
        arguments.append('es')

    return '%s(%s)' % (setter_name, ', '.join(arguments))
Ejemplo n.º 16
0
def generate_getter(interface, attribute, contents):
    idl_type = attribute.idl_type
    extended_attributes = attribute.extended_attributes

    cpp_value = getter_expression(interface, attribute, contents)
    # 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 (attribute.is_nullable or
        idl_type == 'EventHandler' or
        'CachedAttribute' in extended_attributes or
        contents['is_getter_raises_exception']):
        contents['cpp_value_original'] = cpp_value
        cpp_value = 'jsValue'
        # EventHandler has special handling
        if idl_type != 'EventHandler' and v8_types.is_interface_type(idl_type):
            release = True

    if 'ReflectOnly' in extended_attributes:
        contents['cpp_value_original'] = cpp_value
        # FIXME: rename to jsValue
        cpp_value = 'resultValue'

    def v8_set_return_value_statement(for_main_world=False):
        if contents['is_keep_alive_for_gc']:
            return 'v8SetReturnValue(info, wrapper)'
        return v8_types.v8_set_return_value(idl_type, cpp_value, extended_attributes=extended_attributes, script_wrappable='imp', release=release, for_main_world=for_main_world)

    contents.update({
        'cpp_value': cpp_value,
        'v8_set_return_value_for_main_world': v8_set_return_value_statement(for_main_world=True),
        'v8_set_return_value': v8_set_return_value_statement(),
    })
Ejemplo n.º 17
0
def setter_expression(interface, attribute, contents):
    extended_attributes = attribute.extended_attributes
    arguments = v8_utilities.call_with_arguments(
        attribute, extended_attributes.get('SetterCallWith'))

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

    if ('ImplementedBy' in extended_attributes and not attribute.is_static):
        arguments.append('imp')
    idl_type = attribute.idl_type
    if idl_type == 'EventHandler':
        getter_name = v8_utilities.scoped_name(interface, attribute,
                                               cpp_name(attribute))
        contents['event_handler_getter_expression'] = '%s(%s)' % (
            getter_name, ', '.join(arguments))
        if (interface.name in ['Window', 'WorkerGlobalScope']
                and attribute.name == 'onerror'):
            includes.add('bindings/v8/V8ErrorHandler.h')
            arguments.append(
                'V8EventListenerList::findOrCreateWrapper<V8ErrorHandler>(jsValue, true, info.GetIsolate())'
            )
        else:
            arguments.append(
                'V8EventListenerList::getEventListener(jsValue, true, ListenerFindOrCreate)'
            )
    elif v8_types.is_interface_type(
            idl_type) and not v8_types.array_type(idl_type):
        # FIXME: should be able to eliminate WTF::getPtr in most or all cases
        arguments.append('WTF::getPtr(cppValue)')
    else:
        arguments.append('cppValue')
    if contents['is_setter_raises_exception']:
        arguments.append('exceptionState')

    return '%s(%s)' % (setter_name, ', '.join(arguments))
Ejemplo n.º 18
0
def generate_attribute(interface, attribute):
    idl_type = attribute.idl_type
    extended_attributes = attribute.extended_attributes

    v8_types.add_includes_for_type(idl_type)

    # [CheckSecurity]
    is_check_security_for_node = 'CheckSecurity' in extended_attributes
    if is_check_security_for_node:
        includes.add('bindings/v8/BindingSecurity.h')
    # [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'])
    # [RaisesException]
    is_getter_raises_exception = (
        'RaisesException' in extended_attributes and
        extended_attributes['RaisesException'] in [None, 'Getter'])
    if is_check_security_for_node or is_getter_raises_exception:
        includes.add('bindings/v8/ExceptionMessages.h')
    # [Reflect]
    is_reflect = 'Reflect' in extended_attributes
    if is_reflect:
        includes.add('core/dom/custom/CustomElementCallbackDispatcher.h')

    if (idl_type == 'EventHandler' and
        interface.name in ['Window', 'WorkerGlobalScope'] and
        attribute.name == 'onerror'):
        includes.add('bindings/v8/V8ErrorHandler.h')

    contents = {
        'access_control_list': access_control_list(attribute),
        'activity_logging_world_list_for_getter': v8_utilities.activity_logging_world_list(attribute, 'Getter'),  # [ActivityLogging]
        'activity_logging_world_list_for_setter': v8_utilities.activity_logging_world_list(attribute, 'Setter'),  # [ActivityLogging]
        'cached_attribute_validation_method': extended_attributes.get('CachedAttribute'),
        'conditional_string': v8_utilities.conditional_string(attribute),
        'constructor_type': v8_types.constructor_type(idl_type)
                            if is_constructor_attribute(attribute) else None,
        'cpp_name': cpp_name(attribute),
        'cpp_type': v8_types.cpp_type(idl_type),
        'deprecate_as': v8_utilities.deprecate_as(attribute),  # [DeprecateAs]
        'enum_validation_expression':
            v8_utilities.enum_validation_expression(idl_type),
        'has_custom_getter': has_custom_getter,
        'has_custom_setter': has_custom_setter,
        'has_strict_type_checking': (
            'StrictTypeChecking' in extended_attributes and
            v8_types.is_interface_type(idl_type)),
        'idl_type': idl_type,
        'is_call_with_execution_context': v8_utilities.has_extended_attribute_value(attribute, 'CallWith', 'ExecutionContext'),
        'is_check_security_for_node': is_check_security_for_node,
        'is_expose_js_accessors': 'ExposeJSAccessors' in extended_attributes,
        'is_getter_raises_exception': (
            'RaisesException' in extended_attributes and
            extended_attributes['RaisesException'] in [None, 'Getter']),
        'is_initialized_by_event_constructor':
            'InitializedByEventConstructor' in extended_attributes,
        'is_keep_alive_for_gc': is_keep_alive_for_gc(attribute),
        'is_nullable': attribute.is_nullable,
        'is_per_world_bindings': 'PerWorldBindings' in extended_attributes,
        'is_read_only': attribute.is_read_only,
        'is_reflect': is_reflect,
        'is_replaceable': 'Replaceable' in attribute.extended_attributes,
        'is_setter_raises_exception': (
            'RaisesException' in extended_attributes and
            extended_attributes['RaisesException'] in [None, 'Setter']),
        'is_static': attribute.is_static,
        'is_unforgeable': 'Unforgeable' in extended_attributes,
        'measure_as': v8_utilities.measure_as(attribute),  # [MeasureAs]
        'name': attribute.name,
        'per_context_enabled_function': v8_utilities.per_context_enabled_function_name(attribute),  # [PerContextEnabled]
        'property_attributes': property_attributes(attribute),
        'setter_callback': setter_callback_name(interface, attribute),
        'v8_type': v8_types.v8_type(idl_type),
        'runtime_enabled_function': v8_utilities.runtime_enabled_function_name(attribute),  # [RuntimeEnabled]
        'world_suffixes': ['', 'ForMainWorld']
                          if 'PerWorldBindings' in extended_attributes
                          else [''],  # [PerWorldBindings]
    }

    if is_constructor_attribute(attribute):
        return contents
    if not has_custom_getter:
        generate_getter(interface, attribute, contents)
    if not(attribute.is_read_only or has_custom_setter):
        contents.update({
            'cpp_setter': setter_expression(interface, attribute, contents),
            'v8_value_to_local_cpp_value': v8_types.v8_value_to_local_cpp_value(
                idl_type, extended_attributes, 'jsValue', 'cppValue'),
        })

    return contents
Ejemplo n.º 19
0
def generate_attribute(interface, attribute):
    idl_type = attribute.idl_type
    extended_attributes = attribute.extended_attributes

    v8_types.add_includes_for_type(idl_type)

    # [CheckSecurity]
    is_check_security_for_node = 'CheckSecurity' in extended_attributes
    if is_check_security_for_node:
        includes.add('bindings/v8/BindingSecurity.h')
    # [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'])
    # [Reflect]
    is_reflect = 'Reflect' in extended_attributes
    if is_reflect:
        includes.add('core/dom/custom/CustomElementCallbackDispatcher.h')

    if (idl_type == 'EventHandler'
            and interface.name in ['Window', 'WorkerGlobalScope']
            and attribute.name == 'onerror'):
        includes.add('bindings/v8/V8ErrorHandler.h')

    contents = {
        'access_control_list':
        access_control_list(attribute),
        'activity_logging_world_list_for_getter':
        v8_utilities.activity_logging_world_list(
            attribute, 'Getter'),  # [ActivityLogging]
        'activity_logging_world_list_for_setter':
        v8_utilities.activity_logging_world_list(
            attribute, 'Setter'),  # [ActivityLogging]
        'cached_attribute_validation_method':
        extended_attributes.get('CachedAttribute'),
        'conditional_string':
        v8_utilities.conditional_string(attribute),
        'constructor_type':
        v8_types.constructor_type(idl_type)
        if is_constructor_attribute(attribute) else None,
        'cpp_name':
        cpp_name(attribute),
        'cpp_type':
        v8_types.cpp_type(idl_type),
        'deprecate_as':
        v8_utilities.deprecate_as(attribute),  # [DeprecateAs]
        'enum_validation_expression':
        v8_utilities.enum_validation_expression(idl_type),
        'has_custom_getter':
        has_custom_getter,
        'has_custom_setter':
        has_custom_setter,
        'has_strict_type_checking':
        ('StrictTypeChecking' in extended_attributes
         and v8_types.is_interface_type(idl_type)),
        'idl_type':
        idl_type,
        'is_call_with_execution_context':
        v8_utilities.has_extended_attribute_value(attribute, 'CallWith',
                                                  'ExecutionContext'),
        'is_check_security_for_node':
        is_check_security_for_node,
        'is_expose_js_accessors':
        'ExposeJSAccessors' in extended_attributes,
        'is_getter_raises_exception': (  # [RaisesException]
            'RaisesException' in extended_attributes
            and extended_attributes['RaisesException'] in [None, 'Getter']),
        'is_initialized_by_event_constructor':
        'InitializedByEventConstructor' in extended_attributes,
        'is_keep_alive_for_gc':
        is_keep_alive_for_gc(attribute),
        'is_nullable':
        attribute.is_nullable,
        'is_per_world_bindings':
        'PerWorldBindings' in extended_attributes,
        'is_read_only':
        attribute.is_read_only,
        'is_reflect':
        is_reflect,
        'is_replaceable':
        'Replaceable' in attribute.extended_attributes,
        'is_setter_raises_exception':
        ('RaisesException' in extended_attributes
         and extended_attributes['RaisesException'] in [None, 'Setter']),
        'is_static':
        attribute.is_static,
        'is_unforgeable':
        'Unforgeable' in extended_attributes,
        'measure_as':
        v8_utilities.measure_as(attribute),  # [MeasureAs]
        'name':
        attribute.name,
        'per_context_enabled_function':
        v8_utilities.per_context_enabled_function_name(
            attribute),  # [PerContextEnabled]
        'property_attributes':
        property_attributes(attribute),
        'setter_callback':
        setter_callback_name(interface, attribute),
        'v8_type':
        v8_types.v8_type(idl_type),
        'runtime_enabled_function':
        v8_utilities.runtime_enabled_function_name(
            attribute),  # [RuntimeEnabled]
        'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings'
        in extended_attributes else [''],  # [PerWorldBindings]
    }

    if is_constructor_attribute(attribute):
        return contents
    if not has_custom_getter:
        generate_getter(interface, attribute, contents)
    if not (attribute.is_read_only or has_custom_setter):
        contents.update({
            'cpp_setter':
            setter_expression(interface, attribute, contents),
            'v8_value_to_local_cpp_value':
            v8_types.v8_value_to_local_cpp_value(idl_type, extended_attributes,
                                                 'jsValue', 'cppValue'),
        })

    return contents