OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011, 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 // This test ensures that the finally block executes correctly when | |
5 // there are throw, break and return statements in the finally block. | |
6 | |
7 class Hello { | |
8 static var sum; | |
9 | |
10 static foo() { | |
11 sum = 0; | |
12 try { | |
13 sum += 1; | |
14 return 'hi'; | |
15 } finally { | |
16 sum += 1; | |
17 throw 'ball'; | |
18 sum += 1; | |
19 } | |
20 } | |
21 | |
22 static foo1() { | |
23 bool loop = true; | |
24 sum = 0; | |
25 L: | |
26 while (loop) { | |
27 try { | |
28 sum += 1; | |
29 return 'hi'; | |
30 } finally { | |
31 sum += 1; | |
32 break L; | |
33 sum += 1; | |
34 } | |
35 } | |
36 } | |
37 | |
38 static foo2() { | |
39 bool loop = true; | |
40 sum = 0; | |
41 try { | |
42 sum += 1; | |
43 return 'hi'; | |
44 } finally { | |
45 sum += 1; | |
46 return 10; | |
47 sum += 1; | |
48 } | |
49 } | |
50 | |
51 static foo3() { | |
52 sum = 0; | |
53 try { | |
54 sum += 1; | |
55 return 'hi'; | |
56 } finally { | |
57 sum += 1; | |
58 return 10; | |
59 sum += 1; | |
60 } | |
61 } | |
62 | |
63 static void main() { | |
64 foo1(); | |
65 Expect.equals(2, sum); | |
66 foo2(); | |
67 Expect.equals(2, sum); | |
68 foo3(); | |
69 Expect.equals(2, sum); | |
70 try { | |
71 foo(); | |
72 } catch (var e) { | |
73 } | |
74 Expect.equals(2, sum); | |
75 } | |
76 | |
77 } | |
78 | |
79 main() { | |
80 Hello.main(); | |
81 } | |
OLD | NEW |