tor-browser

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

new-resolve-function.js (1479B)


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