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

Unified Diff: Source/bindings/scripts/unstable/v8_interface.py

Issue 153743002: IDL (Python): allow optional values to be undefined in overload resolution (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/scripts/unstable/v8_interface.py
diff --git a/Source/bindings/scripts/unstable/v8_interface.py b/Source/bindings/scripts/unstable/v8_interface.py
index 7f86f646fc402e0074e2e6c68b50bdf143015fdf..799796cddfd86a549ba4b9838649d46dc2855c10 100644
--- a/Source/bindings/scripts/unstable/v8_interface.py
+++ b/Source/bindings/scripts/unstable/v8_interface.py
@@ -373,6 +373,17 @@ def overload_check_expression(method, argument_count):
def overload_check_argument(index, argument):
+ def null_or_optional_check():
+ # If undefined is passed for an optional argument, the argument should
+ # be treated as missing; otherwise undefined is not allowed.
+ if argument['is_nullable']:
+ if argument['is_optional']:
+ return 'isUndefinedOrNull(%s)'
+ return '%s->IsNull()'
+ if argument['is_optional']:
+ return '%s->IsUndefined()'
+ return None
+
cpp_value = 'info[%s]' % index
idl_type = argument['idl_type']
# FIXME: proper type checking, sharing code with attributes and methods
@@ -392,9 +403,14 @@ def overload_check_argument(index, argument):
return type_check
if is_interface_type(idl_type):
# Non-wrapper types are just objects: we don't distinguish type
+ # We only allow undefined for non-wrapper types (notably Dictionary),
+ # as we need it for optional Dictionary arguments, but we don't want to
+ # change behavior of existing bindings for other types.
type_check = '%s->IsObject()' % cpp_value
- if argument['is_nullable']:
- type_check = ' || '.join(['%s->IsNull()' % cpp_value, type_check])
+ added_check_template = null_or_optional_check()
+ if added_check_template:
+ type_check = ' || '.join([added_check_template % cpp_value,
+ type_check])
return type_check
return None
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698