Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(447)

Side by Side Diff: test/mjsunit/thin-strings.js

Issue 2624203002: Version 5.7.440.1 (cherry-pick) (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/cctest/test-strings.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 // Sliced strings can have a thin string as their parent.
58
59 function get_sliced_thin_string(a, b) {
60 // Make a long thin string.
61 var s = a + b;
62 // Slice a substring out of it.
63 var slice = s.substring(0, 20);
64 // Make the original string thin.
65 var o = {};
66 o[s];
67 return slice;
68 }
69
70 var t = get_sliced_thin_string("abcdefghijklmnopqrstuvwxyz",
71 "abcdefghijklmnopqrstuvwxyz");
72 assertEquals("abcdefghijklmnopqrst", decodeURI(t));
OLDNEW
« no previous file with comments | « test/cctest/test-strings.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698