Example #1
0
def generate_argument(method, argument, index):
    extended_attributes = argument.extended_attributes
    idl_type = argument.idl_type
    return {
        'cpp_method':
        cpp_method(method, index),
        'cpp_type':
        v8_types.cpp_type(idl_type),
        'enum_validation_expression':
        v8_utilities.enum_validation_expression(idl_type),
        'has_default':
        'Default' in extended_attributes,
        'idl_type':
        argument.idl_type,
        'index':
        index,
        'is_clamp':
        'Clamp' in extended_attributes,
        'is_optional':
        argument.is_optional,
        'is_variadic_wrapper_type':
        argument.is_variadic and v8_types.is_wrapper_type(idl_type),
        'name':
        argument.name,
        'v8_value_to_local_cpp_value':
        v8_value_to_local_cpp_value(argument, index),
    }
def generate_method_contents(operation):
    contents = {
        'name': operation.name,
        'return_cpp_type': cpp_type(operation.data_type, 'RefPtr'),
        'custom': 'Custom' in operation.extended_attributes,
    }
    contents.update(generate_arguments_contents(operation.arguments))
    return contents
def cpp_type(idl_type):
    # FIXME: remove this function by making callback types consistent
    # (always use usual v8_types.cpp_type)
    if idl_type == 'DOMString':
        return 'const String&'
    # Callbacks use raw pointers, so used_as_argument=True
    usual_cpp_type = v8_types.cpp_type(idl_type, used_as_argument=True)
    if usual_cpp_type.startswith('Vector'):
        return 'const %s&' % usual_cpp_type
    return usual_cpp_type
def cpp_type(idl_type):
    # FIXME: remove this function by making callback types consistent
    # (always use usual v8_types.cpp_type)
    if idl_type == 'DOMString':
        return 'const String&'
    if idl_type == 'void':
        return 'void'
    # Callbacks use raw pointers, so used_as_argument=True
    usual_cpp_type = v8_types.cpp_type(idl_type, used_as_argument=True)
    if usual_cpp_type.startswith('Vector'):
        return 'const %s&' % usual_cpp_type
    return usual_cpp_type
Example #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),
    }
Example #6
0
def v8_value_to_local_cpp_value(argument, index):
    extended_attributes = argument.extended_attributes
    idl_type = argument.idl_type
    name = argument.name
    if argument.is_variadic:
        return 'V8TRYCATCH_VOID(Vector<{cpp_type}>, {name}, toNativeArguments<{cpp_type}>(info, {index}))'.format(
                cpp_type=v8_types.cpp_type(idl_type), name=name, index=index)
    if (argument.is_optional and idl_type == 'DOMString' and
        extended_attributes.get('Default') == 'NullString'):
        v8_value = 'argumentOrNull(info, %s)' % index
    else:
        v8_value = 'info[%s]' % index
    return v8_types.v8_value_to_local_cpp_value(
        idl_type, argument.extended_attributes, v8_value, name, index=index)
def generate_attribute(interface, attribute):
    idl_type = attribute.idl_type
    extended_attributes = attribute.extended_attributes

    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'])
    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),
        'cpp_type': v8_types.cpp_type(idl_type),
        'getter_callback_name': getter_callback_name(interface, attribute),
        'getter_callback_name_for_main_world': getter_callback_name_for_main_world(interface, attribute),
        'has_custom_getter': has_custom_getter,
        'has_custom_setter': has_custom_setter,
        'idl_type': idl_type,
        'is_call_with_execution_context': v8_utilities.has_extended_attribute_value(attribute, 'CallWith', 'ExecutionContext'),
        'is_constructor': is_constructor_attribute(attribute),
        'is_getter_raises_exception': has_extended_attribute(attribute, ('GetterRaisesException', 'RaisesException')),
        'is_keep_alive_for_gc': is_keep_alive_for_gc(attribute),
        'is_nullable': attribute.is_nullable,
        'is_read_only': attribute.is_read_only,
        'is_replaceable': 'Replaceable' in attribute.extended_attributes,
        'is_setter_raises_exception': has_extended_attribute(attribute, ('RaisesException', 'SetterRaisesException')),
        'is_static': attribute.is_static,
        'name': attribute.name,
        'per_context_enabled_function_name': v8_utilities.per_context_enabled_function_name(attribute),  # [PerContextEnabled]
        'property_attributes': property_attributes(attribute),
        'setter_callback_name': setter_callback_name(interface, attribute),
        'setter_callback_name_for_main_world': setter_callback_name_for_main_world(interface, attribute),
        'v8_type': v8_types.v8_type(idl_type),
        'runtime_enabled_function_name': v8_utilities.runtime_enabled_function_name(attribute),  # [RuntimeEnabled]
        'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended_attributes else [''],  # [PerWorldBindings]
        'wrapper_type_info': wrapper_type_info(attribute),
    }
    if is_constructor_attribute(attribute):
        includes.update(v8_types.includes_for_type(idl_type))
        return contents
    if not has_custom_getter:
        generate_getter(interface, attribute, contents)
    if not attribute.is_read_only and not has_custom_setter:
        generate_setter(interface, attribute, contents)

    return contents
