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