tor-browser

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

enqueue-promise-reactions.js (1018B)


      1 // |reftest| skip-if(!xulRuntime.shell) -- needs getSelfHostedValue and drainJobQueue
      2 
      3 function onResolved(val) {
      4    result = 'resolved with ' + val;
      5 }
      6 
      7 function onRejected(val) {
      8    result = 'rejected with ' + val;
      9 }
     10 
     11 // Replacing `Promise#then` shouldn't affect addPromiseReactions.
     12 Promise.prototype.then = 1;
     13 
     14 // Replacing Promise@@species shouldn't affect addPromiseReactions.
     15 Object.defineProperty(Promise, Symbol.species, { get: function(){} });
     16 
     17 // Replacing `Promise` shouldn't affect addPromiseReactions.
     18 let PromiseCtor = Promise;
     19 Promise = {};
     20 
     21 let result;
     22 let res;
     23 let rej;
     24 let p = new PromiseCtor(function(res_, rej_) { res = res_; rej = rej_; });
     25 
     26 addPromiseReactions(p, onResolved, onRejected);
     27 res('foo');
     28 drainJobQueue();
     29 assertEq(result, 'resolved with foo')
     30 
     31 p = new PromiseCtor(function(res_, rej_) { res = res_; rej = rej_; });
     32 
     33 addPromiseReactions(p, onResolved, onRejected);
     34 rej('bar');
     35 drainJobQueue();
     36 assertEq(result, 'rejected with bar');
     37 
     38 this.reportCompare && reportCompare(true,true);