def generate_method(operation):
    if operation.idl_type != 'boolean':
        raise Exception("We don't yet support callbacks that return non-boolean values.")
    is_custom = 'Custom' in operation.extended_attributes
    if not is_custom:
        add_includes_for_operation(operation)
    extended_attributes = operation.extended_attributes
    call_with = extended_attributes.get('CallWith')
    contents = {
        'call_with_this_handle': extended_attribute_value_contains(call_with, 'ThisValue'),
        'custom': is_custom,
        'name': operation.name,
        'return_cpp_type': cpp_type(operation.idl_type, 'RefPtr'),
    }
    contents.update(generate_arguments_contents(operation.arguments, call_with_this_handle))
    return contents
Example #9
0
def generate_argument(method, argument, index):
    extended_attributes = argument.extended_attributes
    idl_type = argument.idl_type
    return {
        'cpp_method': cpp_method(method, index),
        'cpp_type': v8_types.cpp_type(idl_type),
        'enum_validation_expression': v8_utilities.enum_validation_expression(idl_type),
        'has_default': 'Default' in extended_attributes,
        'idl_type': argument.idl_type,
        'index': index,
        'is_clamp': 'Clamp' in extended_attributes,
        'is_optional': argument.is_optional,
        'is_variadic_wrapper_type': argument.is_variadic and v8_types.is_wrapper_type(idl_type),
        'name': argument.name,
        'v8_value_to_local_cpp_value': v8_value_to_local_cpp_value(argument, index),
    }
Example #10
0
def v8_value_to_local_cpp_value(argument, index):
    extended_attributes = argument.extended_attributes
    idl_type = argument.idl_type
    name = argument.name
    if argument.is_variadic:
        return 'V8TRYCATCH_VOID(Vector<{cpp_type}>, {name}, toNativeArguments<{cpp_type}>(info, {index}))'.format(
            cpp_type=v8_types.cpp_type(idl_type), name=name, index=index)
    if (argument.is_optional and idl_type == 'DOMString'
            and extended_attributes.get('Default') == 'NullString'):
        v8_value = 'argumentOrNull(info, %s)' % index
    else:
        v8_value = 'info[%s]' % index
    return v8_types.v8_value_to_local_cpp_value(idl_type,
                                                argument.extended_attributes,
                                                v8_value,
                                                name,
                                                index=index)
def generate_argument(interface, method, argument, index):
    extended_attributes = argument.extended_attributes
    idl_type = argument.idl_type
    this_cpp_value = cpp_value(interface, method, index)
    return {
        'cpp_type': v8_types.cpp_type(idl_type),
        'cpp_value': this_cpp_value,
        'enum_validation_expression': v8_utilities.enum_validation_expression(idl_type),
        'has_default': 'Default' in extended_attributes,
        'idl_type': idl_type,
        'index': index,
        'is_clamp': 'Clamp' in extended_attributes,
        'is_optional': argument.is_optional,
        'is_strict_type_checking': 'StrictTypeChecking' in method.extended_attributes and v8_types.is_wrapper_type(idl_type),
        'is_variadic_wrapper_type': argument.is_variadic and v8_types.is_wrapper_type(idl_type),
        'name': argument.name,
        'v8_set_return_value': v8_set_return_value(method, this_cpp_value),
        'v8_value_to_local_cpp_value': v8_value_to_local_cpp_value(argument, index),
    }
