X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/4be4e30906bcb8ee30b4d189205cb70bad6707ce..81345200c95645a1b0d2635520f96ad55dfde63f:/tests/stress/redundant-array-bounds-checks-addition.js diff --git a/tests/stress/redundant-array-bounds-checks-addition.js b/tests/stress/redundant-array-bounds-checks-addition.js new file mode 100644 index 0000000..256e536 --- /dev/null +++ b/tests/stress/redundant-array-bounds-checks-addition.js @@ -0,0 +1,50 @@ +function foo(a, i) { + 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]]; +} + +noInline(foo); + +function arraycmp(a, b) { + if (a.length != b.length) + return false; + for (var i = 0; i < a.length; ++i) { + if (a[i] != b[i]) + return false; + } + return true; +} + +for (var i = 0; i < 100000; ++i) { + var array = []; + var offset = i & 3; + for (var j = 0; j < offset; ++j) + array.push(42); + var result = foo(array.concat([1, 2, 3, 4, 5, 6, 7, 8]), offset); + if (!arraycmp(result, [1, 2, 3, 4, 5, 6, 7, 8])) + throw "Error: bad result (1..8): " + result; +} + +var result = foo([1, 2, 3, 4, 5, 6, 7], 0); +if (!arraycmp(result, [1, 2, 3, 4, 5, 6, 7, void 0])) + throw "Error: bad result (1..7): " + result; +var result = foo([1, 2, 3, 4, 5, 6], 0); +if (!arraycmp(result, [1, 2, 3, 4, 5, 6, void 0, void 0])) + throw "Error: bad result (1..6): " + result; +var result = foo([1, 2, 3, 4, 5], 0); +if (!arraycmp(result, [1, 2, 3, 4, 5, void 0, void 0, void 0])) + throw "Error: bad result (1..5): " + result; +var result = foo([1, 2, 3, 4], 0); +if (!arraycmp(result, [1, 2, 3, 4, void 0, void 0, void 0, void 0])) + throw "Error: bad result (1..4): " + result; +var result = foo([1, 2, 3], 0); +if (!arraycmp(result, [1, 2, 3, void 0, void 0, void 0, void 0, void 0])) + throw "Error: bad result (1..3): " + result; +var result = foo([1, 2], 0); +if (!arraycmp(result, [1, 2, void 0, void 0, void 0, void 0, void 0, void 0])) + throw "Error: bad result (1..2): " + result; +var result = foo([1], 0); +if (!arraycmp(result, [1, void 0, void 0, void 0, void 0, void 0, void 0, void 0])) + throw "Error: bad result (1..1): " + result; +var result = foo([], 0); +if (!arraycmp(result, [void 0, void 0, void 0, void 0, void 0, void 0, void 0, void 0])) + throw "Error: bad result (1..1): " + result;