| 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 [] on strings. |
| 6 |
| 7 var a = "abc"; |
| 8 var b = "øbc"; |
| 9 var c = new String.fromCharCodes([123, 456, 789]); |
| 10 |
| 11 test_charat(s, i) { |
| 12 return s[i]; |
| 13 } |
| 14 |
| 15 test_const_str(i) { |
| 16 return "abc"[i]; |
| 17 } |
| 18 |
| 19 |
| 20 test_const_index(s) { |
| 21 return s[0]; |
| 22 } |
| 23 |
| 24 test_const_index2(s) { |
| 25 return s[3]; |
| 26 } |
| 27 |
| 28 main() { |
| 29 Expect.equals("a", test_charat(a, 0)); |
| 30 for (var i=0; i<10000; i++) test_charat(a, 0); |
| 31 Expect.equals("a", test_charat(a, 0)); |
| 32 Expect.equals("b", test_charat(a, 1)); |
| 33 Expect.equals("c", test_charat(a, 2)); |
| 34 Expect.throws(() => test_charat(a, 3)); |
| 35 |
| 36 Expect.equals("a", test_const_str(0)); |
| 37 for (var i=0; i<10000; i++) test_const_str(0); |
| 38 Expect.equals("a", test_const_str(0)); |
| 39 Expect.equals("b", test_const_str(1)); |
| 40 Expect.equals("c", test_const_str(2)); |
| 41 Expect.throws(() => test_const_str(3)); |
| 42 |
| 43 Expect.equals("a", test_const_index(a)); |
| 44 for (var i=0; i<10000; i++) test_const_index(a); |
| 45 Expect.equals("a", test_const_index(a)); |
| 46 Expect.equals("ø", test_const_index(b)); |
| 47 Expect.equals(new String.fromCharCodes([123]), test_const_index(c)); |
| 48 Expect.throws(() => test_const_index2(a)); |
| 49 |
| 50 Expect.equals("ø", test_charat(b, 0)); |
| 51 for (var i=0; i<10000; i++) test_charat(b, 0); |
| 52 Expect.equals("ø", test_charat(b, 0)); |
| 53 Expect.equals("b", test_charat(b, 1)); |
| 54 Expect.equals("c", test_charat(b, 2)); |
| 55 Expect.throws(() => test_charat(b, 3)); |
| 56 |
| 57 Expect.equals(new String.fromCharCodes([123]), test_charat(c, 0)); |
| 58 for (var i=0; i<10000; i++) test_charat(c, 0); |
| 59 Expect.equals(new String.fromCharCodes([123]), test_charat(c, 0)); |
| 60 Expect.equals(new String.fromCharCodes([456]), test_charat(c, 1)); |
| 61 Expect.equals(new String.fromCharCodes([789]), test_charat(c, 2)); |
| 62 Expect.throws(() => test_charat(c, 3)); |
| 63 |
| 64 |
| 65 } |
| OLD | NEW |