Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//@ $skipModes << :lockdown

function shouldBe(actual, expected) {
if (actual !== expected)
throw new Error(`expected ${expected} but got ${actual}`);
}

function createWithPush() {
let array = [];
for (let i = 0; i < 8; ++i)
array.push({ i });
return array;
}

function createWithLiteral() {
return [{}, {}, {}];
}

function createWithNewArray() {
let array = new Array(8);
for (let i = 0; i < 8; ++i)
array[i] = { i };
return array;
}

let source = createWithPush();

function createWithMap() {
return source.map((value) => value);
}

function createWithFilter() {
return source.filter(() => true);
}

function createInt32WithPush() {
let array = [];
for (let i = 0; i < 8; ++i)
array.push(i);
return array;
}

function createDoubleWithPush() {
let array = [];
for (let i = 0; i < 8; ++i)
array.push(i + 0.5);
return array;
}

function createInt32WithNewArray() {
let array = new Array(8);
for (let i = 0; i < 8; ++i)
array[i] = i;
return array;
}

function createInt32WithConstantLiteral() {
return [1, 2, 3];
}

function createEmpty() {
return [];
}

function test(create, expected) {
for (let i = 0; i < testLoopCount; ++i) {
let array = create();
if (!(i % 100))
Object.freeze(array);
}
fullGC();
for (let i = 0; i < testLoopCount; ++i)
shouldBe($vm.indexingMode(create()), expected);
}

test(createWithPush, "ArrayWithContiguous");
test(createWithLiteral, "ArrayWithContiguous");
test(createWithNewArray, "ArrayWithContiguous");
test(createWithMap, "ArrayWithContiguous");
test(createWithFilter, "ArrayWithContiguous");
test(createInt32WithPush, "ArrayWithInt32");
test(createDoubleWithPush, "ArrayWithDouble");
test(createInt32WithNewArray, "ArrayWithInt32");
test(createInt32WithConstantLiteral, "CopyOnWriteArrayWithInt32");
test(createEmpty, "ArrayWithUndecided");
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
//@ $skipModes << :lockdown

function shouldBe(actual, expected) {
if (actual !== expected)
throw new Error(`expected ${expected} but got ${actual}`);
}

function create(length) {
let array = new Array(length);
for (let i = 0; i < length; ++i)
array[i] = { i };
return array;
}
noInline(create);

function createFrozen() {
return Object.freeze([{ i: 0 }, { i: 1 }, { i: 2 }]);
}
noInline(createFrozen);

function isObject(value) {
return typeof value === "object";
}

function every(array) {
return array.every(isObject);
}

function some(array) {
return array.some((value) => value.i === -1);
}

function map(array) {
return array.map(isObject).length;
}

function filter(array) {
return array.filter(isObject).length;
}

function forEach(array) {
let count = 0;
array.forEach(() => { ++count; });
return count;
}

function at(array) {
return array.at(0).i;
}

function indexed(array) {
let sum = 0;
for (let i = 0; i < array.length; ++i)
sum += array[i].i;
return sum;
}

function forOf(array) {
let sum = 0;
for (let value of array)
sum += value.i;
return sum;
}

function destructure(array) {
let [first, second] = array;
return first.i + second.i;
}

function store(array) {
for (let i = 0; i < array.length; ++i)
array[i] = array[0];
}

function push(array) {
try {
array.push(array[0]);
} catch { }
}

function test(func) {
for (let i = 0; i < testLoopCount; ++i) {
let array = create(8);
func(array);
shouldBe($vm.indexingMode(array), "ArrayWithContiguous");
if (i % 2)
func(createFrozen());
}
}

for (let func of [every, some, map, filter, forEach, at, indexed, forOf, destructure, store, push])
test(func);
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
//@ $skipModes << :lockdown

function shouldBe(actual, expected) {
if (actual !== expected)
throw new Error(`expected ${expected} but got ${actual}`);
}

function create(length) {
let array = new Array(length);
for (let i = 0; i < length; ++i)
array[i] = { i };
return array;
}
noInline(create);

function createFrozen() {
return Object.freeze([{ i: 0 }, { i: 1 }, { i: 2 }]);
}
noInline(createFrozen);

function isObject(value) {
return typeof value === "object";
}

function every(array) {
return array.every(isObject);
}

function some(array) {
return array.some((value) => value.i === -1);
}

function map(array) {
return array.map(isObject).length;
}

function filter(array) {
return array.filter(isObject).length;
}

function forEach(array) {
let count = 0;
array.forEach(() => { ++count; });
return count;
}

function at(array) {
return array.at(0).i;
}

function indexed(array) {
let sum = 0;
for (let i = 0; i < array.length; ++i)
sum += array[i].i;
return sum;
}

function forOf(array) {
let sum = 0;
for (let value of array)
sum += value.i;
return sum;
}

function destructure(array) {
let [first, second] = array;
return first.i + second.i;
}

function store(array) {
for (let i = 0; i < array.length; ++i)
array[i] = array[0];
}

function push(array) {
try {
array.push(array[0]);
} catch { }
}

function test(func) {
for (let i = 0; i < testLoopCount; ++i) {
let array = create(8);
func(array);
shouldBe($vm.indexingMode(array), "ArrayWithContiguous");
if (!(i % 100))
func(createFrozen());
}
}

for (let func of [every, some, map, filter, forEach, at, indexed, forOf, destructure, store, push])
test(func);
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//@ skip if not $jitTests
//@ runDefault("--validateOptions=true", "--useConcurrentJIT=0")

function shouldBe(actual, expected) {
if (actual !== expected)
throw new Error(`expected ${expected} but got ${actual}`);
}

function shouldNotBeCompiledRepeatedly(func) {
if (numberOfDFGCompiles(func) > 3)
throw new Error(`${func.name} was compiled ${numberOfDFGCompiles(func)} times`);
}

let frozen = Object.freeze([]);

function first(array) {
return array[0];
}
noInline(first);

function indexed(array) {
let count = 0;
for (let i = 0; i < array.length; ++i) {
if (array[i] === undefined)
++count;
}
return count;
}
noInline(indexed);

function forOf(array) {
let count = 0;
for (let value of array)
++count;
return count;
}
noInline(forOf);

function destructure(array) {
let [first, second] = array;
return first;
}
noInline(destructure);

function store(array) {
array[0] = 42;
}
noInline(store);

function push(array) {
try {
array.push(42);
} catch { }
}
noInline(push);

function test(func, create, expected) {
for (let i = 0; i < testLoopCount; ++i) {
let array = create();
func(array);
shouldBe($vm.indexingMode(array), expected);
if (!(i % 100))
func(frozen);
}
shouldNotBeCompiledRepeatedly(func);
}

test(first, () => [], "ArrayWithUndecided");
test(indexed, () => new Array(4), "ArrayWithUndecided");
test(forOf, () => new Array(4), "ArrayWithUndecided");
test(destructure, () => new Array(4), "ArrayWithUndecided");
test(store, () => [], "ArrayWithInt32");
test(push, () => [], "ArrayWithInt32");
Loading
Loading