tor-browser

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

test_thenable_vs_promise_ordering.html (1142B)


      1 <!DOCTYPE html>
      2 <meta charset=utf-8>
      3 <title>Test for promise resolution ordering with thenables and promises</title>
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <div id="log"></div>
      7 <script>
      8 /* global async_test, assert_true, assert_equals */
      9 
     10 var t = async_test("A promise resolved first (with a thenable) should trigger its callbacks before a promise resolved second (with a promise).");
     11 t.step(function() {
     12  var customThenCalled = false;
     13  var p0 = Promise.resolve();
     14  p0.then = function(resolved, rejected) {
     15    customThenCalled = true;
     16    Promise.prototype.then.call(this, resolved, rejected);
     17  };
     18  var p1 = new Promise(function(r) { r(p0); });
     19  delete p0.then;
     20  var p2 = new Promise(function(r) { r(p0); });
     21  var resolutionOrder = "";
     22  Promise.all([ p1.then(function() { resolutionOrder += "1"; }),
     23                p2.then(function() { resolutionOrder += "2"; }) ])
     24         .then(t.step_func_done(function() {
     25           assert_true(customThenCalled, "Should have called custom then");
     26           assert_equals(resolutionOrder, "12");
     27         }));
     28 });
     29 </script>