tor-browser

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

non-function-getters-2.js (837B)


      1 // |jit-test| skip-if: !('scriptAddressForFunction' in this)
      2 
      3 with ({}) {}
      4 
      5 function makeObjWithFunctionGetter(n) {
      6  var o = {};
      7  Object.defineProperty(o, "x", {
      8    get() { return n; }
      9  });
     10 
     11  return o;
     12 }
     13 
     14 function makeObjWithBoundGetter() {
     15  // Use a testing function to leak the address of the script
     16  // so that we can circumvent the GuardFunctionScript.
     17  let orig = makeObjWithFunctionGetter(0);
     18  let getter = Object.getOwnPropertyDescriptor(orig, "x").get;
     19  let getterAddress = scriptAddressForFunction(getter);
     20 
     21  var inner = () => "bound";
     22  var bound = inner.bind(getterAddress);
     23 
     24  let o = {};
     25  Object.defineProperty(o, "x", {
     26    get: bound
     27  });
     28  return o;
     29 }
     30 
     31 function foo(o) { return o.x; }
     32 
     33 for (var i = 0; i < 100; i++) {
     34  foo(makeObjWithFunctionGetter(i));
     35 }
     36 
     37 assertEq(foo(makeObjWithBoundGetter()), "bound");