| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 // Dart test program for testing try/catch statement without any exceptions | 4 // Dart test program for testing try/catch statement without any exceptions |
| 5 // being thrown. | 5 // being thrown. |
| 6 // VMOptions=--optimization-counter-threshold=100 --no-background-compilation --
enable-inlining-annotations | 6 // VMOptions=--optimization-counter-threshold=100 --no-background-compilation --
enable-inlining-annotations |
| 7 | 7 |
| 8 // Test local variables updated inside try-catch. | 8 // Test local variables updated inside try-catch. |
| 9 | 9 |
| 10 import "package:expect/expect.dart"; | 10 import "package:expect/expect.dart"; |
| 11 | 11 |
| 12 const noInline = "NeverInline"; | 12 const noInline = "NeverInline"; |
| 13 | 13 |
| 14 @noInline | 14 @noInline |
| 15 m1(int b) { | 15 m1(int b) { |
| 16 if (b == 1) throw 123; | 16 if (b == 1) throw 123; |
| 17 } | 17 } |
| 18 | 18 |
| 19 | |
| 20 @noInline | 19 @noInline |
| 21 m2(int b) { | 20 m2(int b) { |
| 22 if (b == 2) throw 456; | 21 if (b == 2) throw 456; |
| 23 } | 22 } |
| 24 | 23 |
| 25 | |
| 26 @noInline | 24 @noInline |
| 27 test(b) { | 25 test(b) { |
| 28 var state = 0; | 26 var state = 0; |
| 29 try { | 27 try { |
| 30 state++; | 28 state++; |
| 31 m1(b); | 29 m1(b); |
| 32 state++; | 30 state++; |
| 33 m2(b); | 31 m2(b); |
| 34 state++; | 32 state++; |
| 35 } on dynamic catch (e, s) { | 33 } on dynamic catch (e, s) { |
| 36 if (b == 1 && state != 1) throw "fail1"; | 34 if (b == 1 && state != 1) throw "fail1"; |
| 37 if (b == 2 && state != 2) throw "fail2"; | 35 if (b == 2 && state != 2) throw "fail2"; |
| 38 if (b == 3 && state != 3) throw "fail3"; | 36 if (b == 3 && state != 3) throw "fail3"; |
| 39 return e; | 37 return e; |
| 40 } | 38 } |
| 41 return "no throw"; | 39 return "no throw"; |
| 42 } | 40 } |
| 43 | 41 |
| 44 main() { | 42 main() { |
| 45 for (var i=0; i<300; i++) { | 43 for (var i = 0; i < 300; i++) { |
| 46 Expect.equals("no throw", test(0)); | 44 Expect.equals("no throw", test(0)); |
| 47 } | 45 } |
| 48 Expect.equals("no throw", test(0)); | 46 Expect.equals("no throw", test(0)); |
| 49 Expect.equals(123, test(1)); | 47 Expect.equals(123, test(1)); |
| 50 Expect.equals(456, test(2)); | 48 Expect.equals(456, test(2)); |
| 51 } | 49 } |
| OLD | NEW |