tor-browser

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

for-in-proto-properties.js (1256B)


      1 function testNonEnumerableVisited() {
      2    // Non-enumerable properties must still be included in the duplicate-property
      3    // checking.
      4 
      5    var proto1 = Object.create(null);
      6    Object.defineProperty(proto1, "x", {enumerable: true, value: 1});
      7 
      8    var proto2 = Object.create(proto1);
      9    Object.defineProperty(proto2, "x", {enumerable: false, value: 1});
     10 
     11    for (var p in proto2) {
     12        throw "Shouldn't enumerate any properties";
     13    }
     14 
     15    var o = Object.create(proto2);
     16    for (var p in o) {
     17        throw "Shouldn't enumerate any properties";
     18    }
     19 }
     20 testNonEnumerableVisited();
     21 
     22 function testEnumerableOnProto() {
     23    var iter = o => {
     24        var props = [];
     25        for (var p in o) { props.push(p); }
     26        return props;
     27    };
     28 
     29    // Test dense elements on the proto chain are included.
     30    var props = iter(Object.create({0: 1}));
     31    assertEq(JSON.stringify(props), '["0"]');
     32 
     33    // Test typed array elements on the proto chain are included.
     34    props = iter(Object.create(new Int32Array(2)));
     35    assertEq(JSON.stringify(props), '["0","1"]');
     36 
     37    // Test sparse elements on the proto chain are included.
     38    props = iter(Object.create({1234567: 1}));
     39    assertEq(JSON.stringify(props), '["1234567"]');
     40 }
     41 testEnumerableOnProto();