tor-browser

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

Object-getPromiseReactions-02.js (2014B)


      1 // Debugger.Object.protoype.getPromiseReactions reports directly resolved promises.
      2 
      3 load(libdir + 'array-compare.js');
      4 
      5 var g = newGlobal({ newCompartment: true });
      6 var dbg = new Debugger;
      7 var DOg = dbg.addDebuggee(g);
      8 
      9 g.eval(`
     10    var pResolve, pReject;
     11    var p = new Promise((resolve, reject) => { pResolve = resolve; pReject = reject });
     12    var p2 = new Promise((resolve, reject) => { resolve(p); });
     13    var p3 = new Promise((resolve, reject) => { resolve(p); });
     14    var p4 = new Promise((resolve, reject) => { resolve(p2); });
     15 `);
     16 
     17 var [DOp, DOp2, DOp3, DOp4] = [g.p, g.p2, g.p3, g.p4].map(p => DOg.makeDebuggeeValue(p));
     18 
     19 // Since the standard resolving functions enqueue a job to do the `then` call,
     20 // none of the reactions should be visible yet.
     21 assertEq(true, arraysEqual(DOp.getPromiseReactions(), []));
     22 assertEq(true, arraysEqual(DOp2.getPromiseReactions(), []));
     23 assertEq(true, arraysEqual(DOp3.getPromiseReactions(), []));
     24 assertEq(true, arraysEqual(DOp4.getPromiseReactions(), []));
     25 
     26 // This should let them all appear in place.
     27 drainJobQueue();
     28 
     29 assertEq(true, arraysEqual(DOp.getPromiseReactions(), [DOp2, DOp3]));
     30 assertEq(true, arraysEqual(DOp2.getPromiseReactions(), [DOp4]));
     31 assertEq(true, arraysEqual(DOp3.getPromiseReactions(), []));
     32 assertEq(true, arraysEqual(DOp4.getPromiseReactions(), []));
     33 
     34 // Resolving the initial promise should kick off its reactions, but propagating
     35 // that the rest of the way requires microtasks.
     36 g.pResolve(42);
     37 
     38 assertEq(true, arraysEqual(DOp.getPromiseReactions(), []));
     39 assertEq(true, arraysEqual(DOp2.getPromiseReactions(), [DOp4]));
     40 assertEq(true, arraysEqual(DOp3.getPromiseReactions(), []));
     41 assertEq(true, arraysEqual(DOp4.getPromiseReactions(), []));
     42 
     43 // Let the propagation complete.
     44 drainJobQueue();
     45 
     46 assertEq(true, arraysEqual(DOp.getPromiseReactions(), []));
     47 assertEq(true, arraysEqual(DOp2.getPromiseReactions(), []));
     48 assertEq(true, arraysEqual(DOp3.getPromiseReactions(), []));
     49 assertEq(true, arraysEqual(DOp4.getPromiseReactions(), []));