Example #12
0
def generate_argument(interface, method, argument, index):
    extended_attributes = argument.extended_attributes
    idl_type = argument.idl_type
    this_cpp_value = cpp_value(interface, method, index)
    return {
        'cpp_type':
        v8_types.cpp_type(idl_type),
        'cpp_value':
        this_cpp_value,
        'enum_validation_expression':
        v8_utilities.enum_validation_expression(idl_type),
        'has_default':
        'Default' in extended_attributes,
        'idl_type':
        idl_type,
        'index':
        index,
        'is_clamp':
        'Clamp' in extended_attributes,
        'is_callback_interface':
        v8_types.is_callback_interface(idl_type),
        'is_nullable':
        argument.is_nullable,
        'is_optional':
        argument.is_optional,
        'is_strict_type_checking':
        'StrictTypeChecking' in extended_attributes,
        'is_variadic_wrapper_type':
        argument.is_variadic and v8_types.is_wrapper_type(idl_type),
        'is_wrapper_type':
        v8_types.is_wrapper_type(idl_type),
        'name':
        argument.name,
        'v8_set_return_value_for_main_world':
        v8_set_return_value(interface.name,
                            method,
                            this_cpp_value,
                            for_main_world=True),
        'v8_set_return_value':
        v8_set_return_value(interface.name, method, this_cpp_value),
        'v8_value_to_local_cpp_value':
        v8_value_to_local_cpp_value(argument, index),
    }
Example #13
0
def generate_attribute_and_includes(attribute):
    idl_type = attribute.data_type
    # FIXME: need to check should_keep_attribute_alive, but for now sufficient
    # to check if primitive.
    should_keep_attribute_alive = not v8_types.primitive_type(idl_type)
    if should_keep_attribute_alive:
        return_v8_value_statement = None  # unused
        includes = v8_types.includes_for_type(idl_type)
        includes.add('bindings/v8/V8HiddenPropertyName.h')
    else:
        cpp_value = 'imp->%s()' % uncapitalize(attribute.name)
        return_v8_value_statement = v8_types.v8_set_return_value(idl_type, cpp_value, callback_info='info')
        includes = []
    contents = {
        'name': attribute.name,
        'conditional_string': generate_conditional_string(attribute),
        'cpp_method_name': cpp_method_name(attribute),
        'cpp_type': v8_types.cpp_type(idl_type, pointer_type='RefPtr'),
        'should_keep_attribute_alive': should_keep_attribute_alive,
        'return_v8_value_statement': return_v8_value_statement,
        'v8_type': v8_types.v8_type(idl_type),
    }
    return contents, includes
def generate_method(operation):
    if operation.idl_type != 'boolean':
        raise Exception(
            "We don't yet support callbacks that return non-boolean values.")
    is_custom = 'Custom' in operation.extended_attributes
    if not is_custom:
        add_includes_for_operation(operation)
    extended_attributes = operation.extended_attributes
    call_with = extended_attributes.get('CallWith')
    contents = {
        'call_with_this_handle':
        extended_attribute_value_contains(call_with, 'ThisValue'),
        'custom':
        is_custom,
        'name':
        operation.name,
        'return_cpp_type':
        cpp_type(operation.idl_type, 'RefPtr'),
    }
    contents.update(
        generate_arguments_contents(operation.arguments,
                                    call_with_this_handle))
    return contents
