tor-browser

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

bug730977-implement-jsop-delprop.js (1482B)


      1 function makeThing(i)
      2 {
      3    var thing = {};
      4    thing.foo = i;
      5    thing.bar = "bar_" + i;
      6    Object.defineProperty(thing, 'baz', {'configurable':false, 'value':[i]});
      7    return thing;
      8 }
      9 function makeArray(count)
     10 {
     11    var arr = new Array(count);
     12    for(var i = 0; i < count; i++) {
     13        arr[i] = makeThing(i);
     14    }
     15    return arr;
     16 }
     17 function delBar(obj)
     18 {
     19    assertEq(Object.getOwnPropertyDescriptor(obj, 'bar') === undefined, false);
     20    assertEq(delete obj.bar, true);
     21    assertEq(Object.getOwnPropertyDescriptor(obj, 'bar') === undefined, true);
     22 }
     23 function delBaz(obj)
     24 {
     25    var s = delete obj.baz;
     26    assertEq(Object.getOwnPropertyDescriptor(obj, 'baz') === undefined, false);
     27    assertEq(delete obj.baz, false);
     28    assertEq(Object.getOwnPropertyDescriptor(obj, 'baz') === undefined, false);
     29 }
     30 function delNonexistentThingy(obj)
     31 {
     32    assertEq(Object.getOwnPropertyDescriptor(obj, 'thingy') === undefined, true);
     33    assertEq(delete obj.thingy, true);
     34    assertEq(Object.getOwnPropertyDescriptor(obj, 'thingy') === undefined, true);
     35 }
     36 function testDelProp()
     37 {
     38    var arr = makeArray(10000);
     39    for(var i = 0; i < 10000; i++) {
     40        var obj = arr[i];
     41        assertEq(Object.getOwnPropertyDescriptor(obj, 'foo') === undefined, false);
     42        assertEq(delete obj.foo, true);
     43        assertEq(Object.getOwnPropertyDescriptor(obj, 'foo') === undefined, true);
     44        delBar(obj);
     45        delBaz(obj);
     46        delNonexistentThingy(obj);
     47    }
     48 }
     49 
     50 testDelProp();