Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(362)

Unified Diff: Source/bindings/scripts/v8_methods.py

Issue 337343002: IDL: make optional arguments (without default) explicit sometimes Base URL: https://chromium.googlesource.com/chromium/blink.git@idl-default-arguments-next
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/bindings/scripts/v8_methods.py
diff --git a/Source/bindings/scripts/v8_methods.py b/Source/bindings/scripts/v8_methods.py
index 6f8378d24fd8ec381513a5af52b3d70b4707b6e9..4b79eb64dd696aa2cec205e46b5f2d2f1defa2d6 100644
--- a/Source/bindings/scripts/v8_methods.py
+++ b/Source/bindings/scripts/v8_methods.py
@@ -67,6 +67,21 @@ def argument_needs_try_catch(argument):
(base_type == 'DOMString' and not argument.is_variadic))
+def argument_is_explicit_optional(method, index):
+ argument = method.arguments[index]
+ if not(argument.is_optional and
+ not argument.default_value and
+ not 'Default' in argument.extended_attributes):
+ # Argument itself is not optional, or has a default value.
+ return False
+ for following in method.arguments[index + 1:]:
+ if (following.default_value or
+ 'Default' in following.extended_attributes):
+ # A following argument has a default value.
+ return True
+ return False
+
+
def generate_method(interface, method):
arguments = method.arguments
extended_attributes = method.extended_attributes
@@ -203,6 +218,7 @@ def generate_argument(interface, method, argument, index):
'index': index,
'is_clamp': 'Clamp' in extended_attributes,
'is_callback_interface': idl_type.is_callback_interface,
+ 'is_explicit_optional': argument_is_explicit_optional(method, index),
'is_nullable': idl_type.is_nullable,
'is_optional': argument.is_optional,
'is_variadic_wrapper_type': is_variadic_wrapper_type,
@@ -220,7 +236,8 @@ def generate_argument(interface, method, argument, index):
################################################################################
def cpp_value(interface, method, number_of_arguments):
- def cpp_argument(argument):
+ def cpp_argument(index):
+ argument = method.arguments[index]
idl_type = argument.idl_type
if idl_type.name == 'EventListener':
if (interface.name == 'EventTarget' and
@@ -233,10 +250,11 @@ def cpp_value(interface, method, number_of_arguments):
idl_type.name in ['NodeFilter', 'XPathNSResolver']):
# FIXME: remove this special case
return '%s.release()' % argument.name
+ if argument_is_explicit_optional(method, index):
+ return 'makeOptional({name}, {name}Missing)'.format(
+ name=argument.name)
return argument.name
- # Truncate omitted optional arguments
- arguments = method.arguments[:number_of_arguments]
cpp_arguments = v8_utilities.call_with_arguments(method)
# Members of IDL partial interface definitions are implemented in C++ as
# static member functions, which for instance members (non-static members)
@@ -244,7 +262,8 @@ def cpp_value(interface, method, number_of_arguments):
if ('PartialInterfaceImplementedAs' in method.extended_attributes and
not method.is_static):
cpp_arguments.append('*impl')
- cpp_arguments.extend(cpp_argument(argument) for argument in arguments)
+ cpp_arguments.extend(cpp_argument(index)
+ for index in range(number_of_arguments))
this_union_arguments = method.idl_type and method.idl_type.union_arguments
if this_union_arguments:
cpp_arguments.extend(this_union_arguments)
« no previous file with comments | « no previous file | Source/bindings/templates/methods.cpp » ('j') | Source/bindings/tests/results/V8TestInterfaceConstructor.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698