| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 | 4 |
| 5 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 | 6 |
| 7 // Test optimized constant string and constant array access. | 7 // Test optimized constant string and constant array access. |
| 8 | 8 |
| 9 int testConstantStringAndIndexCodeUnitAt() { | 9 int testConstantStringAndIndexCodeUnitAt() { |
| 10 int test(b) { | 10 int test(b) { |
| 11 if (b) return "hest".codeUnitAt(400); | 11 if (b) return "hest".codeUnitAt(400); |
| 12 return "hest".codeUnitAt(2); | 12 return "hest".codeUnitAt(2); |
| 13 } | 13 } |
| 14 | 14 |
| 15 Expect.throws(() => test(true)); | 15 Expect.throws(() => test(true)); |
| 16 for (int i = 0; i < 10000; i++) test(false); | 16 for (int i = 0; i < 10000; i++) test(false); |
| 17 Expect.throws(() => test(true)); | 17 Expect.throws(() => test(true)); |
| 18 } | 18 } |
| 19 | 19 |
| 20 | 20 |
| 21 int testConstantArrayAndIndexAt() { | 21 int testConstantArrayAndIndexAt() { |
| 22 int test(b) { | 22 int testPositive(b) { |
| 23 var a = const [1,2,3,4]; | 23 var a = const [1,2,3,4]; |
| 24 if (b) return a[400]; | 24 if (b) return a[400]; |
| 25 return a[2]; | 25 return a[2]; |
| 26 } | 26 } |
| 27 | 27 |
| 28 Expect.throws(() => test(true)); | 28 int testNegative(b) { |
| 29 for (int i = 0; i < 10000; i++) test(false); | 29 var a = const [1,2,3,4]; |
| 30 Expect.throws(() => test(true)); | 30 if (b) return a[-1]; |
| 31 return a[2]; |
| 32 } |
| 33 |
| 34 Expect.throws(() => testPositive(true)); |
| 35 for (int i = 0; i < 10000; i++) testPositive(false); |
| 36 Expect.throws(() => testPositive(true)); |
| 37 |
| 38 Expect.throws(() => testNegative(true)); |
| 39 for (int i = 0; i < 10000; i++) testNegative(false); |
| 40 Expect.throws(() => testNegative(true)); |
| 31 } | 41 } |
| 32 | 42 |
| 33 | 43 |
| 34 foo(a) { | 44 foo(a) { |
| 35 if (a == 1) { return 2; } | 45 if (a == 1) { return 2; } |
| 36 var aa = const [1, 2]; | 46 var aa = const [1, 2]; |
| 37 return aa[2.3]; | 47 return aa[2.3]; |
| 38 } | 48 } |
| 39 | 49 |
| 40 | 50 |
| 41 int testNonSmiIndex() { | 51 int testNonSmiIndex() { |
| 42 for (int i = 0; i < 10000; i++) { foo(1); } | 52 for (int i = 0; i < 10000; i++) { foo(1); } |
| 43 Expect.throws(() => foo(2)); | 53 Expect.throws(() => foo(2)); |
| 44 } | 54 } |
| 45 | 55 |
| 46 | 56 |
| 47 main() { | 57 main() { |
| 48 testConstantStringAndIndexCodeUnitAt(); | 58 testConstantStringAndIndexCodeUnitAt(); |
| 49 testConstantArrayAndIndexAt(); | 59 testConstantArrayAndIndexAt(); |
| 50 testNonSmiIndex(); | 60 testNonSmiIndex(); |
| 51 } | 61 } |
| OLD | NEW |