mirror of
https://github.com/tc39/test262.git
synced 2025-05-03 14:30:27 +02:00
* [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)
109 lines
2.9 KiB
JavaScript
109 lines
2.9 KiB
JavaScript
function shouldBe(actual, expected) {
|
|
if (actual !== expected)
|
|
throw new Error('bad value: ' + actual);
|
|
}
|
|
|
|
function shouldBeArray(actual, expected) {
|
|
shouldBe(actual.length, expected.length);
|
|
for (var i = 0; i < expected.length; ++i) {
|
|
try {
|
|
if (Array.isArray(expected[i])) {
|
|
shouldBe(Array.isArray(actual[i]), true);
|
|
shouldBeArray(actual[i], expected[i]);
|
|
} else
|
|
shouldBe(actual[i], expected[i]);
|
|
} catch(e) {
|
|
print(JSON.stringify(actual));
|
|
throw e;
|
|
}
|
|
}
|
|
}
|
|
|
|
function shouldThrow(func, errorMessage) {
|
|
var errorThrown = false;
|
|
var error = null;
|
|
try {
|
|
func();
|
|
} catch (e) {
|
|
errorThrown = true;
|
|
error = e;
|
|
}
|
|
if (!errorThrown)
|
|
throw new Error('not thrown');
|
|
if (String(error) !== errorMessage)
|
|
throw new Error(`bad error: ${String(error)}`);
|
|
}
|
|
|
|
shouldBe([].flat.length, 0);
|
|
shouldBe([].flat.name, `flat`);
|
|
|
|
shouldBeArray([].flat(), []);
|
|
shouldBeArray([0, 1, 2, 3, , 4].flat(), [0, 1, 2, 3, 4]);
|
|
shouldBeArray([,,,,,].flat(), []);
|
|
|
|
shouldBeArray([].flat(0), []);
|
|
shouldBeArray([0, 1, 2, 3, , 4].flat(0), [0, 1, 2, 3, 4]);
|
|
shouldBeArray([,,,,,].flat(0), []);
|
|
|
|
shouldBeArray([].flat(-1), []);
|
|
shouldBeArray([0, 1, 2, 3, , 4].flat(-1), [0, 1, 2, 3, 4]);
|
|
shouldBeArray([,,,,,].flat(-1), []);
|
|
|
|
shouldBeArray([[],[]].flat(), []);
|
|
shouldBeArray([[0],[1]].flat(), [0,1]);
|
|
shouldBeArray([[0],[],1].flat(), [0,1]);
|
|
shouldBeArray([[0],[[]],1].flat(), [0,[],1]);
|
|
shouldBeArray([[0],[[]],1].flat(1), [0,[],1]);
|
|
shouldBeArray([[0],[[]],1].flat(2), [0,1]);
|
|
|
|
shouldBeArray([[],[]].flat(0), [[],[]]);
|
|
shouldBeArray([[0],[1]].flat(0), [[0],[1]]);
|
|
shouldBeArray([[0],[],1].flat(0), [[0],[],1]);
|
|
shouldBeArray([[0],[[]],1].flat(0), [[0],[[]],1]);
|
|
|
|
shouldBeArray([[[[[[[[[[[[[[[[[[[[[42]]]]]]]]]]]]]]]]]]]]].flat(Infinity), [42]);
|
|
|
|
var array = [];
|
|
shouldBe(array.flat() !== array, true);
|
|
|
|
class DerivedArray extends Array { }
|
|
shouldBe((new DerivedArray).flat() instanceof DerivedArray, true);
|
|
var flat = [].flat;
|
|
var realm = createGlobalObject();
|
|
shouldBe(flat.call({}) instanceof Array, true);
|
|
shouldBe(flat.call(new realm.Array) instanceof Array, true);
|
|
var array2 = new realm.Array;
|
|
array2.constructor = 0;
|
|
|
|
shouldThrow(() => {
|
|
flat.call(array2);
|
|
}, `TypeError: 0 is not a constructor`);
|
|
|
|
var array2 = new realm.Array;
|
|
array2.constructor = undefined;
|
|
shouldBe(flat.call(array2) instanceof Array, true);
|
|
|
|
var array2 = new realm.Array;
|
|
array2.constructor = {
|
|
get [Symbol.species]() {
|
|
return null;
|
|
}
|
|
};
|
|
shouldBe(flat.call(array2) instanceof Array, true);
|
|
|
|
var array2 = new realm.Array;
|
|
array2.constructor = {
|
|
get [Symbol.species]() {
|
|
return undefined;
|
|
}
|
|
};
|
|
shouldBe(flat.call(array2) instanceof Array, true);
|
|
|
|
var array2 = new realm.Array;
|
|
array2.constructor = {
|
|
get [Symbol.species]() {
|
|
return DerivedArray;
|
|
}
|
|
};
|
|
shouldBe(flat.call(array2) instanceof DerivedArray, true);
|