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():
'DoNotCheckSecurity' not in extended_attributes)
is_raises_exception = 'RaisesException' in extended_attributes
- contents = {
+ 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)],
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'],
+ 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_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,
'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]
}
- return contents
def generate_argument(interface, method, argument, index):
'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),
}
+################################################################################
+# Value handling
+################################################################################
+
def cpp_value(interface, method, number_of_arguments):
def cpp_argument(argument):
idl_type = argument.idl_type
not method.is_static):
cpp_arguments.append('imp')
cpp_arguments.extend(cpp_argument(argument) for argument in arguments)
+ this_union_arguments = union_arguments(method.idl_type)
+ if this_union_arguments:
+ cpp_arguments.extend(this_union_arguments)
+
if 'RaisesException' in method.extended_attributes:
cpp_arguments.append('exceptionState')
return '%s(%s)' % (cpp_method_name, ', '.join(cpp_arguments))
-def v8_set_return_value(interface_name, method, cpp_value):
+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):
+ 'RaisesException' in extended_attributes or
+ is_union_type):
# 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)
+ 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)
-# [NotEnumerable]
-def property_attributes(method):
- extended_attributes = method.extended_attributes
- property_attributes_list = []
- if 'NotEnumerable' in extended_attributes:
- property_attributes_list.append('v8::DontEnum')
- if 'ReadOnly' in extended_attributes:
- property_attributes_list.append('v8::ReadOnly')
- if property_attributes_list:
- property_attributes_list.insert(0, 'v8::DontDelete')
- return property_attributes_list
+ 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)
def v8_value_to_local_cpp_value(argument, index):
v8_value = 'info[%s]' % index
return v8_types.v8_value_to_local_cpp_value(
idl_type, argument.extended_attributes, v8_value, name, index=index)
+
+
+################################################################################
+# Auxiliary functions
+################################################################################
+
+# [NotEnumerable]
+def property_attributes(method):
+ extended_attributes = method.extended_attributes
+ property_attributes_list = []
+ if 'NotEnumerable' in extended_attributes:
+ property_attributes_list.append('v8::DontEnum')
+ if 'ReadOnly' in extended_attributes:
+ property_attributes_list.append('v8::ReadOnly')
+ if property_attributes_list:
+ property_attributes_list.insert(0, 'v8::DontDelete')
+ return property_attributes_list
+
+
+def union_arguments(idl_type):
+ """Return list of ['result0Enabled', 'result0', 'result1Enabled', ...] for union types, for use in setting return value"""
+ if not v8_types.is_union_type(idl_type):
+ return None
+ return [arg
+ for i in range(len(idl_type.union_member_types))
+ for arg in ['result%sEnabled' % i, 'result%s' % i]]