Example #15
0
def method_context(interface, method, component_info, is_visible=True):
    arguments = method.arguments
    extended_attributes = method.extended_attributes
    idl_type = method.idl_type
    is_static = method.is_static
    name = method.name

    if is_visible:
        idl_type.add_includes_for_type(extended_attributes)

    this_cpp_value = cpp_value(interface, method, len(arguments))

    is_call_with_script_state = has_extended_attribute_value(
        method, 'CallWith', 'ScriptState')
    is_call_with_this_value = has_extended_attribute_value(
        method, 'CallWith', 'ThisValue')
    if is_call_with_script_state or is_call_with_this_value:
        includes.add('platform/bindings/script_state.h')

    # [CheckSecurity]
    is_cross_origin = 'CrossOrigin' in extended_attributes
    is_check_security_for_receiver = (has_extended_attribute_value(
        interface, 'CheckSecurity', 'Receiver') and not is_cross_origin)
    is_check_security_for_return_value = (has_extended_attribute_value(
        method, 'CheckSecurity', 'ReturnValue'))
    if is_check_security_for_receiver or is_check_security_for_return_value:
        includes.add('bindings/core/v8/binding_security.h')
    if is_check_security_for_return_value:
        includes.add('core/frame/web_feature.h')
        includes.add('platform/instrumentation/use_counter.h')

    is_ce_reactions = 'CEReactions' in extended_attributes
    if is_ce_reactions:
        includes.add('core/html/custom/ce_reactions_scope.h')
    is_custom_element_callbacks = 'CustomElementCallbacks' in extended_attributes
    if is_custom_element_callbacks:
        includes.add('core/html/custom/v0_custom_element_processing_stack.h')

    is_raises_exception = 'RaisesException' in extended_attributes

    if 'LenientThis' in extended_attributes:
        raise Exception('[LenientThis] is not supported for operations.')

    if has_extended_attribute_value(method, 'Affects', 'Nothing'):
        side_effect_type = 'V8DOMConfiguration::kHasNoSideEffect'
    else:
        side_effect_type = 'V8DOMConfiguration::kHasSideEffect'

    # [LogActivity]
    if 'LogActivity' in extended_attributes:
        includes.add('platform/bindings/v8_per_context_data.h')

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

    runtime_features = component_info['runtime_enabled_features']

    return {
        'activity_logging_world_list':
        v8_utilities.activity_logging_world_list(method),  # [ActivityLogging]
        'arguments':
        argument_contexts,
        'camel_case_name':
        NameStyleConverter(name).to_upper_camel_case(),
        'cpp_type':
        (v8_types.cpp_template_type('base::Optional', idl_type.cpp_type)
         if idl_type.is_explicit_nullable else v8_types.cpp_type(
             idl_type, extended_attributes=extended_attributes)),
        'cpp_value':
        this_cpp_value,
        'cpp_type_initializer':
        idl_type.cpp_type_initializer,
        'high_entropy':
        v8_utilities.high_entropy(method),  # [HighEntropy]
        'deprecate_as':
        v8_utilities.deprecate_as(method),  # [DeprecateAs]
        'do_not_test_new_object':
        'DoNotTestNewObject' in extended_attributes,
        'exposed_test':
        v8_utilities.exposed(method, interface),  # [Exposed]
        'has_exception_state':
        is_raises_exception or is_check_security_for_receiver
        or any(argument for argument in arguments
               if argument_conversion_needs_exception_state(method, argument)),
        'has_optional_argument_without_default_value':
        any(True for argument_context in argument_contexts
            if argument_context['is_optional_without_default_value']),
        'idl_type':
        idl_type.base_type,
        'is_call_with_execution_context':
        has_extended_attribute_value(method, 'CallWith', 'ExecutionContext'),
        'is_call_with_script_state':
        is_call_with_script_state,
        'is_call_with_this_value':
        is_call_with_this_value,
        'is_ce_reactions':
        is_ce_reactions,
        'is_check_security_for_receiver':
        is_check_security_for_receiver,
        'is_check_security_for_return_value':
        is_check_security_for_return_value,
        'is_cross_origin':
        'CrossOrigin' in extended_attributes,
        'is_custom':
        'Custom' in extended_attributes,
        'is_custom_element_callbacks':
        is_custom_element_callbacks,
        'is_explicit_nullable':
        idl_type.is_explicit_nullable,
        'is_new_object':
        'NewObject' in extended_attributes,
        'is_partial_interface_member':
        'PartialInterfaceImplementedAs' in extended_attributes,
        'is_per_world_bindings':
        'PerWorldBindings' in extended_attributes,
        'is_raises_exception':
        is_raises_exception,
        'is_static':
        is_static,
        'is_unforgeable':
        is_unforgeable(method),
        'is_variadic':
        arguments and arguments[-1].is_variadic,
        'measure_as':
        v8_utilities.measure_as(method, interface),  # [MeasureAs]
        'name':
        name,
        'number_of_arguments':
        len(arguments),
        'number_of_required_arguments':
        len([
            argument for argument in arguments
            if not (argument.is_optional or argument.is_variadic)
        ]),
        'number_of_required_or_variadic_arguments':
        len([argument for argument in arguments if not argument.is_optional]),
        'on_instance':
        v8_utilities.on_instance(interface, method),
        'on_interface':
        v8_utilities.on_interface(interface, method),
        'on_prototype':
        v8_utilities.on_prototype(interface, method),
        # [RuntimeEnabled] for origin trial
        'origin_trial_feature_name':
        v8_utilities.origin_trial_feature_name(method, runtime_features),
        'property_attributes':
        property_attributes(interface, method),
        'returns_promise':
        method.returns_promise,
        'runtime_call_stats':
        runtime_call_stats_context(interface, method),
        # [RuntimeEnabled] if not in origin trial
        'runtime_enabled_feature_name':
        v8_utilities.runtime_enabled_feature_name(method, runtime_features),
        # [SecureContext]
        'secure_context_test':
        v8_utilities.secure_context(method, interface),
        # [Affects]
        'side_effect_type':
        side_effect_type,
        'snake_case_name':
        NameStyleConverter(name).to_snake_case(),
        'use_output_parameter_for_result':
        idl_type.use_output_parameter_for_result,
        'use_local_result':
        use_local_result(method),
        'v8_set_return_value':
        v8_set_return_value(interface.name, method, this_cpp_value),
        'v8_set_return_value_for_main_world':
        v8_set_return_value(interface.name,
                            method,
                            this_cpp_value,
                            for_main_world=True),
        'visible':
        is_visible,
        'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings'
        in extended_attributes else [''],  # [PerWorldBindings],
    }
