summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/basic/substring-inline-strings.js
blob: d881514923e2af7420c4ad03cb5733ea3e51934b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
let hasStringRepresentation = typeof stringRepresentation === "function";

function testLatin1() {
  var s = "abcdefghijklmnopqrstuvwxyz";
  for (var i = 0; i < 100; i++) {
    var sub8 = s.substring(0, 8);
    assertEq(sub8, "abcdefgh");
    if (hasStringRepresentation) {
      assertEq(stringRepresentation(sub8).startsWith("((JSThinInlineString"), true);
    }

    var sub24 = s.substring(0, 24);
    assertEq(sub24, "abcdefghijklmnopqrstuvwx");
    if (hasStringRepresentation) {
      assertEq(stringRepresentation(sub24).startsWith("((JSFatInlineString"), true);
    }

    var sub25 = s.substring(0, 25);
    assertEq(sub25, "abcdefghijklmnopqrstuvwxy");
    if (hasStringRepresentation) {
      assertEq(stringRepresentation(sub25).startsWith("((JSDependentString"), true);
    }
  }
}
testLatin1();

function testTwoByte() {
  var s = "\u1000bcdefghijklmnopqrstuvwxyz";
  for (var i = 0; i < 100; i++) {
    var sub4 = s.substring(0, 4);
    assertEq(sub4, "\u1000bcd");
    if (hasStringRepresentation) {
      assertEq(stringRepresentation(sub4).startsWith("((JSThinInlineString"), true);
    }

    var sub12 = s.substring(0, 12);
    assertEq(sub12, "\u1000bcdefghijkl");
    if (hasStringRepresentation) {
      assertEq(stringRepresentation(sub12).startsWith("((JSFatInlineString"), true);
    }

    var sub13 = s.substring(0, 13);
    assertEq(sub13, "\u1000bcdefghijklm");
    if (hasStringRepresentation) {
      assertEq(stringRepresentation(sub13).startsWith("((JSDependentString"), true);
    }
  }
}
testTwoByte();