tor-browser

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

promise-job-global.js (844B)


      1 // Test that jobs added to the promise job queue have a global that's consistent
      2 // with and without same-compartment realms.
      3 
      4 var g1 = newGlobal();
      5 var g2 = newGlobal({sameCompartmentAs: this});
      6 
      7 // EnqueuePromiseReactionJob, handler is a primitive.
      8 // Job's global is the reaction's global.
      9 function test1(g) {
     10    var resolve;
     11    var p = new Promise(res => { resolve = res; });
     12    g.Promise.prototype.then.call(p, 1);
     13    resolve();
     14    assertEq(globalOfFirstJobInQueue(), g);
     15    drainJobQueue();
     16 }
     17 test1(g1);
     18 test1(g2);
     19 
     20 // EnqueuePromiseReactionJob, handler is an object.
     21 // Job's global is the handler's global.
     22 function test2(g) {
     23    var resolve;
     24    var p = new Promise(res => { resolve = res; });
     25    p.then(new g.Function());
     26    resolve();
     27    assertEq(globalOfFirstJobInQueue(), g);
     28    drainJobQueue();
     29 }
     30 test2(g1);
     31 test2(g2);