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 // Dart test program for testing execution of finally blocks on | |
5 // control flow breaks because of 'return', 'continue' etc. | |
6 | |
7 | |
8 class Helper { | |
9 Helper() : i = 0 { } | |
10 | |
11 int f1(int param) { | |
12 if (param == 0) { | |
13 try { | |
14 int j; | |
15 j = func(); | |
16 try { | |
17 i = 1; | |
18 return i; // Value of i is 1 on return. | |
19 } finally { | |
20 i = i + 400; // Should get executed when we return. | |
21 } | |
22 i = 2; // Should not get executed. | |
23 return i; | |
24 } finally { | |
25 i = i + 800; // Should get executed when we return. | |
26 } | |
27 return i + 200; // Should not get executed. | |
28 } | |
29 try { | |
30 int j; | |
31 j = func(); | |
32 try { | |
33 i = 4; | |
34 return i; // Value of i is 1 on return. | |
35 } finally { | |
36 i = i + 100; // Should get executed when we return. | |
37 } | |
38 i = 2; // Should not get executed. | |
39 return i; | |
40 } finally { | |
41 i = i + 200; // Should get executed when we return. | |
42 } | |
43 return i + 200; // Should not get executed. | |
44 } | |
45 | |
46 static int func() { | |
47 int i = 0; | |
48 while (i < 10) { | |
49 i++; | |
50 } | |
51 return i; | |
52 } | |
53 | |
54 int i; | |
55 } | |
56 | |
57 class ExecuteFinally5Test { | |
58 static testMain() { | |
59 Helper obj = new Helper(); | |
60 Expect.equals(1, obj.f1(0)); | |
61 Expect.equals(1201, obj.i); | |
62 Expect.equals(4, obj.f1(1)); | |
63 Expect.equals(304, obj.i); | |
64 } | |
65 } | |
66 | |
67 main() { | |
68 ExecuteFinally5Test.testMain(); | |
69 } | |
OLD | NEW |