Index: tool/input_sdk/private/ddc_runtime/classes.dart |
diff --git a/tool/input_sdk/private/ddc_runtime/classes.dart b/tool/input_sdk/private/ddc_runtime/classes.dart |
index f6cb1af603420b0268f107db6021f6bda12df2ce..637a2302ff1b01a491f038a6b79fb87e2f59dafe 100644 |
--- a/tool/input_sdk/private/ddc_runtime/classes.dart |
+++ b/tool/input_sdk/private/ddc_runtime/classes.dart |
@@ -75,6 +75,24 @@ final _typeArguments = JS('', 'Symbol("typeArguments")'); |
final _originalDeclaration = JS('', 'Symbol("originalDeclaration")'); |
+/// Wrap a generic class builder function with future flattening. |
+flattenFutures(builder) => JS('', '''(() => { |
+ function flatten(T) { |
+ if (!T) return $builder($dynamic); |
+ let futureClass = $getGenericClass($Future); |
+ //TODO(leafp): This only handles the direct flattening case. |
+ // It would probably be good to at least search up the class |
+ // hierarchy. If we keep doing flattening long term, we may |
+ // want to implement the full future flattening per spec. |
+ if ($getGenericClass(T) == futureClass) { |
+ let args = $getGenericArgs(T); |
+ if (args) return $builder(args[0]); |
+ } |
+ return $builder(T); |
+ } |
+ return flatten; |
+})()'''); |
+ |
/// Memoize a generic type constructor function. |
generic(typeConstructor) => JS('', '''(() => { |
let length = $typeConstructor.length; |