Example #16
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
Example #17
0
def generate_method(interface, method):
    arguments = method.arguments
    extended_attributes = method.extended_attributes
    idl_type = method.idl_type
    is_static = method.is_static
    name = method.name

    this_cpp_value = cpp_value(interface, method, len(arguments))
    this_custom_signature = custom_signature(method, arguments)

    def function_template():
        if is_static:
            return 'functionTemplate'
        if 'Unforgeable' in extended_attributes:
            return 'instanceTemplate'
        return 'prototypeTemplate'

    def signature():
        if this_custom_signature:
            return name + 'Signature'
        if is_static or 'DoNotCheckSignature' in extended_attributes:
            return 'v8::Local<v8::Signature>()'
        return 'defaultSignature'

    is_call_with_script_arguments = has_extended_attribute_value(
        method, 'CallWith', 'ScriptArguments')
    if is_call_with_script_arguments:
        includes.update([
            'bindings/v8/ScriptCallStackFactory.h',
            'core/inspector/ScriptArguments.h'
        ])
    is_call_with_script_state = has_extended_attribute_value(
        method, 'CallWith', 'ScriptState')
    if is_call_with_script_state:
        includes.add('bindings/v8/ScriptState.h')
    is_check_security_for_node = 'CheckSecurity' in extended_attributes
    if is_check_security_for_node:
        includes.add('bindings/v8/BindingSecurity.h')
    is_custom_element_callbacks = 'CustomElementCallbacks' in extended_attributes
    if is_custom_element_callbacks:
        includes.add('core/dom/custom/CustomElementCallbackDispatcher.h')

    contents = {
        'activity_logging_world_list':
        v8_utilities.activity_logging_world_list(method),  # [ActivityLogging]
        'arguments': [
            generate_argument(interface, method, argument, index)
            for index, argument in enumerate(arguments)
        ],
        'conditional_string':
        v8_utilities.conditional_string(method),
        'cpp_type':
        v8_types.cpp_type(idl_type),
        'cpp_value':
        this_cpp_value,
        'custom_signature':
        this_custom_signature,
        'deprecate_as':
        v8_utilities.deprecate_as(method),  # [DeprecateAs]
        'do_not_check_signature':
        not (this_custom_signature or is_static
             or v8_utilities.has_extended_attribute(method, [
                 'DoNotCheckSecurity', 'DoNotCheckSignature', 'NotEnumerable',
                 'ReadOnly', 'RuntimeEnabled', 'Unforgeable'
             ])),
        'function_template':
        function_template(),
        'idl_type':
        idl_type,
        'is_call_with_execution_context':
        has_extended_attribute_value(method, 'CallWith', 'ExecutionContext'),
        'is_call_with_script_arguments':
        is_call_with_script_arguments,
        'is_call_with_script_state':
        is_call_with_script_state,
        'is_check_security_for_frame':
        ('CheckSecurity' in interface.extended_attributes
         and 'DoNotCheckSecurity' not in extended_attributes),
        'is_check_security_for_node':
        is_check_security_for_node,
        'is_custom':
        'Custom' in extended_attributes,
        'is_custom_element_callbacks':
        is_custom_element_callbacks,
        'is_do_not_check_security':
        'DoNotCheckSecurity' in extended_attributes,
        'is_per_world_bindings':
        'PerWorldBindings' in extended_attributes,
        'is_raises_exception':
        'RaisesException' in extended_attributes,
        'is_read_only':
        'ReadOnly' in extended_attributes,
        'is_static':
        is_static,
        'is_strict_type_checking':
        'StrictTypeChecking' in extended_attributes,
        'is_variadic':
        arguments and arguments[-1].is_variadic,
        'measure_as':
        v8_utilities.measure_as(method),  # [MeasureAs]
        'name':
        name,
        'number_of_arguments':
        len(arguments),
        'number_of_required_arguments':
        len([
            argument for argument in arguments
            if not (argument.is_optional or argument.is_variadic)
        ]),
        'number_of_required_or_variadic_arguments':
        len([argument for argument in arguments if not argument.is_optional]),
        'per_context_enabled_function':
        v8_utilities.per_context_enabled_function_name(
            method),  # [PerContextEnabled]
        'property_attributes':
        property_attributes(method),
        'runtime_enabled_function':
        v8_utilities.runtime_enabled_function_name(method),  # [RuntimeEnabled]
        'signature':
        signature(),
        'v8_set_return_value':
        v8_set_return_value(method, this_cpp_value),
        'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings'
        in extended_attributes else [''],  # [PerWorldBindings]
    }
    return contents
