tor-browser

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

resolved-sequence.js (1489B)


      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 /*---
      6 esid: sec-promise.allsettled
      7 description: Resolution ticks are set in a predictable sequence
      8 info: |
      9  Runtime Semantics: PerformPromiseAllSettled ( iteratorRecord, constructor, resultCapability )
     10 
     11  4. Let remainingElementsCount be a new Record { [[Value]]: 1 }.
     12  ...
     13  6.d ...
     14    ii. Set remainingElementsCount.[[value]] to remainingElementsCount.[[value]] − 1.
     15    iii. If remainingElementsCount.[[value]] is 0, then
     16      1. Let valuesArray be CreateArrayFromList(values).
     17      2. Perform ? Call(resultCapability.[[Resolve]], undefined, « valuesArray »).
     18  ...
     19 flags: [async]
     20 includes: [promiseHelper.js]
     21 features: [Promise.allSettled]
     22 ---*/
     23 
     24 var sequence = [];
     25 
     26 var p1 = new Promise(function(resolve) {
     27  resolve(1);
     28 });
     29 var p2 = new Promise(function(resolve) {
     30  resolve(2);
     31 });
     32 
     33 sequence.push(1);
     34 
     35 p1.then(function() {
     36  sequence.push(3);
     37  assert.sameValue(sequence.length, 3);
     38  checkSequence(sequence, 'Expected to be called first.');
     39 }).catch($DONE);
     40 
     41 Promise.allSettled([p1, p2]).then(function() {
     42  sequence.push(5);
     43  assert.sameValue(sequence.length, 5);
     44  checkSequence(sequence, 'Expected to be called third.');
     45 }).then($DONE, $DONE);
     46 
     47 p2.then(function() {
     48  sequence.push(4);
     49  assert.sameValue(sequence.length, 4);
     50  checkSequence(sequence, 'Expected to be called second.');
     51 }).catch($DONE);
     52 
     53 sequence.push(2);