tor-browser

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

new-reject-function.js (1439B)


      1 // Copyright (C) 2019 Leo Balter, 2020 Rick Waldron. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 
      4 /*---
      5 esid: sec-performpromiseany
      6 description: >
      7  Each Promise.any element is called with a new Promise.any Reject Element function.
      8 info: |
      9  Runtime Semantics: PerformPromiseAny ( iteratorRecord, constructor, resultCapability )
     10 
     11  ...
     12  k. Let rejectElement be ! CreateBuiltinFunction(steps, « [[AlreadyCalled]], [[Index]], [[Errors]], [[Capability]], [[RemainingElements]] »).
     13  ...
     14  r. Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], rejectElement »).
     15  ...
     16 
     17 features: [Promise.any]
     18 ---*/
     19 
     20 function rejectFunction() {}
     21 
     22 function Constructor(executor) {
     23  executor(rejectFunction, Test262Error.thrower);
     24 }
     25 Constructor.resolve = function(v) {
     26  return v;
     27 };
     28 
     29 var callCount1 = 0;
     30 var callCount2 = 0;
     31 var p1OnRejected;
     32 
     33 var p1 = {
     34  then(_, onRejected) {
     35    callCount1 += 1;
     36    p1OnRejected = onRejected;
     37    assert.notSameValue(onRejected, rejectFunction, 'p1.then');
     38  }
     39 };
     40 var p2 = {
     41  then(_, onRejected) {
     42    callCount2 += 1;
     43    assert.notSameValue(onRejected, rejectFunction, 'p2.then');
     44    assert.notSameValue(onRejected, p1OnRejected, 'p1.onRejected != p2.onRejected');
     45  }
     46 };
     47 
     48 Promise.any.call(Constructor, [p1, p2]);
     49 assert.sameValue(callCount1, 1, 'p1.then call count');
     50 assert.sameValue(callCount2, 1, 'p2.then call count');
     51 
     52 
     53 reportCompare(0, 0);