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

Unified Diff: pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/generators.dart

Issue 2804113002: DDC fix for foreign futures (Closed)
Patch Set: Optimize Created 3 years, 8 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
Index: pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/generators.dart
diff --git a/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/generators.dart b/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/generators.dart
index 2d6dbb9156673e6b413e796bbad74b4d1d59574c..cc022d2221fc9d272ccae1af70cf00c3220c3114 100644
--- a/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/generators.dart
+++ b/pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/generators.dart
@@ -26,6 +26,16 @@ async_(gen, T, @rest args) => JS(
'',
'''(() => {
let iter;
+ const FutureT = ${getGenericClass(Future)}($T);
+ let _FutureType;
+ // Return the raw class type or null if not a class object.
+ // This is streamlined to test for native futures.
+ function _getRawClassType(obj) {
+ if (!obj) return null;
+ let constructor = obj.constructor;
+ if (!constructor == null) return null;
+ return $getGenericClass(constructor);
+ }
function onValue(res) {
if (res === void 0) res = null;
return next(iter.next(res));
@@ -46,15 +56,14 @@ async_(gen, T, @rest args) => JS(
if (ret.done) {
return ret.value;
}
- // Checks if the awaited value is a Future.
- if (!$instanceOf(future, $Future)) {
+ // Wraps if future is not a native Future.
+ if (_getRawClassType(future) !== _FutureType) {
future = $Future.value(future);
}
// Chain the Future so `await` receives the Future's value.
return future.then($dynamic)(onValue, {onError: onError});
}
- let FutureT = ${getGenericClass(Future)(T)};
- return FutureT.microtask(function() {
+ let result = FutureT.microtask(function() {
iter = $gen.apply(null, $args)[Symbol.iterator]();
var result = onValue();
if ($strongInstanceOf(result, FutureT) == null) {
@@ -65,6 +74,9 @@ async_(gen, T, @rest args) => JS(
return result;
}
});
+ // TODO(jmesserly): optimize this further.
+ _FutureType = _getRawClassType(result);
+ return result;
})()''');
// Implementation inspired by _AsyncStarStreamController in
« no previous file with comments | « pkg/dev_compiler/test/codegen_expected/varargs.js ('k') | tests/language_strong/async_await_foreign_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698