blob: 60db85ef471fc44260dff85daa16b2ff86b28277 [file] [log] [blame]
function shouldBe(actual, expected) {
if (actual !== expected)
throw new Error(`Bad value: ${actual}!`);
}
(function sourceIsJSArray() {
for (var i = 0; i < 10_000; i++) {
var sourceObj = [0, 1, 2];
var slicedArr = sourceObj.slice(0, 1000);
shouldBe(slicedArr.length, 3);
shouldBe(slicedArr.join(), "0,1,2");
}
})();
const MAX_ARRAY_LENGTH = 2 ** 32 - 1;
(function sourceIsFinalObject() {
for (var i = 0; i < 10_000; i++) {
var sourceObj = {};
sourceObj[0] = "x";
sourceObj[MAX_ARRAY_LENGTH] = "y";
sourceObj.length = MAX_ARRAY_LENGTH + 1;
sourceObj.slice = Array.prototype.slice;
var slicedArr = sourceObj.slice(MAX_ARRAY_LENGTH, MAX_ARRAY_LENGTH + 2);
shouldBe(slicedArr.length, 1);
shouldBe(slicedArr[0], "y");
}
})();