tor-browser

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

Object-getPromiseReactions-06.js (1534B)


      1 // Debugger.Object.prototype.getPromiseReactions should handle reaction records
      2 // that are cross-compartment with their promises.
      3 
      4 var dbg = new Debugger;
      5 
      6 var g1 = newGlobal({ newCompartment: true });
      7 var DOg1 = dbg.addDebuggee(g1);
      8 
      9 var g2 = newGlobal({ newCompartment: true });
     10 var DOg2 = dbg.addDebuggee(g2);
     11 
     12 g1.eval(`
     13    var pResolve, pReject;
     14    var p = new Promise((resolve, reject) => { pResolve = resolve; pReject = reject });
     15 `);
     16 
     17 g2.p = g1.p;
     18 g2.eval(`
     19    var p2 = new Promise((resolve, reject) => { resolve(p); });
     20 `);
     21 
     22 const DOp = DOg1.makeDebuggeeValue(g1.p);
     23 const DOp2 = DOg2.makeDebuggeeValue(g2.p2);
     24 
     25 // Since the standard resolving functions enqueue a job to do the `then` call,
     26 // we need to drain the queue before p2 will appear on p1's reaction list.
     27 drainJobQueue();
     28 
     29 const reactions = DOp.getPromiseReactions();
     30 assertEq(true, Array.isArray(reactions));
     31 assertEq(reactions.length, 1);
     32 assertEq(typeof reactions[0], "object");
     33 assertEq(true, reactions[0].resolve instanceof Debugger.Object);
     34 assertEq(true, reactions[0].resolve.callable);
     35 assertEq(true, reactions[0].reject instanceof Debugger.Object);
     36 assertEq(true, reactions[0].reject.callable);
     37 
     38 // Unfortunately, this is not p2; it's the promise returned by the internal call
     39 // to `then` that attached the reaction record to p. See bug 1603575 for ideas
     40 // about how to actually retrieve p2.
     41 assertEq(true, reactions[0].result instanceof Debugger.Object);
     42 assertEq(reactions[0].result.class, "Promise");
     43 assertEq(true, reactions[0].result !== DOp2);