Example #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'])
    # [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
Example #19
0
def generate_method(interface, method):
    arguments = method.arguments
    extended_attributes = method.extended_attributes
    idl_type = method.idl_type
    is_static = method.is_static
    name = method.name

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

    def function_template():
        if is_static:
            return 'functionTemplate'
        if 'Unforgeable' in extended_attributes:
            return 'instanceTemplate'
        return 'prototypeTemplate'

    is_call_with_script_arguments = has_extended_attribute_value(method, 'CallWith', 'ScriptArguments')
    if is_call_with_script_arguments:
        includes.update(['bindings/v8/ScriptCallStackFactory.h',
                         'core/inspector/ScriptArguments.h'])
    is_call_with_script_state = has_extended_attribute_value(method, 'CallWith', 'ScriptState')
    if is_call_with_script_state:
        includes.add('bindings/v8/ScriptState.h')
    is_check_security_for_node = 'CheckSecurity' in extended_attributes
    if is_check_security_for_node:
        includes.add('bindings/v8/BindingSecurity.h')
    is_custom_element_callbacks = 'CustomElementCallbacks' in extended_attributes
    if is_custom_element_callbacks:
        includes.add('core/dom/custom/CustomElementCallbackDispatcher.h')

    is_check_security_for_frame = (
        'CheckSecurity' in interface.extended_attributes and
        'DoNotCheckSecurity' not in extended_attributes)
    is_raises_exception = 'RaisesException' in extended_attributes

    return {
        'activity_logging_world_list': v8_utilities.activity_logging_world_list(method),  # [ActivityLogging]
        'arguments': [generate_argument(interface, method, argument, index)
                      for index, argument in enumerate(arguments)],
        'conditional_string': v8_utilities.conditional_string(method),
        'cpp_type': v8_types.cpp_type(idl_type),
        'cpp_value': this_cpp_value,
        'deprecate_as': v8_utilities.deprecate_as(method),  # [DeprecateAs]
        'do_not_check_signature': not(is_static or
            v8_utilities.has_extended_attribute(method,
                ['DoNotCheckSecurity', 'DoNotCheckSignature', 'NotEnumerable',
                 'ReadOnly', 'RuntimeEnabled', 'Unforgeable'])),
        'function_template': function_template(),
        'idl_type': idl_type,
        'has_exception_state':
            is_raises_exception or
            is_check_security_for_frame or
            any(argument for argument in arguments
                if argument.idl_type == 'SerializedScriptValue' or
                   v8_types.is_integer_type(argument.idl_type)) or
            name in ['addEventListener', 'removeEventListener'],
        'is_call_with_execution_context': has_extended_attribute_value(method, 'CallWith', 'ExecutionContext'),
        'is_call_with_script_arguments': is_call_with_script_arguments,
        'is_call_with_script_state': is_call_with_script_state,
        'is_check_security_for_frame': is_check_security_for_frame,
        'is_check_security_for_node': is_check_security_for_node,
        'is_custom': 'Custom' in extended_attributes,
        'is_custom_element_callbacks': is_custom_element_callbacks,
        'is_do_not_check_security': 'DoNotCheckSecurity' in extended_attributes,
        'is_do_not_check_signature': 'DoNotCheckSignature' in extended_attributes,
        'is_per_world_bindings': 'PerWorldBindings' in extended_attributes,
        'is_raises_exception': is_raises_exception,
        'is_read_only': 'ReadOnly' in extended_attributes,
        'is_static': is_static,
        'is_strict_type_checking':
            'StrictTypeChecking' in extended_attributes or
            'StrictTypeChecking' in interface.extended_attributes,
        'is_variadic': arguments and arguments[-1].is_variadic,
        'measure_as': v8_utilities.measure_as(method),  # [MeasureAs]
        'name': name,
        'number_of_arguments': len(arguments),
        'number_of_required_arguments': len([
            argument for argument in arguments
            if not (argument.is_optional or argument.is_variadic)]),
        'number_of_required_or_variadic_arguments': len([
            argument for argument in arguments
            if not argument.is_optional]),
        'per_context_enabled_function': v8_utilities.per_context_enabled_function_name(method),  # [PerContextEnabled]
        'property_attributes': property_attributes(method),
        'runtime_enabled_function': v8_utilities.runtime_enabled_function_name(method),  # [RuntimeEnabled]
        'signature': 'v8::Local<v8::Signature>()' if is_static or 'DoNotCheckSignature' in extended_attributes else 'defaultSignature',
        'union_arguments': union_arguments(idl_type),
        'v8_set_return_value_for_main_world': v8_set_return_value(interface.name, method, this_cpp_value, for_main_world=True),
        'v8_set_return_value': v8_set_return_value(interface.name, method, this_cpp_value),
        'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended_attributes else [''],  # [PerWorldBindings]
    }
