tor-browser

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

proxy-ccw.js (1418B)


      1 // |reftest| 
      2 
      3 // Validate CCWs and proxies
      4 class Base {
      5  constructor(o) {
      6    return o;
      7  }
      8 }
      9 
     10 class A extends Base {
     11  x1 = 12;
     12  #x = 10;
     13  static gx(o) {
     14    return o.#x;
     15  }
     16  static sx(o, x) {
     17    o.#x = x;
     18  }
     19  static hasx(o) {
     20    try {
     21      o.#x;
     22      return true;
     23    } catch {
     24      return false;
     25    }
     26  }
     27 }
     28 
     29 
     30 var g = newGlobal({newCompartment: true});
     31 g.A = A;
     32 
     33 // cross_compartment_target is a cross compartment wrapper to an empty object.
     34 var cross_compartment_target = g.eval('this.x = {}; this.x');
     35 
     36 // #x gets stamped into the target of the CCW.
     37 new A(cross_compartment_target);
     38 assertEq(A.hasx(cross_compartment_target), true);
     39 
     40 // Can we update and read from this compartment?
     41 assertEq(A.gx(cross_compartment_target), 10);
     42 var o = {test: 12};
     43 A.sx(cross_compartment_target, o);
     44 assertEq(A.gx(cross_compartment_target), o);
     45 
     46 // Can we read and update from the other compartment?
     47 assertEq(g.eval('this.A.gx(this.x)'), o);
     48 var y = g.eval('this.y = {test: 13}; this.A.sx(this.x, this.y); this.y');
     49 assertEq(g.eval('this.A.gx(this.x)'), y);
     50 assertEq(A.gx(cross_compartment_target), y);
     51 
     52 
     53 if (typeof nukeCCW === 'function') {
     54  // Nuke the CCW. Now things should throw.
     55  nukeCCW(cross_compartment_target);
     56  var threw = true;
     57  try {
     58    A.gx(cross_compartment_target);
     59    threw = false;
     60  } catch (e) {
     61  }
     62  assertEq(threw, true);
     63 }
     64 
     65 
     66 if (typeof reportCompare === 'function') reportCompare(0, 0);