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)
49 lines
1.5 KiB
JavaScript
49 lines
1.5 KiB
JavaScript
// This file tests is concat spreadable.
|
|
|
|
function arrayEq(a, b) {
|
|
if (a.length !== b.length)
|
|
return false;
|
|
for (let i = 0; i < a.length; i++) {
|
|
if (a[i] !== b[i])
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
{
|
|
let o = {0:1, 1:2, 2:3, length:3};
|
|
|
|
// Test it works with proxies by default
|
|
for (let i = 0; i < 100000; i++) {
|
|
if (!arrayEq(Array.prototype.concat.call(o,o), [o,o]))
|
|
throw "failed normally with an object"
|
|
}
|
|
|
|
// Test it works with spreadable true
|
|
o[Symbol.isConcatSpreadable] = true;
|
|
for (let i = 0; i < 100000; i++) {
|
|
let result = Array.prototype.concat.call(o,o)
|
|
if (!arrayEq(result, [1,2,3,1,2,3]))
|
|
throw "failed with spread got: " + result;
|
|
}
|
|
|
|
// Test it works with many things
|
|
o[Symbol.isConcatSpreadable] = true;
|
|
let other = {}
|
|
for (let i = 0; i < 100000; i++) {
|
|
let result = Array.prototype.concat.call(o,o,true,[1,2],other)
|
|
if (!arrayEq(result, [1,2,3,1,2,3,true,1,2,other]))
|
|
throw "failed with spread got: " + result;
|
|
}
|
|
|
|
// Test it works with strings
|
|
String.prototype[Symbol.isConcatSpreadable] = true;
|
|
for (let i = 0; i < 100000; i++) {
|
|
let result = Array.prototype.concat.call("hi","hi")
|
|
// This is what the spec says is the correct answer... D:
|
|
if (!arrayEq(result, ["h", "i", "hi"]))
|
|
throw "failed with string got: " + result + " on iteration " + i;
|
|
}
|
|
}
|