tor-browser

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

accessor-ic-shape-replacement.js (1317B)


      1 // Make sure we properly update the getter when we update the holder
      2 // shape in the getter IC.
      3 function f(obj) {
      4    var x;
      5    for (var i = 0; i < 20; ++i) {
      6 x = obj.foo;
      7    }
      8    return x;
      9 }
     10 
     11 var proto = {};
     12 var obj1 = Object.create(proto);
     13 var obj2 = Object.create(proto);
     14 obj2.bar = "5";
     15 Object.defineProperty(proto, "foo",
     16 	      { get: function() { return 1; }, configurable: true });
     17 assertEq(f(obj1), 1);
     18 assertEq(f(obj2), 1);
     19 
     20 Object.defineProperty(proto, "foo",
     21 	      { get: function() { return 2; }, configurable: true });
     22 assertEq(f(obj1), 2);
     23 assertEq(f(obj2), 2);
     24 
     25 // Make sure we properly update the setter when we update the holder
     26 // shape in the setter IC.
     27 function g(obj) {
     28    var x;
     29    for (var i = 0; i < 20; ++i) {
     30 obj.foo = i;
     31    }
     32    return x;
     33 }
     34 
     35 var proto = {};
     36 var obj1 = Object.create(proto);
     37 var obj2 = Object.create(proto);
     38 var sideEffect;
     39 obj2.bar = "5";
     40 Object.defineProperty(proto, "foo",
     41 	      { set: function() { sideEffect = 1; }, configurable: true });
     42 g(obj1);
     43 assertEq(sideEffect, 1);
     44 sideEffect = undefined;
     45 g(obj2);
     46 assertEq(sideEffect, 1);
     47 sideEffect = undefined;
     48 
     49 Object.defineProperty(proto, "foo",
     50 	      { set: function() { sideEffect = 2; }, configurable: true });
     51 g(obj1);
     52 assertEq(sideEffect, 2);
     53 sideEffect = undefined;
     54 g(obj2);
     55 assertEq(sideEffect, 2);