OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Flags: --allow-natives-syntax |
| 6 |
| 7 function get_thin_string(a, b) { |
| 8 var str = a + b; // Make a ConsString. |
| 9 var o = {}; |
| 10 o[str]; // Turn it into a ThinString. |
| 11 return str; |
| 12 } |
| 13 |
| 14 var str = get_thin_string("foo", "bar"); |
| 15 |
| 16 var re = /.o+ba./; |
| 17 assertEquals(["foobar"], re.exec(str)); |
| 18 assertEquals(["foobar"], re.exec(str)); |
| 19 assertEquals(["foobar"], re.exec(str)); |
| 20 |
| 21 function CheckCS() { |
| 22 assertEquals("o", str.substring(1, 2)); |
| 23 assertEquals("f".charCodeAt(0), str.charCodeAt(0)); |
| 24 assertEquals("f", str.split(/oo/)[0]); |
| 25 } |
| 26 CheckCS(); |
| 27 %OptimizeFunctionOnNextCall(CheckCS); |
| 28 CheckCS(); |
| 29 |
| 30 function CheckTF() { |
| 31 try {} catch(e) {} // Turbofan. |
| 32 assertEquals("o", str.substring(1, 2)); |
| 33 assertEquals("f".charCodeAt(0), str.charCodeAt(0)); |
| 34 assertEquals("f", str.split(/oo/)[0]); |
| 35 } |
| 36 CheckTF(); |
| 37 %OptimizeFunctionOnNextCall(CheckTF); |
| 38 CheckTF(); |
| 39 |
| 40 // Flat cons strings can point to a thin string. |
| 41 |
| 42 function get_cons_thin_string(a, b) { |
| 43 // Make a ConsString. |
| 44 var s = a + b; |
| 45 // Flatten it. |
| 46 s.endsWith("a"); |
| 47 // Internalize the first part. |
| 48 var o = {}; |
| 49 o[s]; |
| 50 return s; |
| 51 } |
| 52 |
| 53 var s = get_cons_thin_string("__________", "@@@@@@@@@@a"); |
| 54 s.match(/.*a/); |
| 55 assertEquals("________", s.substring(0, 8)); |
| 56 |
| 57 function cc1(s) { |
| 58 assertEquals(95, s.charCodeAt(0)); |
| 59 assertEquals(95, s.codePointAt(0)); |
| 60 } |
| 61 cc1(s); |
| 62 cc1(s); |
| 63 %OptimizeFunctionOnNextCall(cc1); |
| 64 cc1(s); |
| 65 |
| 66 // Sliced strings can have a thin string as their parent. |
| 67 |
| 68 function get_sliced_thin_string(a, b) { |
| 69 // Make a long thin string. |
| 70 var s = a + b; |
| 71 // Slice a substring out of it. |
| 72 var slice = s.substring(0, 20); |
| 73 // Make the original string thin. |
| 74 var o = {}; |
| 75 o[s]; |
| 76 return slice; |
| 77 } |
| 78 |
| 79 var t = get_sliced_thin_string("abcdefghijklmnopqrstuvwxyz", |
| 80 "abcdefghijklmnopqrstuvwxyz"); |
| 81 assertEquals("abcdefghijklmnopqrst", decodeURI(t)); |
| 82 |
| 83 function cc2(s) { |
| 84 assertEquals(97, s.charCodeAt(0)); |
| 85 assertEquals(97, s.codePointAt(0)); |
| 86 } |
| 87 cc2(t); |
| 88 cc2(t); |
| 89 %OptimizeFunctionOnNextCall(cc2); |
| 90 cc2(t); |
OLD | NEW |