]> git.saurik.com Git - apple/javascriptcore.git/blame_incremental - tests/stress/redundant-array-bounds-checks-addition.js
JavaScriptCore-7600.1.4.9.tar.gz
[apple/javascriptcore.git] / tests / stress / redundant-array-bounds-checks-addition.js
... / ...
CommitLineData
1function foo(a, i) {
2 return [a[i + 0], a[i + 1], a[i + 2], a[i + 3], a[i + 4], a[i + 5], a[i + 6], a[i + 7]];
3}
4
5noInline(foo);
6
7function arraycmp(a, b) {
8 if (a.length != b.length)
9 return false;
10 for (var i = 0; i < a.length; ++i) {
11 if (a[i] != b[i])
12 return false;
13 }
14 return true;
15}
16
17for (var i = 0; i < 100000; ++i) {
18 var array = [];
19 var offset = i & 3;
20 for (var j = 0; j < offset; ++j)
21 array.push(42);
22 var result = foo(array.concat([1, 2, 3, 4, 5, 6, 7, 8]), offset);
23 if (!arraycmp(result, [1, 2, 3, 4, 5, 6, 7, 8]))
24 throw "Error: bad result (1..8): " + result;
25}
26
27var result = foo([1, 2, 3, 4, 5, 6, 7], 0);
28if (!arraycmp(result, [1, 2, 3, 4, 5, 6, 7, void 0]))
29 throw "Error: bad result (1..7): " + result;
30var result = foo([1, 2, 3, 4, 5, 6], 0);
31if (!arraycmp(result, [1, 2, 3, 4, 5, 6, void 0, void 0]))
32 throw "Error: bad result (1..6): " + result;
33var result = foo([1, 2, 3, 4, 5], 0);
34if (!arraycmp(result, [1, 2, 3, 4, 5, void 0, void 0, void 0]))
35 throw "Error: bad result (1..5): " + result;
36var result = foo([1, 2, 3, 4], 0);
37if (!arraycmp(result, [1, 2, 3, 4, void 0, void 0, void 0, void 0]))
38 throw "Error: bad result (1..4): " + result;
39var result = foo([1, 2, 3], 0);
40if (!arraycmp(result, [1, 2, 3, void 0, void 0, void 0, void 0, void 0]))
41 throw "Error: bad result (1..3): " + result;
42var result = foo([1, 2], 0);
43if (!arraycmp(result, [1, 2, void 0, void 0, void 0, void 0, void 0, void 0]))
44 throw "Error: bad result (1..2): " + result;
45var result = foo([1], 0);
46if (!arraycmp(result, [1, void 0, void 0, void 0, void 0, void 0, void 0, void 0]))
47 throw "Error: bad result (1..1): " + result;
48var result = foo([], 0);
49if (!arraycmp(result, [void 0, void 0, void 0, void 0, void 0, void 0, void 0, void 0]))
50 throw "Error: bad result (1..1): " + result;