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

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

Issue 466323002: IDL: Use Nullable for union type return value (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 4 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 | « Source/bindings/scripts/v8_interface.py ('k') | Source/bindings/scripts/v8_types.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/scripts/v8_methods.py
diff --git a/Source/bindings/scripts/v8_methods.py b/Source/bindings/scripts/v8_methods.py
index c69fcd1f3bec6af9e2d387395ce9e368fa0ed1a7..2dff48b00498b23a56ce8dc294288474bfa05903 100644
--- a/Source/bindings/scripts/v8_methods.py
+++ b/Source/bindings/scripts/v8_methods.py
@@ -304,7 +304,8 @@ def cpp_value(interface, method, 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)
+ 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':
@@ -401,11 +402,35 @@ def property_attributes(method):
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
+ 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)
+ 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_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 list of ['result0Enabled', 'result0', 'result1Enabled', ...] for union types, for use in setting return value"""
- return [arg
- for i in range(len(idl_type.member_types))
- for arg in ['result%sEnabled' % i, 'result%s' % i]]
+ 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):
« no previous file with comments | « Source/bindings/scripts/v8_interface.py ('k') | Source/bindings/scripts/v8_types.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698