tor-browser

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

reject-from-same-thenable.js (1659B)


      1 // Copyright (C) 2020 Rick Waldron. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 /*---
      4 description: Rejecting with a non-thenable object value
      5 esid: sec-promise.any
      6 info: |
      7  PerformPromiseAny
      8 
      9  Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] + 1.
     10  Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], rejectElement »).
     11 
     12  Promise.any Reject Element Functions
     13 
     14  Let alreadyCalled be F.[[AlreadyCalled]].
     15  If alreadyCalled.[[Value]] is true, return undefined.
     16  Set alreadyCalled.[[Value]] to true.
     17  ...
     18 features: [Promise.any]
     19 ---*/
     20 
     21 let callCount = 0;
     22 let error;
     23 
     24 function Constructor(executor) {
     25  function reject(result) {
     26    callCount += 1;
     27    error = result;
     28  }
     29  executor(() => {throw new Test262Error()}, reject);
     30 }
     31 Constructor.resolve = function(v) {
     32  return v;
     33 };
     34 
     35 let p1OnRejected, p2OnRejected, p3OnRejected;
     36 
     37 let p1 = {
     38  then(_, onRejected) {
     39    p1OnRejected = onRejected;
     40  }
     41 };
     42 let p2 = {
     43  then(_, onRejected) {
     44    p2OnRejected = onRejected;
     45  }
     46 };
     47 let p3 = {
     48  then(_, onRejected) {
     49    p3OnRejected = onRejected;
     50  }
     51 };
     52 
     53 assert.sameValue(callCount, 0, 'callCount before call to any()');
     54 
     55 Promise.any.call(Constructor, [p1, p2, p3]);
     56 
     57 assert.sameValue(callCount, 0, 'callCount after call to any()');
     58 
     59 p1OnRejected('p1-rejection');
     60 p1OnRejected('p1-rejection-unexpected-1');
     61 p1OnRejected('p1-rejection-unexpected-2');
     62 
     63 assert.sameValue(callCount, 0, 'callCount after resolving p1');
     64 
     65 p2OnRejected('p2-rejection');
     66 p3OnRejected('p3-rejection');
     67 
     68 assert.sameValue(callCount, 1, 'callCount after resolving all elements');
     69 
     70 reportCompare(0, 0);