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

Unified Diff: lib/dom/scripts/generator.py

Issue 10827428: Dispatch with conversion hooks (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 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 | « no previous file | lib/dom/scripts/systemhtml.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/dom/scripts/generator.py
diff --git a/lib/dom/scripts/generator.py b/lib/dom/scripts/generator.py
index 04b88a7181dbac9195847b8381051d33049dcdd4..522c54080ec64953c0da460eb1f2aadbc8e255ca 100644
--- a/lib/dom/scripts/generator.py
+++ b/lib/dom/scripts/generator.py
@@ -169,6 +169,9 @@ class ParamInfo(object):
self.dart_type = dart_type
self.is_optional = is_optional
+ def Copy(self):
+ return ParamInfo(self.name, self.type_id, self.dart_type, self.is_optional)
+
def __repr__(self):
content = 'name = %s, type_id = %s, dart_type = %s, is_optional = %s' % (
self.name, self.type_id, self.dart_type, self.is_optional)
@@ -413,6 +416,15 @@ class OperationInfo(object):
else:
return self.type_name
+ def CopyAndWidenDefaultParameters(self):
+ """Returns equivalent OperationInfo, but default parameters are Dynamic."""
+ info = copy.copy(self)
+ info.param_infos = [param.Copy() for param in self.param_infos]
+ for param in info.param_infos:
+ if param.is_optional:
+ param.dart_type = 'Dynamic'
+ return info
+
def ConstantOutputOrder(a, b):
"""Canonical output ordering for constants."""
@@ -449,6 +461,61 @@ def TypeName(type_ids, interface):
# ------------------------------------------------------------------------------
+class Conversion(object):
+ """Represents a way of converting between types."""
+ def __init__(self, name, input_type, output_type):
+ # input_type is the type of the API input (and the argument type of the
+ # conversion function)
+ # output_type is the type of the API output (and the result type of the
+ # conversion function)
+ self.function_name = name
+ self.input_type = input_type
+ self.output_type = output_type
+
+# TYPE -> "DIRECTION INTERFACE.MEMBER" -> conversion
+# TYPE -> "DIRECTION INTERFACE.*" -> conversion
+# TYPE -> "DIRECTION" -> conversion
+#
+# where DIRECTION is 'get' for getters and operation return values, 'set' for
+# setters and operation arguments. INTERFACE and MEMBER are the idl names.
+#
+dart2js_conversions = {
+ 'IDBKey': {
+ 'get':
+ Conversion('_convertNativeToDart_IDBKey', 'Dynamic', 'Dynamic'),
+ 'set':
+ Conversion('_convertDartToNative_IDBKey', 'Dynamic', 'Dynamic'),
+ },
+ 'ImageData': {
+ 'get':
+ Conversion('_convertNativeToDart_ImageData', 'Dynamic', 'ImageData'),
+ 'set':
+ Conversion('_convertDartToNative_ImageData', 'ImageData', 'Dynamic')
+ },
+ 'Dictionary': {
+ 'get':
+ Conversion('_convertNativeToDart_Dictionary', 'Dynamic', 'Map'),
+ 'set':
+ Conversion('_convertDartToNative_Dictionary', 'Map', 'Dynamic'),
+ },
+
+ 'DOMString[]': {
+ 'set':
+ Conversion(
+ '_convertDartToNative_StringArray', 'List<String>', 'List'),
+ },
+}
+
+def FindConversion(idl_type, direction, interface, member):
+ table = dart2js_conversions.get(idl_type)
+ if table:
+ return (table.get('%s %s.%s' % (direction, interface, member)) or
+ table.get('%s %s.*' % (direction, interface)) or
+ table.get(direction))
+ return None
+
+# ------------------------------------------------------------------------------
+
class IDLTypeInfo(object):
def __init__(self, idl_type, data):
self._idl_type = idl_type
« no previous file with comments | « no previous file | lib/dom/scripts/systemhtml.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698