tor-browser

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

bug1536228.js (1560B)


      1 load(libdir + "asserts.js");
      2 
      3 function test() {
      4    var plainDataProperty = {
      5        value: 0, enumerable: true, configurable: true, writable: true
      6    };
      7    var nonEnumerableProperty = {
      8        value: 0, enumerable: false, configurable: true, writable: true
      9    };
     10    var nonConfigurableProperty = {
     11        value: 0, enumerable: true, configurable: false, writable: true
     12    };
     13    var n = 5000;
     14    for (var i = 0; i < n; ++i) {
     15        var obj = {};
     16 
     17        // Create a different shape for each object to ensure JSOP_INITELEM
     18        // below can get into the megamorphic state.
     19        Object.defineProperty(obj, "bar" + i, nonEnumerableProperty);
     20 
     21        // Plain data property, will be created through DefineDataProperty,
     22        // which is emitted as JSOP_INITELEM. The object doesn't have a "foo"
     23        // property, so JSOP_INITELEM can simply create a new property.
     24        Object.defineProperty(obj, "foo", plainDataProperty);
     25 
     26        // Redefine as a non-data property for the last object.
     27        var desc = (i + 1 !== n) ? plainDataProperty : nonConfigurableProperty;
     28        Object.defineProperty(obj, "foo", desc);
     29 
     30        // Again JSOP_INITELEM, but this time JSOP_INITELEM can't simply add a
     31        // property, because "foo" is already present. And for the last object,
     32        // which has a non-configurable "foo" property, this call must throw a
     33        // TypeError exception.
     34        Object.defineProperty(obj, "foo", plainDataProperty);
     35    }
     36 }
     37 
     38 for (var i = 0; i < 2; ++i) {
     39    assertThrowsInstanceOf(test, TypeError);
     40 }