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

Unified Diff: tests/language_strong/async_await_foreign_test.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
« no previous file with comments | « pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/generators.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/language_strong/async_await_foreign_test.dart
diff --git a/tests/language_strong/async_await_foreign_test.dart b/tests/language_strong/async_await_foreign_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..ed5f99e36206f20cf5e4a88e6337a4b89b9275f2
--- /dev/null
+++ b/tests/language_strong/async_await_foreign_test.dart
@@ -0,0 +1,72 @@
+// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'dart:async';
+import 'package:expect/expect.dart';
+
+typedef Future<Null> Task();
+
+class ForeignFuture implements Future<Null> {
+ ForeignFuture(List<Task> tasks) {
+ tasks.forEach(_addTask);
+ }
+
+ Future<Null> _future;
+
+ void _addTask(Task task) {
+ _future = (_future == null) ? task() : _future.then((_) => task());
+ }
+
+ Future<S> then<S>(FutureOr<S> onValue(Null _), {Function onError}) {
+ assert(_future != null);
+ return _future.then((_) {
+ _future = null;
+ return onValue(null);
+ }, onError: (error, trace) {
+ _future = null;
+ if (onError != null) {
+ onError(error, trace);
+ }
+ });
+ }
+
+ Stream<Null> asStream() {
+ return new Stream.fromFuture(this);
+ }
+
+ Future<Null> catchError(onError, {bool test(Object error)}) {
+ print('Unimplemented catchError');
+ return null;
+ }
+
+ Future<Null> timeout(Duration timeLimit, {onTimeout()}) {
+ print('Unimplemented timeout');
+ return null;
+ }
+
+ Future<Null> whenComplete(action()) {
+ print('Unimplemented whenComplete');
+ return null;
+ }
+}
+
+var r1;
+
+Future<Null> hello() async {
+ r1 = 'hello';
+ throw new Exception('error');
+}
+
+Future<String> world() async {
+ try {
+ await new ForeignFuture([hello]);
+ } catch (e) {}
+ return 'world';
+}
+
+Future main() async {
+ var r2 = await world();
+ Expect.equals('hello', r1);
+ Expect.equals('world', r2);
+}
« no previous file with comments | « pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/generators.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698