summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/warp/string-compare-char-out-of-bounds.js
blob: 842b009a0f7d7b9aa8a80537cf573a9a42d5bc45 (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
// |str.char(idx) == "b"| is compiled as |str.charCodeAt(idx) == 0x62|.

const strings = [
  "",
  "a", "b", "c",
  "a-", "b-", "c-",
];

for (let i = 0; i < 1000; ++i) {
  let str = strings[i % strings.length];

  // |j <= str.length| to test out-of-bounds access, too.
  for (let j = 0; j <= str.length; ++j) {
    let ch = str.charAt(j);
    let code = j < str.length ? str.charCodeAt(j) : -1;

    assertEq(ch == "", code == -1);

    assertEq(ch == "b", code == 0x62);
    assertEq(ch != "b", code != 0x62);

    assertEq(ch < "b", code < 0x62);
    assertEq(ch <= "b", code <= 0x62);

    assertEq(ch > "b", code > 0x62);
    assertEq(ch >= "b", code >= 0x62);
  }
}