tor-browser

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

object-spread.js (1082B)


      1 function test() {
      2    var from, to;
      3 
      4    // From values.
      5    from = {x: 1, y: 2};
      6    to = {...from};
      7    assertEq(to.y, 2);
      8    to = {...from, ...from};
      9    assertEq(to.y, 2);
     10 
     11    // From getter.
     12    var c = 7;
     13    from = {x: 1, get y() { return ++c; }};
     14    to = {...from};
     15    assertEq(to.y, 8);
     16    to = {...from, ...from};
     17    assertEq(to.y, 10);
     18 
     19    // Array with dense elements.
     20    from = [1, 2, 3];
     21    to = {...from};
     22    assertEq(to[2], 3);
     23    assertEq("length" in to, false);
     24 
     25    // Object with sparse elements and symbols.
     26    from = {x: 1, 1234567: 2, 1234560: 3, [Symbol.iterator]: 5, z: 3};
     27    to = {...from};
     28    assertEq(to[1234567], 2);
     29    assertEq(Object.keys(to).toString(), "1234560,1234567,x,z");
     30    assertEq(to[Symbol.iterator], 5);
     31 
     32    // Typed array.
     33    from = new Int32Array([1, 2, 3]);
     34    to = {...from};
     35    assertEq(to[1], 2);
     36 
     37    // Primitive string.
     38    from = "foo";
     39    to = {...from};
     40    assertEq(to[0], "f");
     41 
     42    // String object.
     43    from = new String("bar");
     44    to = {...from};
     45    assertEq(to[2], "r");
     46 }
     47 test();
     48 test();
     49 test();