def generate_method(interface, method):
    arguments = method.arguments
    extended_attributes = method.extended_attributes
    idl_type = method.idl_type
    is_static = method.is_static
    name = method.name

    this_cpp_value = cpp_value(interface, method, len(arguments))
    this_custom_signature = custom_signature(method, arguments)

    def function_template():
        # FIXME: Rename as follows (also in v8/V8DOMConfiguration):
        # desc => functionTemplate
        # instance => instanceTemplate
        # proto => prototypeTemplate
        if is_static:
            return 'desc'
        if 'Unforgeable' in extended_attributes:
            return 'instance'
        return 'proto'

    def signature():
        if this_custom_signature:
            return name + 'Signature'
        if is_static or 'DoNotCheckSignature' in extended_attributes:
            return 'v8::Local<v8::Signature>()'
        return 'defaultSignature'

    is_call_with_script_arguments = has_extended_attribute_value(method, 'CallWith', 'ScriptArguments')
    if is_call_with_script_arguments:
        includes.update(['bindings/v8/ScriptCallStackFactory.h',
                         'core/inspector/ScriptArguments.h'])
    is_call_with_script_state = has_extended_attribute_value(method, 'CallWith', 'ScriptState')
    if is_call_with_script_state:
        includes.add('bindings/v8/ScriptState.h')
    is_check_security_for_node = 'CheckSecurityForNode' in extended_attributes
    if is_check_security_for_node:
        includes.add('bindings/v8/BindingSecurity.h')
    is_custom_element_callbacks = 'CustomElementCallbacks' in extended_attributes
    if is_custom_element_callbacks:
        includes.add('core/dom/custom/CustomElementCallbackDispatcher.h')
    is_raises_exception = 'RaisesException' in extended_attributes
    if is_raises_exception:
        includes.update(['bindings/v8/ExceptionMessages.h',
                         'bindings/v8/ExceptionState.h'])

    contents = {
        'activity_logging_world_list': v8_utilities.activity_logging_world_list(method),  # [ActivityLogging]
        'arguments': [generate_argument(interface, method, argument, index)
                      for index, argument in enumerate(arguments)],
        'conditional_string': v8_utilities.conditional_string(method),
        'cpp_type': v8_types.cpp_type(idl_type),
        'cpp_value': this_cpp_value,
        'custom_signature': this_custom_signature,
        'deprecate_as': v8_utilities.deprecate_as(method),  # [DeprecateAs]
        'do_not_check_signature': not(this_custom_signature or is_static or
            v8_utilities.has_extended_attribute(method,
                ['DoNotCheckSignature', 'NotEnumerable', 'ReadOnly',
                 'RuntimeEnabled', 'Unforgeable'])),
        'function_template': function_template(),
        'idl_type': idl_type,
        'is_call_with_execution_context': has_extended_attribute_value(method, 'CallWith', 'ExecutionContext'),
        'is_call_with_script_arguments': is_call_with_script_arguments,
        'is_call_with_script_state': is_call_with_script_state,
        'is_check_security_for_node': is_check_security_for_node,
        'is_custom': 'Custom' in extended_attributes,
        'is_custom_element_callbacks': is_custom_element_callbacks,
        'is_per_world_bindings': 'PerWorldBindings' in extended_attributes,
        'is_raises_exception': is_raises_exception,
        'is_static': is_static,
        'measure_as': v8_utilities.measure_as(method),  # [MeasureAs]
        'name': name,
        'number_of_arguments': len(arguments),
        'number_of_required_arguments': len([
            argument for argument in arguments
            if not (argument.is_optional or argument.is_variadic)]),
        'number_of_required_or_variadic_arguments': len([
            argument for argument in arguments
            if not argument.is_optional]),
        'per_context_enabled_function_name': v8_utilities.per_context_enabled_function_name(method),  # [PerContextEnabled]
        'property_attributes': property_attributes(method),
        'runtime_enabled_function_name': v8_utilities.runtime_enabled_function_name(method),  # [RuntimeEnabled]
        'signature': signature(),
        'v8_set_return_value': v8_set_return_value(method, this_cpp_value),
        'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended_attributes else [''],  # [PerWorldBindings]
    }
    return contents
 def argument_declaration(argument):
     return '%s %s' % (cpp_type(argument.idl_type), argument.name)
