tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

array-concat-spreadable.js (1128B)


      1 function testConcat(o1, o2, len, json) {
      2    let res = Array.prototype.concat.call(o1, o2);
      3    assertEq(res.length, len);
      4    assertEq(JSON.stringify(res), json);
      5 }
      6 
      7 const o1 = {[Symbol.isConcatSpreadable]: true, length: 2, 0: 4, 1: 5, 2: 6};
      8 const o2 = {[Symbol.isConcatSpreadable]: true, length: 2, 0: 4, 2: 6};
      9 
     10 testConcat([1, 2, 3], o1, 5, "[1,2,3,4,5]");
     11 testConcat([1, 2, 3], o2, 5, "[1,2,3,4,null]");
     12 
     13 testConcat(o1, [1, 2, 3], 5, "[4,5,1,2,3]");
     14 testConcat(o2, [1, 2, 3], 5, "[4,null,1,2,3]");
     15 
     16 testConcat(o1, o1, 4, "[4,5,4,5]");
     17 testConcat(o2, o2, 4, "[4,null,4,null]");
     18 
     19 testConcat(o1, o2, 4, "[4,5,4,null]");
     20 testConcat(o2, o1, 4, "[4,null,4,5]");
     21 
     22 o1[Symbol.isConcatSpreadable] = false;
     23 
     24 testConcat(o1, o2, 3, '[{"0":4,"1":5,"2":6,"length":2},4,null]');
     25 testConcat(o2, o1, 3, '[4,null,{"0":4,"1":5,"2":6,"length":2}]');
     26 
     27 const ta = new Int32Array([4, 5, 6]);
     28 testConcat([1, 2, 3], ta, 4, '[1,2,3,{"0":4,"1":5,"2":6}]');
     29 testConcat(ta, ta, 2, '[{"0":4,"1":5,"2":6},{"0":4,"1":5,"2":6}]');
     30 
     31 ta[Symbol.isConcatSpreadable] = true;
     32 testConcat([1, 2, 3], ta, 6, "[1,2,3,4,5,6]");
     33 testConcat(ta, ta, 6, "[4,5,6,4,5,6]");