Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 // Test optimized constant string and constant array access. | |
| 6 | |
| 7 int testConstantStringAndIndexCharCodeAt() { | |
| 8 int test(b) { | |
| 9 if (b) return "hest".charCodeAt(400); | |
| 10 return "hest".charCodeAt(2); | |
| 11 } | |
| 12 | |
| 13 try { | |
| 14 test(true); | |
| 15 } catch(e) { } | |
|
srdjan
2012/11/01 20:32:18
You may want to use Expect.throws instead.
Florian Schneider
2012/11/01 22:58:56
Done.
| |
| 16 for (int i = 0; i < 10000; i++) test(false); | |
| 17 try { | |
| 18 return test(true); | |
|
srdjan
2012/11/01 20:32:18
ditto and below
Florian Schneider
2012/11/01 22:58:56
Done.
| |
| 19 } catch (e) { | |
| 20 return -12345; | |
| 21 } | |
| 22 } | |
| 23 | |
| 24 | |
| 25 int testConstantArrayAndIndexAt() { | |
| 26 int test(b) { | |
| 27 var a = const [1,2,3,4]; | |
| 28 if (b) return a[400]; | |
| 29 return a[2]; | |
| 30 } | |
| 31 | |
| 32 try { | |
| 33 test(true); | |
| 34 } catch(e) { } | |
| 35 for (int i = 0; i < 10000; i++) test(false); | |
| 36 try { | |
| 37 return test(true); | |
| 38 } catch (e) { | |
| 39 return -12345; | |
| 40 } | |
| 41 } | |
| 42 | |
| 43 | |
| 44 main() { | |
| 45 Expect.equals(-12345, testConstantStringAndIndexCharCodeAt()); | |
| 46 Expect.equals(-12345, testConstantArrayAndIndexAt()); | |
| 47 } | |
| OLD | NEW |