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

Unified Diff: tools/json_schema_compiler/dart_generator.py

Issue 12315074: Fix problem with non void return types in extension API IDL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Have another go Created 7 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 | tools/json_schema_compiler/idl_schema.py » ('j') | tools/json_schema_compiler/idl_schema.py » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/json_schema_compiler/dart_generator.py
diff --git a/tools/json_schema_compiler/dart_generator.py b/tools/json_schema_compiler/dart_generator.py
index 66db1357ee60518e5d4a63ff3db505cc25109dae..d40cc7329ceb5c5378089ef1cd74011d90c61bea 100644
--- a/tools/json_schema_compiler/dart_generator.py
+++ b/tools/json_schema_compiler/dart_generator.py
@@ -224,8 +224,13 @@ class _Generator(object):
)
elif self._IsObjectType(prop.type_):
# TODO(sashab): Think of a way to serialize generic Dart objects.
- c.Append("%s get %s => JS('%s', '#.%s', this._jsObject);" %
- (type_name, prop.name, type_name, prop.name))
+ if type_name in self._types:
+ c.Append("%s get %s => new %s._proxy(JS('%s', '#.%s', "
+ "this._jsObject));" %
+ (type_name, prop.name, type_name, type_name, prop.name))
+ else:
+ c.Append("%s get %s => JS('%s', '#.%s', this._jsObject);" %
+ (type_name, prop.name, type_name, prop.name))
else:
raise Exception(
"Could not generate wrapper for %s.%s: unserializable type %s" %
@@ -373,9 +378,18 @@ class _Generator(object):
if function.callback:
n_params += 1
- params = ["'%s'" % self._GetDartType(function.returns),
- "'#.%s(%s)'" % (function.name, ', '.join(['#'] * n_params)),
- call_target]
+ return_type_str = self._GetDartType(function.returns)
+ params = []
+
+ # If this object is serializable, don't convert the type from JS - pass the
+ # JS object straight into the proxy.
+ if self._IsSerializableObjectType(function.returns):
+ params.append("''")
+ else:
+ params.append("'%s'" % return_type_str)
+
+ params.append("'#.%s(%s)'" % (function.name, ', '.join(['#'] * n_params)))
+ params.append(call_target)
for param in function.params:
if not self._IsBaseType(param.type_):
@@ -390,7 +404,12 @@ class _Generator(object):
params.append('convertDartClosureToJS(%s, %s)' % (callback_name,
len(function.callback.params)))
- return 'JS(%s)' % ', '.join(params)
+ # If the object is serializable, call the proxy constructor for this type.
+ proxy_call = 'JS(%s)' % ', '.join(params)
+ if self._IsSerializableObjectType(function.returns):
+ proxy_call = 'new %s._proxy(%s)' % (return_type_str, proxy_call)
+
+ return proxy_call
def _GenerateEvent(self, event):
"""Given a Function object, returns the Code with the .dart for this event,
@@ -609,7 +628,7 @@ class _Generator(object):
def _AddPrefix(self, name):
"""Given the name of a type, prefixes the namespace (as camelcase) and
- return the new name.
+ returns the new name.
"""
# TODO(sashab): Split the dart library into multiple files, avoiding the
# need for this prefixing.
@@ -629,6 +648,8 @@ class _Generator(object):
If this object is a reference to something not in this namespace, assumes
its a serializable object.
"""
+ if type_ is None:
+ return False
if type_.property_type is PropertyType.CHOICES:
return all(self._IsSerializableObjectType(c) for c in type_.choices)
if type_.property_type is PropertyType.REF:
« no previous file with comments | « no previous file | tools/json_schema_compiler/idl_schema.py » ('j') | tools/json_schema_compiler/idl_schema.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698