blob: 0726f62aeedbe246ca10e59fffd0799eae11aaea [file] [log] [blame]
keith_miller@apple.com5bed6f62016-06-16 06:01:47 +00001// This file tests is concat spreadable.
2
3function arrayEq(a, b) {
4 if (a.length !== b.length)
5 return false;
6 for (let i = 0; i < a.length; i++) {
7 if (a[i] !== b[i])
8 return false;
9 }
10 return true;
11}
12
13
14{
15 let array = [1,2,3];
16 let {proxy:p, revoke} = Proxy.revocable(array, { get : function(o, k) { return o[k]; } });
17
18 // Test it works with proxies by default
19 for (let i = 0; i < 100000; i++) {
20 if (!arrayEq(Array.prototype.concat.call(p,p), [1,2,3,1,2,3]))
21 throw "failed normally with a proxy"
22 }
23
24 // Test it works with spreadable false.
25 p[Symbol.isConcatSpreadable] = false;
26 for (let i = 0; i < 100000; i++) {
27 if (!arrayEq(Array.prototype.concat.call(p,p), [p,p]))
28 throw "failed with no spread"
29 }
30
31 p[Symbol.isConcatSpreadable] = undefined;
32 revoke();
33 passed = true;
34 try {
35 Array.prototype.concat.call(p,[]);
36 passed = false;
37 } catch (e) { }
caitp@igalia.comc0bae9562018-05-29 16:56:29 +000038 if (!passed)
39 throw "failed to throw spreading revoked proxy";
keith_miller@apple.com5bed6f62016-06-16 06:01:47 +000040}