tor-browser

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

reject-deferred.js (1512B)


      1 // |reftest| async
      2 // Copyright (C) 2019 Leo Balter. All rights reserved.
      3 // This code is governed by the BSD license found in the LICENSE file.
      4 /*---
      5 description: Rejecting through deferred invocation of the provided resolving function
      6 esid: sec-promise.allsettled
      7 info: |
      8  6. Let result be PerformPromiseAllSettled(iteratorRecord, C, promiseCapability).
      9 
     10  Runtime Semantics: PerformPromiseAllSettled
     11  
     12  6. Repeat
     13    ...
     14    z. Perform ? Invoke(nextPromise, "then", « resolveElement, rejectElement »).
     15 
     16  Promise.allSettled Reject Element Functions
     17 
     18  9. Let obj be ! ObjectCreate(%ObjectPrototype%).
     19  10. Perform ! CreateDataProperty(obj, "status", "rejected").
     20  11. Perform ! CreateDataProperty(obj, "reason", x).
     21  12. Set values[index] to be obj.
     22  13. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1.
     23  14. If remainingElementsCount.[[Value]] is 0, then
     24    a. Let valuesArray be CreateArrayFromList(values).
     25    b. Return ? Call(promiseCapability.[[Resolve]], undefined, « valuesArray »).
     26 flags: [async]
     27 features: [Promise.allSettled]
     28 ---*/
     29 
     30 var simulation = {};
     31 var thenable = {
     32  then(_, reject) {
     33    new Promise(function(resolve) {
     34        resolve();
     35      })
     36      .then(function() {
     37        reject(simulation);
     38      });
     39  }
     40 };
     41 
     42 Promise.allSettled([thenable])
     43  .then((settleds) => {
     44    assert.sameValue(settleds.length, 1);
     45    assert.sameValue(settleds[0].status, 'rejected');
     46    assert.sameValue(settleds[0].reason, simulation);
     47  }).then($DONE, $DONE);