Example #1
0
def generate_constructor(interface, constructor):
    return {
        'argument_list': constructor_argument_list(interface, constructor),
        'arguments': [constructor_argument(argument, index)
                      for index, argument in enumerate(constructor.arguments)],
        'has_exception_state':
            # [RaisesException=Constructor]
            interface.extended_attributes.get('RaisesException') == 'Constructor' or
            any(argument for argument in constructor.arguments
                if argument.idl_type == 'SerializedScriptValue' or
                   v8_types.is_integer_type(argument.idl_type)),
        'is_constructor': True,
        'is_variadic': False,  # Required for overload resolution
        'number_of_required_arguments':
            number_of_required_arguments(constructor),
    }
Example #2
0
def property_setter(setter):
    idl_type = setter.arguments[1].idl_type
    extended_attributes = setter.extended_attributes
    is_raises_exception = 'RaisesException' in extended_attributes
    return {
        'has_strict_type_checking':
            'StrictTypeChecking' in extended_attributes and
            v8_types.is_wrapper_type(idl_type),
        'idl_type': idl_type,
        'is_custom': 'Custom' in extended_attributes,
        'has_exception_state': is_raises_exception or
                               v8_types.is_integer_type(idl_type),
        'is_raises_exception': is_raises_exception,
        'name': cpp_name(setter),
        'v8_value_to_local_cpp_value': v8_types.v8_value_to_local_cpp_value(
            idl_type, extended_attributes, 'jsValue', 'propertyValue'),
    }
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'])
    # [CustomElementCallbacks], [Reflect]
    is_custom_element_callbacks = 'CustomElementCallbacks' in extended_attributes
    is_reflect = 'Reflect' in extended_attributes
    if is_custom_element_callbacks or is_reflect:
        includes.add('core/dom/custom/CustomElementCallbackDispatcher.h')
    # [RaisesException], [RaisesException=Setter]
    is_setter_raises_exception = (
        'RaisesException' in extended_attributes and
        extended_attributes['RaisesException'] in [None, 'Setter'])
    # [StrictTypeChecking]
    has_strict_type_checking = (
        ('StrictTypeChecking' in extended_attributes or
         'StrictTypeChecking' in interface.extended_attributes) and
        v8_types.is_wrapper_type(idl_type))

    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': has_strict_type_checking,
        '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_custom_element_callbacks': is_custom_element_callbacks,
        '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(interface, 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_call_with_execution_context': v8_utilities.has_extended_attribute_value(attribute, 'SetterCallWith', 'ExecutionContext'),
        'is_setter_raises_exception': is_setter_raises_exception,
        'has_setter_exception_state': (
            is_setter_raises_exception or has_strict_type_checking or
            v8_types.is_integer_type(idl_type)),
        'is_static': attribute.is_static,
        'is_url': 'URL' in extended_attributes,
        '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),
        'put_forwards': 'PutForwards' in extended_attributes,
        'reflect_empty': extended_attributes.get('ReflectEmpty'),
        'reflect_invalid': extended_attributes.get('ReflectInvalid', ''),
        'reflect_missing': extended_attributes.get('ReflectMissing'),
        'reflect_only': extended_attributes['ReflectOnly'].split('|')
            if 'ReflectOnly' in extended_attributes else None,
        '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 has_custom_setter and
        (not attribute.is_read_only or 'PutForwards' in extended_attributes)):
        generate_setter(interface, attribute, contents)

    return contents
Example #4
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]
    }
Example #5
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'])
    # [CustomElementCallbacks], [Reflect]
    is_custom_element_callbacks = 'CustomElementCallbacks' in extended_attributes
    is_reflect = 'Reflect' in extended_attributes
    if is_custom_element_callbacks or is_reflect:
        includes.add('core/dom/custom/CustomElementCallbackDispatcher.h')
    # [RaisesException], [RaisesException=Setter]
    is_setter_raises_exception = ('RaisesException' in extended_attributes
                                  and extended_attributes['RaisesException']
                                  in [None, 'Setter'])
    # [StrictTypeChecking]
    has_strict_type_checking = (
        ('StrictTypeChecking' in extended_attributes
         or 'StrictTypeChecking' in interface.extended_attributes)
        and v8_types.is_wrapper_type(idl_type))

    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':
        has_strict_type_checking,
        '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_custom_element_callbacks':
        is_custom_element_callbacks,
        '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(interface, 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_call_with_execution_context':
        v8_utilities.has_extended_attribute_value(attribute, 'SetterCallWith',
                                                  'ExecutionContext'),
        'is_setter_raises_exception':
        is_setter_raises_exception,
        'has_setter_exception_state':
        (is_setter_raises_exception or has_strict_type_checking
         or v8_types.is_integer_type(idl_type)),
        'is_static':
        attribute.is_static,
        'is_url':
        'URL' in extended_attributes,
        '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),
        'put_forwards':
        'PutForwards' in extended_attributes,
        'reflect_empty':
        extended_attributes.get('ReflectEmpty'),
        'reflect_invalid':
        extended_attributes.get('ReflectInvalid', ''),
        'reflect_missing':
        extended_attributes.get('ReflectMissing'),
        'reflect_only':
        extended_attributes['ReflectOnly'].split('|')
        if 'ReflectOnly' in extended_attributes else None,
        '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 has_custom_setter and
        (not attribute.is_read_only or 'PutForwards' in extended_attributes)):
        generate_setter(interface, attribute, contents)

    return contents
Example #6
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', 'dispatchEvent'],
        '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]
    }