tor-browser

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

resolved-then-catch-finally.js (1472B)


      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: >
      8  Resolution the first resolved promise
      9 info: |
     10  PerformPromiseRace
     11 
     12  Repeat,
     13    Let next be IteratorStep(iteratorRecord).
     14    If next is an abrupt completion, set iteratorRecord.[[Done]] to true.
     15    ReturnIfAbrupt(next).
     16    If next is false, then
     17      Set iteratorRecord.[[Done]] to true.
     18      Return resultCapability.[[Promise]].
     19    Let nextValue be IteratorValue(next).
     20    If nextValue is an abrupt completion, set iteratorRecord.[[Done]] to true.
     21    ReturnIfAbrupt(nextValue).
     22    Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »).
     23    Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], resultCapability.[[Reject]] »).
     24 
     25 flags: [async]
     26 ---*/
     27 
     28 let a = Promise.reject('a').catch((v) => v);
     29 let b = Promise.resolve('b').then((v) => { throw v });
     30 let c = Promise.reject('c').then((v) => { throw v; });
     31 let d = Promise.resolve('d').finally((v) => v);
     32 let e = Promise.reject('e').finally((v) => v);
     33 let f = Promise.resolve('f').finally((v) => { throw v; });
     34 let g = Promise.reject('g').finally((v) => { throw v; });
     35 let h = Promise.reject('h').then((v) => v, () => 'j');
     36 let i = Promise.resolve('i').then(v => v);
     37 
     38 Promise.race([a, b, c, d, e, f, g, h, i]).then(winner => {
     39  assert.sameValue(winner, 'a');
     40 }).then($DONE, $DONE);