Debian Codegraph @

js/src/jit-test/tests/cacheir/string-charCodeAt-rope.js

raw
1 function makeRope() {
2 var left = newRope("@ABCDEFGHIJKLMNO", "PQRSTUVWXYZ[\\]^_");
3 var right = newRope("`abcdefghijklmno", "pqrstuvwxyz{|}~");
4 var rope = newRope(left, right);
5 return {left, right, rope};
6 }
7
8 // Load a character from the left rope child using a constant index. The input
9 // to String.prototype.charCodeAt is always rope.
10 function testLeftChildConstant() {
11 for (var i = 0; i < 200; ++i) {
12 var {rope} = makeRope();
13
14 var ch = rope.charCodeAt(0);
15 assertEq(ch, 0x40);
16 }
17 }
18 for (var i = 0; i < 2; ++i) {
19 testLeftChildConstant();
20 }
21
22 // Load a character from the right rope child using a constant index. The input
23 // to String.prototype.charCodeAt is always rope.
24 function testRightChildConstant() {
25 for (var i = 0; i < 200; ++i) {
26 var {rope} = makeRope();
27
28 var ch = rope.charCodeAt(32);
29 assertEq(ch, 0x60);
30 }
31 }
32 for (var i = 0; i < 2; ++i) {
33 testRightChildConstant();
34 }
35
36 // Load a character from the left rope child using a variable index. The input
37 // to String.prototype.charCodeAt is always rope.
38 function testLeftChildVariable() {
39 for (var i = 0; i < 200; ++i) {
40 var {left, rope} = makeRope();
41
42 var idx = i % left.length;
43 var ch = rope.charCodeAt(idx);
44 assertEq(ch, 0x40 + idx);
45 }
46 }
47 for (var i = 0; i < 2; ++i) {
48 testLeftChildVariable();
49 }
50
51 // Load a character from the right rope child using a variable index. The input
52 // to String.prototype.charCodeAt is always rope.
53 function testRightChildVariable() {
54 for (var i = 0; i < 200; ++i) {
55 var {left, right, rope} = makeRope();
56
57 var idx = i % right.length;
58 var ch = rope.charCodeAt(left.length + idx);
59 assertEq(ch, 0x60 + idx);
60 }
61 }
62 for (var i = 0; i < 2; ++i) {
63 testRightChildVariable();
64 }
65
66 // Load all characters from both child ropes. This covers the case when the
67 // call to String.prototype.charCodeAt linearizes the rope.
68 function testBothChildren() {
69 for (var i = 0; i < 200; ++i) {
70 var {rope} = makeRope();
71
72 for (var j = 0; j < rope.length; ++j) {
73 var ch = rope.charCodeAt(j);
74 assertEq(ch, 0x40 + j);
75 }
76 }
77 }
78 for (var i = 0; i < 2; ++i) {
79 testBothChildren();
80 }