tor-browser

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

resolved-sequence-with-rejections.js (1745B)


      1 // |reftest| async
      2 // Copyright (C) 2020 Rick Waldron. All rights reserved.
      3 // This code is governed by the BSD license found in the LICENSE file.
      4 
      5 /*---
      6 esid: sec-promise.race
      7 description: Resolution ticks are set in a predictable sequence
      8 info: |
      9  PerformPromiseRace
     10 
     11  Repeat,
     12    Let next be IteratorStep(iteratorRecord).
     13    If next is an abrupt completion, set iteratorRecord.[[Done]] to true.
     14    ReturnIfAbrupt(next).
     15    If next is false, then
     16      Set iteratorRecord.[[Done]] to true.
     17      Return resultCapability.[[Promise]].
     18    Let nextValue be IteratorValue(next).
     19    If nextValue is an abrupt completion, set iteratorRecord.[[Done]] to true.
     20    ReturnIfAbrupt(nextValue).
     21    Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »).
     22    Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], resultCapability.[[Reject]] »).
     23 
     24 flags: [async]
     25 includes: [compareArray.js, promiseHelper.js]
     26 ---*/
     27 
     28 let a = new Promise((_, reject) => reject('a'));
     29 let b = new Promise((_, reject) => reject('b'));
     30 let sequence = [1];
     31 Promise.all([
     32  a.catch(() => {
     33    sequence.push(3);
     34    assert.sameValue(sequence.length, 3);
     35    return checkSequence(sequence, 'Expected to be called first.');
     36  }),
     37  Promise.race([a, b]).catch(() => {
     38    sequence.push(5);
     39    assert.sameValue(sequence.length, 5);
     40    return checkSequence(sequence, 'Expected to be called third.');
     41  }),
     42  b.catch(() => {
     43    sequence.push(4);
     44    assert.sameValue(sequence.length, 4);
     45    return checkSequence(sequence, 'Expected to be called second.');
     46  })
     47 ]).then(result => {
     48  assert.compareArray(result, [true, true, true]);
     49  assert.sameValue(sequence.length, 5);
     50  checkSequence(sequence);
     51 }).then($DONE, $DONE);
     52 
     53 sequence.push(2);