test262/implementation-contributed/javascriptcore/stress/array-slice-jettison-on-constructor-change.js
test262-automation e9a5a7f918 [javascriptcore-test262-automation] changes from git@github.com:WebKit/webkit.git at sha 949e26452cfa153a7f4afe593da97e2fe9e1b706 on Tue Jul 03 2018 14:35:15 GMT-0400 (Eastern Daylight Time) (#1620)
* [javascriptcore-test262-automation] changes from git@github.com:WebKit/webkit.git at sha 949e26452cfa153a7f4afe593da97e2fe9e1b706 on Tue Jul 03 2018 14:35:15 GMT-0400 (Eastern Daylight Time)
2018-07-03 15:59:58 -04:00

73 lines
1.8 KiB
JavaScript

function assert(b, ...m) {
if (!b)
throw new Error("Bad: ", ...m)
}
noInline(assert);
let shouldBeNewConstructor = false;
const newConstructor = {};
function shallowEq(a, b) {
assert(a.length === b.length, a, b);
if (shouldBeNewConstructor)
assert(b.constructor === newConstructor);
for (let i = 0; i < a.length; i++)
assert(a[i] === b[i], a, b);
}
noInline(shallowEq);
let tests = [
[[1,2,3,4,5], [1,2,3,4,5], 0, 5],
[[1,2,3,4,5], [1,2,3,4,5], 0],
[[1,2,3,4,5], [4], -2, -1],
[[1,2,3,4,5], [5], -1],
[[1,2,3,4,5], [5], -1, 5],
[[1,2,3,4,5], [], -10, -20],
[[1,2,3,4,5], [], -20, -10],
[[1,2,3,4,5], [], 6, 4],
[[1,2,3,4,5], [], 3, 2],
[[1,2,3,4,5], [4,5], 3, 10],
[[1,2,3,4,5], [3,4,5], 2, 10],
[[1,2,3,4,5], [1,2,3,4,5], -10, 10],
[[1,2,3,4,5], [1,2,3,4,5], -5, 10],
[[1,2,3,4,5], [2,3,4,5], -4, 10],
];
function runTest1(a, b) {
let result = a.slice(b);
return result;
}
noInline(runTest1);
function runTest2(a, b, c) {
let result = a.slice(b, c);
return result;
}
noInline(runTest2);
function addRandomProperties(input) {
for (let i = 0; i < 4; i++) {
input["prop" + i + ((Math.random() * 100000) | 0)] = i;
}
}
noInline(addRandomProperties);
function runTests() {
for (let i = 0; i < 10000; i++) {
for (let [input, output, ...args] of tests) {
addRandomProperties(input);
assert(args.length === 1 || args.length === 2);
if (args.length === 1)
shallowEq(runTest1(input, args[0]), output);
else
shallowEq(runTest2(input, args[0], args[1]), output);
}
}
}
runTests();
Array.prototype.constructor = newConstructor;
shouldBeNewConstructor = true;
runTests();