Index: bindings/scripts/v8_methods.py |
diff --git a/bindings/scripts/v8_methods.py b/bindings/scripts/v8_methods.py |
index d33071209161db46bf6a9494447b587eaeb2a8c8..7db6e4ea4c0a38b2448d9e86d7f9af7f0018d715 100644 |
--- a/bindings/scripts/v8_methods.py |
+++ b/bindings/scripts/v8_methods.py |
@@ -39,7 +39,8 @@ from idl_types import IdlTypeBase, IdlUnionType, inherits_interface |
from v8_globals import includes |
import v8_types |
import v8_utilities |
-from v8_utilities import has_extended_attribute_value |
+from v8_utilities import (has_extended_attribute_value, is_unforgeable, |
+ is_legacy_interface_type_checking) |
# Methods with any of these require custom method registration code in the |
@@ -62,20 +63,22 @@ def use_local_result(method): |
idl_type.is_explicit_nullable) |
-def method_context(interface, method): |
+def method_context(interface, method, is_visible=True): |
arguments = method.arguments |
extended_attributes = method.extended_attributes |
idl_type = method.idl_type |
is_static = method.is_static |
name = method.name |
- idl_type.add_includes_for_type() |
+ if is_visible: |
+ idl_type.add_includes_for_type(extended_attributes) |
+ |
this_cpp_value = cpp_value(interface, method, len(arguments)) |
def function_template(): |
if is_static: |
return 'functionTemplate' |
- if 'Unforgeable' in extended_attributes: |
+ if is_unforgeable(interface, method): |
return 'instanceTemplate' |
return 'prototypeTemplate' |
@@ -93,11 +96,12 @@ def method_context(interface, method): |
includes.update(['bindings/core/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/core/v8/V8ScriptState.h') |
+ 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('bindings/core/v8/ScriptState.h') |
is_check_security_for_node = 'CheckSecurity' in extended_attributes |
if is_check_security_for_node: |
- includes.add('bindings/common/BindingSecurity.h') |
+ includes.add('bindings/core/v8/BindingSecurity.h') |
is_custom_element_callbacks = 'CustomElementCallbacks' in extended_attributes |
if is_custom_element_callbacks: |
includes.add('core/dom/custom/CustomElementProcessingStack.h') |
@@ -113,10 +117,20 @@ def method_context(interface, method): |
not is_do_not_check_security) |
is_raises_exception = 'RaisesException' in extended_attributes |
+ is_custom_call_prologue = has_extended_attribute_value(method, 'Custom', 'CallPrologue') |
+ is_custom_call_epilogue = has_extended_attribute_value(method, 'Custom', 'CallEpilogue') |
+ is_post_message = 'PostMessage' in extended_attributes |
+ if is_post_message: |
+ includes.add('bindings/core/v8/SerializedScriptValueFactory.h') |
+ includes.add('core/dom/DOMArrayBuffer.h') |
+ includes.add('core/dom/MessagePort.h') |
+ |
+ if 'LenientThis' in extended_attributes: |
+ raise Exception('[LenientThis] is not supported for operations.') |
return { |
'activity_logging_world_list': v8_utilities.activity_logging_world_list(method), # [ActivityLogging] |
- 'arguments': [argument_context(interface, method, argument, index) |
+ 'arguments': [argument_context(interface, method, argument, index, is_visible=is_visible) |
for index, argument in enumerate(arguments)], |
'argument_declarations_for_private_script': |
argument_declarations_for_private_script(interface, method), |
@@ -131,7 +145,9 @@ def method_context(interface, method): |
'deprecate_as': v8_utilities.deprecate_as(method), # [DeprecateAs] |
'exposed_test': v8_utilities.exposed(method, interface), # [Exposed] |
'function_template': function_template(), |
- 'has_custom_registration': is_static or |
+ 'has_custom_registration': |
+ is_static or |
+ is_unforgeable(interface, method) or |
v8_utilities.has_extended_attribute( |
method, CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES), |
'has_exception_state': |
@@ -145,10 +161,14 @@ def method_context(interface, method): |
'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_call_with_this_value': is_call_with_this_value, |
'is_check_security_for_frame': is_check_security_for_frame, |
'is_check_security_for_node': is_check_security_for_node, |
'is_check_security_for_window': is_check_security_for_window, |
- 'is_custom': 'Custom' in extended_attributes, |
+ 'is_custom': 'Custom' in extended_attributes and |
+ not (is_custom_call_prologue or is_custom_call_epilogue), |
+ 'is_custom_call_prologue': is_custom_call_prologue, |
+ 'is_custom_call_epilogue': is_custom_call_epilogue, |
'is_custom_element_callbacks': is_custom_element_callbacks, |
'is_do_not_check_security': is_do_not_check_security, |
'is_do_not_check_signature': 'DoNotCheckSignature' in extended_attributes, |
@@ -157,11 +177,12 @@ def method_context(interface, method): |
'is_partial_interface_member': |
'PartialInterfaceImplementedAs' in extended_attributes, |
'is_per_world_bindings': 'PerWorldBindings' in extended_attributes, |
+ 'is_post_message': is_post_message, |
'is_raises_exception': is_raises_exception, |
- 'is_read_only': 'Unforgeable' in extended_attributes, |
+ 'is_read_only': is_unforgeable(interface, method), |
'is_static': is_static, |
'is_variadic': arguments and arguments[-1].is_variadic, |
- 'measure_as': v8_utilities.measure_as(method), # [MeasureAs] |
+ 'measure_as': v8_utilities.measure_as(method, interface), # [MeasureAs] |
'name': name, |
'number_of_arguments': len(arguments), |
'number_of_required_arguments': len([ |
@@ -170,72 +191,84 @@ def method_context(interface, method): |
'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), |
'only_exposed_to_private_script': is_only_exposed_to_private_script, |
- 'per_context_enabled_function': v8_utilities.per_context_enabled_function_name(method), # [PerContextEnabled] |
'private_script_v8_value_to_local_cpp_value': idl_type.v8_value_to_local_cpp_value( |
- extended_attributes, 'v8Value', 'cppValue', isolate='scriptState->isolate()', used_in_private_script=True), |
- 'property_attributes': property_attributes(method), |
+ extended_attributes, 'v8Value', 'cppValue', isolate='scriptState->isolate()', bailout_return_value='false'), |
+ 'property_attributes': property_attributes(interface, method), |
+ 'returns_promise': method.returns_promise, |
'runtime_enabled_function': v8_utilities.runtime_enabled_function_name(method), # [RuntimeEnabled] |
'should_be_exposed_to_script': not (is_implemented_in_private_script and is_only_exposed_to_private_script), |
'signature': 'v8::Local<v8::Signature>()' if is_static or 'DoNotCheckSignature' in extended_attributes else 'defaultSignature', |
- 'union_arguments': idl_type.union_arguments, |
+ '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], |
} |
-def argument_context(interface, method, argument, index): |
+def argument_context(interface, method, argument, index, is_visible=True): |
extended_attributes = argument.extended_attributes |
idl_type = argument.idl_type |
+ if is_visible: |
+ idl_type.add_includes_for_type(extended_attributes) |
this_cpp_value = cpp_value(interface, method, index) |
is_variadic_wrapper_type = argument.is_variadic and idl_type.is_wrapper_type |
+ # [TypeChecking=Interface] / [LegacyInterfaceTypeChecking] |
+ has_type_checking_interface = ( |
+ not is_legacy_interface_type_checking(interface, method) and |
+ idl_type.is_wrapper_type) |
+ |
if ('ImplementedInPrivateScript' in extended_attributes and |
not idl_type.is_wrapper_type and |
not idl_type.is_basic_type): |
raise Exception('Private scripts supports only primitive types and DOM wrappers.') |
- default_cpp_value = argument.default_cpp_value |
- return { |
- 'cpp_type': idl_type.cpp_type_args(extended_attributes=extended_attributes, |
+ set_default_value = argument.set_default_value |
+ this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attributes, |
raw_type=True, |
- used_as_variadic_argument=argument.is_variadic), |
+ used_as_variadic_argument=argument.is_variadic) |
+ return { |
+ 'cpp_type': ( |
+ v8_types.cpp_template_type('Nullable', this_cpp_type) |
+ if idl_type.is_explicit_nullable and not argument.is_variadic |
+ else this_cpp_type), |
'cpp_value': this_cpp_value, |
# FIXME: check that the default value's type is compatible with the argument's |
- 'default_value': default_cpp_value, |
- 'enum_validation_expression': idl_type.enum_validation_expression, |
+ 'set_default_value': set_default_value, |
+ 'enum_type': idl_type.enum_type, |
+ 'enum_values': idl_type.enum_values, |
'handle': '%sHandle' % argument.name, |
# FIXME: remove once [Default] removed and just use argument.default_value |
- 'has_default': 'Default' in extended_attributes or default_cpp_value, |
- 'has_type_checking_interface': |
- (has_extended_attribute_value(interface, 'TypeChecking', 'Interface') or |
- has_extended_attribute_value(method, 'TypeChecking', 'Interface')) and |
- idl_type.is_wrapper_type, |
- 'has_type_checking_unrestricted': |
- (has_extended_attribute_value(interface, 'TypeChecking', 'Unrestricted') or |
- has_extended_attribute_value(method, 'TypeChecking', 'Unrestricted')) and |
- idl_type.name in ('Float', 'Double'), |
+ 'has_default': 'Default' in extended_attributes or set_default_value, |
+ 'has_type_checking_interface': has_type_checking_interface, |
# Dictionary is special-cased, but arrays and sequences shouldn't be |
'idl_type': idl_type.base_type, |
'idl_type_object': idl_type, |
'index': index, |
+ 'is_callback_function': idl_type.is_callback_function, |
'is_callback_interface': idl_type.is_callback_interface, |
# FIXME: Remove generic 'Dictionary' special-casing |
'is_dictionary': idl_type.is_dictionary or idl_type.base_type == 'Dictionary', |
+ 'is_explicit_nullable': idl_type.is_explicit_nullable, |
'is_nullable': idl_type.is_nullable, |
'is_optional': argument.is_optional, |
+ 'is_variadic': argument.is_variadic, |
'is_variadic_wrapper_type': is_variadic_wrapper_type, |
'is_wrapper_type': idl_type.is_wrapper_type, |
'name': argument.name, |
'private_script_cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( |
argument.name, isolate='scriptState->isolate()', |
creation_context='scriptState->context()->Global()'), |
+ 'use_permissive_dictionary_conversion': 'PermissiveDictionaryConversion' in extended_attributes, |
'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), |
- 'v8_value_to_local_cpp_value': v8_value_to_local_cpp_value(argument, index, return_promise=method.returns_promise), |
- 'vector_type': v8_types.cpp_ptr_type('Vector', 'HeapVector', idl_type.gc_type), |
+ 'v8_value_to_local_cpp_value': v8_value_to_local_cpp_value(method, argument, index), |
} |
@@ -258,8 +291,6 @@ def cpp_value(interface, method, number_of_arguments): |
idl_type = argument.idl_type |
if idl_type.name == 'EventListener': |
return argument.name |
- if idl_type.is_dictionary: |
- return '*%s' % argument.name |
if (idl_type.name in ['NodeFilter', 'NodeFilterOrNull', |
'XPathNSResolver', 'XPathNSResolverOrNull']): |
# FIXME: remove this special case |
@@ -270,7 +301,7 @@ def cpp_value(interface, method, number_of_arguments): |
arguments = method.arguments[:number_of_arguments] |
cpp_arguments = [] |
if 'ImplementedInPrivateScript' in method.extended_attributes: |
- cpp_arguments.append('toFrameIfNotDetached(info.GetIsolate()->GetCurrentContext())') |
+ cpp_arguments.append('toLocalFrame(toFrameIfNotDetached(info.GetIsolate()->GetCurrentContext()))') |
cpp_arguments.append('impl') |
if method.is_constructor: |
@@ -288,11 +319,6 @@ def cpp_value(interface, method, number_of_arguments): |
cpp_arguments.append('*impl') |
cpp_arguments.extend(cpp_argument(argument) for argument in arguments) |
- this_union_arguments = method.idl_type and method.idl_type.union_arguments |
- if this_union_arguments: |
- cpp_arguments.extend([member_argument['cpp_value'] |
- for member_argument in this_union_arguments]) |
- |
if 'ImplementedInPrivateScript' in method.extended_attributes: |
if method.idl_type.name != 'void': |
cpp_arguments.append('&result') |
@@ -301,6 +327,12 @@ def cpp_value(interface, method, number_of_arguments): |
has_extended_attribute_value(interface, 'RaisesException', 'Constructor'))): |
cpp_arguments.append('exceptionState') |
+ # If a method returns an IDL dictionary or union type, the return value is |
+ # passed as an argument to impl classes. |
+ idl_type = method.idl_type |
+ if idl_type and idl_type.use_output_parameter_for_result: |
+ cpp_arguments.append('result') |
+ |
if method.name == 'Constructor': |
base_name = 'create' |
elif method.name == 'NamedConstructor': |
@@ -337,39 +369,43 @@ def v8_set_return_value(interface_name, method, cpp_value, for_main_world=False) |
release = idl_type.release |
script_wrappable = 'impl' if inherits_interface(interface_name, 'Node') else '' |
- return idl_type.v8_set_return_value(cpp_value, extended_attributes, script_wrappable=script_wrappable, release=release, for_main_world=for_main_world) |
+ return idl_type.v8_set_return_value(cpp_value, extended_attributes, script_wrappable=script_wrappable, release=release, for_main_world=for_main_world, is_static=method.is_static) |
-def v8_value_to_local_cpp_variadic_value(argument, index, return_promise): |
+def v8_value_to_local_cpp_variadic_value(method, argument, index, return_promise): |
assert argument.is_variadic |
idl_type = argument.idl_type |
+ this_cpp_type = idl_type.cpp_type |
- suffix = '' |
- |
- macro = 'TONATIVE_VOID_EXCEPTIONSTATE' |
- macro_args = [ |
- argument.name, |
- 'toImplArguments<%s>(info, %s, exceptionState)' % (idl_type.cpp_type, index), |
- 'exceptionState', |
- ] |
- |
- if return_promise: |
- suffix += '_PROMISE' |
- macro_args.extend(['info', 'V8ScriptState::current(info.GetIsolate())']) |
+ if method.returns_promise: |
+ check_expression = 'exceptionState.hadException()' |
+ else: |
+ check_expression = 'exceptionState.throwIfNeeded()' |
- suffix += '_INTERNAL' |
+ if idl_type.is_dictionary or idl_type.is_union_type: |
+ vector_type = 'HeapVector' |
+ else: |
+ vector_type = 'Vector' |
- return '%s%s(%s)' % (macro, suffix, ', '.join(macro_args)) |
+ return { |
+ 'assign_expression': 'toImplArguments<%s<%s>>(info, %s, exceptionState)' % (vector_type, this_cpp_type, index), |
+ 'check_expression': check_expression, |
+ 'cpp_type': this_cpp_type, |
+ 'cpp_name': argument.name, |
+ 'declare_variable': False, |
+ } |
-def v8_value_to_local_cpp_value(argument, index, return_promise=False): |
+def v8_value_to_local_cpp_value(method, argument, index, return_promise=False, restricted_float=False): |
extended_attributes = argument.extended_attributes |
idl_type = argument.idl_type |
name = argument.name |
if argument.is_variadic: |
- return v8_value_to_local_cpp_variadic_value(argument, index, return_promise) |
+ return v8_value_to_local_cpp_variadic_value(method, argument, index, return_promise) |
return idl_type.v8_value_to_local_cpp_value(extended_attributes, 'info[%s]' % index, |
- name, index=index, declare_variable=False, return_promise=return_promise) |
+ name, index=index, declare_variable=False, |
+ use_exception_state=method.returns_promise, |
+ restricted_float=restricted_float) |
################################################################################ |
@@ -377,63 +413,61 @@ def v8_value_to_local_cpp_value(argument, index, return_promise=False): |
################################################################################ |
# [NotEnumerable] |
-def property_attributes(method): |
+def property_attributes(interface, method): |
extended_attributes = method.extended_attributes |
property_attributes_list = [] |
if 'NotEnumerable' in extended_attributes: |
property_attributes_list.append('v8::DontEnum') |
- if 'Unforgeable' in extended_attributes: |
+ if is_unforgeable(interface, method): |
property_attributes_list.append('v8::ReadOnly') |
if property_attributes_list: |
property_attributes_list.insert(0, 'v8::DontDelete') |
return property_attributes_list |
-def union_member_argument_context(idl_type, index): |
- """Returns a context of union member for argument.""" |
- this_cpp_value = 'result%d' % index |
- this_cpp_type = idl_type.cpp_type |
- this_cpp_type_initializer = idl_type.cpp_type_initializer |
- cpp_return_value = this_cpp_value |
- |
- if not idl_type.cpp_type_has_null_value: |
- this_cpp_type = v8_types.cpp_template_type('Nullable', this_cpp_type) |
- this_cpp_type_initializer = '' |
- cpp_return_value = '%s.get()' % this_cpp_value |
- |
- if idl_type.is_string_type: |
- null_check_value = '!%s.isNull()' % this_cpp_value |
- else: |
- null_check_value = this_cpp_value |
- |
- return { |
- 'cpp_type': this_cpp_type, |
- 'cpp_type_initializer': this_cpp_type_initializer, |
- 'cpp_value': this_cpp_value, |
- 'null_check_value': null_check_value, |
- 'v8_set_return_value': idl_type.v8_set_return_value( |
- cpp_value=cpp_return_value, |
- release=idl_type.release), |
- } |
- |
- |
-def union_arguments(idl_type): |
- return [union_member_argument_context(member_idl_type, index) |
- for index, member_idl_type |
- in enumerate(idl_type.member_types)] |
- |
- |
-def argument_default_cpp_value(argument): |
- if argument.idl_type.is_dictionary: |
- # We always create impl objects for IDL dictionaries. |
- return '%s::create()' % argument.idl_type.base_type |
- if not argument.default_value: |
+def argument_set_default_value(argument): |
+ idl_type = argument.idl_type |
+ default_value = argument.default_value |
+ if not default_value: |
return None |
- return argument.idl_type.literal_cpp_value(argument.default_value) |
+ if idl_type.is_dictionary: |
+ if not argument.default_value.is_null: |
+ raise Exception('invalid default value for dictionary type') |
+ return None |
+ if idl_type.is_array_or_sequence_type: |
+ if default_value.value != '[]': |
+ raise Exception('invalid default value for sequence type: %s' % default_value.value) |
+ # Nothing to do when we set an empty sequence as default value, but we |
+ # need to return non-empty value so that we don't generate method calls |
+ # without this argument. |
+ return '/* Nothing to do */' |
+ if idl_type.is_union_type: |
+ if argument.default_value.is_null: |
+ if not idl_type.includes_nullable_type: |
+ raise Exception('invalid default value for union type: null for %s' |
+ % idl_type.name) |
+ # Union container objects are "null" initially. |
+ return '/* null default value */' |
+ if isinstance(default_value.value, basestring): |
+ member_type = idl_type.string_member_type |
+ elif isinstance(default_value.value, (int, float)): |
+ member_type = idl_type.numeric_member_type |
+ elif isinstance(default_value.value, bool): |
+ member_type = idl_type.boolean_member_type |
+ else: |
+ member_type = None |
+ if member_type is None: |
+ raise Exception('invalid default value for union type: %r for %s' |
+ % (default_value.value, idl_type.name)) |
+ member_type_name = (member_type.inner_type.name |
+ if member_type.is_nullable else |
+ member_type.name) |
+ return '%s.set%s(%s)' % (argument.name, member_type_name, |
+ member_type.literal_cpp_value(default_value)) |
+ return '%s = %s' % (argument.name, |
+ idl_type.literal_cpp_value(default_value)) |
-IdlTypeBase.union_arguments = None |
-IdlUnionType.union_arguments = property(union_arguments) |
-IdlArgument.default_cpp_value = property(argument_default_cpp_value) |
+IdlArgument.set_default_value = property(argument_set_default_value) |
def method_returns_promise(method): |
@@ -446,5 +480,4 @@ def argument_conversion_needs_exception_state(method, argument): |
idl_type = argument.idl_type |
return (idl_type.v8_conversion_needs_exception_state or |
argument.is_variadic or |
- (method.returns_promise and (idl_type.is_string_type or |
- idl_type.is_enum))) |
+ (method.returns_promise and idl_type.is_string_type)) |