test262/implementation-contributed/javascriptcore/stress/array-indexof-constant-folding.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
2.4 KiB
JavaScript

function shouldBe(actual, expected)
{
if (actual !== expected)
throw new Error('bad value: ' + actual);
}
(function () {
function indexOfInt32Other(array, value, index)
{
return array.indexOf(value, index);
}
noInline(indexOfInt32Other);
function indexOfInt32Cell(array, value, index)
{
return array.indexOf(value, index);
}
noInline(indexOfInt32Cell);
function indexOfInt32Boolean(array, value, index)
{
return array.indexOf(value, index);
}
noInline(indexOfInt32Boolean);
function indexOfDoubleOther(array, value, index)
{
return array.indexOf(value, index);
}
noInline(indexOfDoubleOther);
function indexOfDoubleCell(array, value, index)
{
return array.indexOf(value, index);
}
noInline(indexOfDoubleCell);
function indexOfDoubleBoolean(array, value, index)
{
return array.indexOf(value, index);
}
noInline(indexOfDoubleBoolean);
var key = {};
var int32Array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
var doubleArray = [0, 1, 2, 3, 4.2, 5, 6, 7, 8, 9, 10.5, 11, 12];
for (var i = 0; i < 1e4; ++i) {
shouldBe(indexOfInt32Other(int32Array, null, 0), -1);
shouldBe(indexOfInt32Other(int32Array, undefined, 0), -1);
shouldBe(indexOfInt32Cell(int32Array, key, 0), -1);
shouldBe(indexOfInt32Cell(int32Array, Symbol("Cocoa"), 0), -1);
shouldBe(indexOfInt32Cell(int32Array, "Cocoa", 0), -1);
shouldBe(indexOfInt32Boolean(int32Array, true, 0), -1);
shouldBe(indexOfInt32Boolean(int32Array, false, 0), -1);
shouldBe(indexOfDoubleOther(doubleArray, null, 0), -1);
shouldBe(indexOfDoubleOther(doubleArray, undefined, 0), -1);
shouldBe(indexOfDoubleCell(doubleArray, key, 0), -1);
shouldBe(indexOfDoubleCell(doubleArray, Symbol("Cocoa"), 0), -1);
shouldBe(indexOfDoubleCell(doubleArray, "Cocoa", 0), -1);
shouldBe(indexOfDoubleBoolean(doubleArray, true, 0), -1);
shouldBe(indexOfDoubleBoolean(doubleArray, false, 0), -1);
}
shouldBe(indexOfInt32Other(int32Array, 1, 0), 1);
shouldBe(indexOfInt32Cell(int32Array, 1, 0), 1);
shouldBe(indexOfInt32Boolean(int32Array, 1, 0), 1);
shouldBe(indexOfDoubleOther(doubleArray, 1, 0), 1);
shouldBe(indexOfDoubleCell(doubleArray, 1, 0), 1);
shouldBe(indexOfDoubleBoolean(doubleArray, 1, 0), 1);
}());