Example #22
0
def generate_attribute(interface, attribute):
    idl_type = attribute.idl_type
    extended_attributes = attribute.extended_attributes

    has_custom_getter = has_extended_attribute(attribute,
                                               ('Custom', 'CustomGetter'))
    has_custom_setter = not attribute.is_read_only and has_extended_attribute(
        attribute, ('Custom', 'CustomSetter'))
    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.generate_conditional_string(attribute),
        'cpp_type':
        v8_types.cpp_type(idl_type),
        'getter_callback_name':
        getter_callback_name(interface, attribute),
        'getter_callback_name_for_main_world':
        getter_callback_name_for_main_world(interface, attribute),
        'has_custom_getter':
        has_custom_getter,
        'has_custom_setter':
        has_custom_setter,
        'idl_type':
        idl_type,
        'is_constructor':
        is_constructor_attribute(attribute),
        'is_getter_raises_exception':
        has_extended_attribute(attribute,
                               ('GetterRaisesException', 'RaisesException')),
        'is_keep_alive_for_gc':
        is_keep_alive_for_gc(attribute),
        'is_nullable':
        attribute.is_nullable,
        'is_read_only':
        attribute.is_read_only,
        'is_replaceable':
        'Replaceable' in attribute.extended_attributes,
        'is_setter_raises_exception':
        has_extended_attribute(attribute,
                               ('RaisesException', 'SetterRaisesException')),
        'is_static':
        attribute.is_static,
        'name':
        attribute.name,
        'per_context_enabled_function_name':
        v8_utilities.per_context_enabled_function_name(
            attribute),  # [PerContextEnabled]
        'property_attributes':
        property_attributes(attribute),
        'setter_callback_name':
        setter_callback_name(interface, attribute),
        'setter_callback_name_for_main_world':
        setter_callback_name_for_main_world(interface, attribute),
        'v8_type':
        v8_types.v8_type(idl_type),
        'runtime_enabled_function_name':
        v8_utilities.runtime_enabled_function_name(
            attribute),  # [RuntimeEnabled]
        'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings'
        in extended_attributes else [''],  # [PerWorldBindings]
        'wrapper_type_info':
        wrapper_type_info(attribute),
    }
    if is_constructor_attribute(attribute):
        includes.update(v8_types.includes_for_type(idl_type))
        return contents
    if not has_custom_getter:
        generate_getter(interface, attribute, contents)
    if not attribute.is_read_only and not has_custom_setter:
        generate_setter(interface, attribute, contents)

    return contents
 def argument_declaration(argument):
     return '%s %s' % (cpp_type(argument.idl_type), argument.name)