tor-browser

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

ccw.js (1281B)


      1 // |reftest| shell-option(--enable-shadow-realms) skip-if(!xulRuntime.shell)
      2 
      3 var g = newGlobal({ newCompartment: true });
      4 
      5 var sr = g.evaluate(`new ShadowRealm()`);
      6 
      7 
      8 // sr should be a CCW to a ShadowRealm.
      9 ShadowRealm.prototype.evaluate.call(sr, "var x = 10");
     10 assertEq(sr.evaluate("x"), 10);
     11 
     12 // wrappedf should *not* be a CCW, because we're using this realm's ShadowRealm.prototype.evaluate,
     13 // and so the active realm when invoking will be this current realm.
     14 //
     15 // However, the target function (wrappedf's f)  comes from another compartment, and will have to be a CCW.
     16 var wrappedf = ShadowRealm.prototype.evaluate.call(sr, "function f() { return 10; }; f");
     17 assertEq(wrappedf(), 10);
     18 
     19 var evaluate_from_other_realm = g.evaluate('ShadowRealm.prototype.evaluate');
     20 
     21 // wrappedb should be a CCW, since the callee of the .call comes from the other
     22 // compartment.
     23 var wrappedb = evaluate_from_other_realm.call(sr, "function b() { return 12; }; b");
     24 assertEq(wrappedb(), 12);
     25 
     26 nukeAllCCWs()
     27 // This throws, but the dead object message is lost and replaced with the wrapped function
     28 // object message.
     29 assertThrowsInstanceOf(() => wrappedf(), TypeError);
     30 assertThrowsInstanceOf(() => wrappedb(), TypeError);
     31 
     32 if (typeof reportCompare === 'function')
     33    reportCompare(true, true);