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

Side by Side Diff: tests/language/async_control_structures_test.dart

Issue 460763002: Fix returning from async functions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: first set of comments Created 6 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 unified diff | Download patch | Annotate | Revision Log
« runtime/vm/ast.h ('K') | « runtime/vm/parser.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 // VMOptions=--enable_async
6
7 import 'package:expect/expect.dart';
8
9 import 'dart:async';
10
11 expectThenValue(future, value) {
12 Expect.isTrue(future is Future);
13 future.then((result) {
14 Expect.equals(value, result);
15 });
16 }
17
18 asyncIf(condition) async {
19 if(condition) {
20 return 1;
21 } else {
22 return 2;
23 }
24 // This return is never reached as the finally block returns from the
25 // function.
26 return 3;
27 }
28
29 asyncFor(condition) async {
30 for (int i = 0; i < 10; i++) {
31 if (i == 5 && condition) {
32 return 1;
33 }
34 }
35 return 2;
36 }
37
38 asyncTryCatchFinally(overrideInFinally, doThrow) async {
39 try {
40 if (doThrow) throw 444;
41 return 1;
42 } catch (e) {
43 return e;
44 } finally {
45 if (overrideInFinally) return 3;
46 }
47 }
48
49 asyncTryCatchLoop() async {
50 var i = 0;
51 var throws = 13;
52 while (true) {
53 try {
54 throw throws;
55 } catch (e) {
56 if (i == throws) { return e; }
57 } finally {
58 i++;
59 }
60 }
61 }
62
63 asyncImplicitReturn() async {
64 try {}
65 catch (e) {}
66 finally {}
67 }
68
69 main() {
70 var asyncReturn;
71
72 asyncReturn = asyncIf(true);
73 expectThenValue(asyncReturn, 1);
74 asyncReturn = asyncIf(false);
75 expectThenValue(asyncReturn, 2);
76
77 asyncReturn = asyncFor(true);
78 expectThenValue(asyncReturn, 1);
79 asyncReturn = asyncFor(false);
80 expectThenValue(asyncReturn, 2);
81
82 asyncReturn = asyncTryCatchFinally(true, false);
83 expectThenValue(asyncReturn, 3);
84 asyncReturn = asyncTryCatchFinally(false, false);
85 expectThenValue(asyncReturn, 1);
86 asyncReturn = asyncTryCatchFinally(true, true);
87 expectThenValue(asyncReturn, 3);
88 asyncReturn = asyncTryCatchFinally(false, true);
89 expectThenValue(asyncReturn, 444);
90 asyncReturn = asyncTryCatchLoop();
91 expectThenValue(asyncReturn, 13);
92
93 asyncReturn = asyncImplicitReturn();
94 expectThenValue(asyncReturn, null);
95 }
OLDNEW
« runtime/vm/ast.h ('K') | « runtime/vm/parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698