tor-browser

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

invoke-resolve-get-once-no-calls.js (1479B)


      1 // |reftest| async
      2 // Copyright (C) 2019 Leo Balter, 2020 Rick Waldron. All rights reserved.
      3 // This code is governed by the BSD license found in the LICENSE file.
      4 
      5 /*---
      6 description: >
      7  Gets constructor's `resolve` method once from zero to many invocations.
      8 esid: sec-promise.any
      9 info: |
     10  5. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability).
     11  6. If result is an abrupt completion, then
     12    a. If iteratorRecord.[[Done]] is false, set result to IteratorClose(iteratorRecord, result).
     13    b. IfAbruptRejectPromise(result, promiseCapability).
     14 
     15  Runtime Semantics: PerformPromiseAny
     16 
     17  6. Let promiseResolve be ? Get(constructor, "resolve").
     18  7. If ! IsCallable(promiseResolve) is false, throw a TypeError exception.
     19  8. Repeat
     20    ...
     21    i. Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »).
     22 
     23 flags: [async]
     24 features: [Promise.any, arrow-function, destructuring-binding]
     25 ---*/
     26 
     27 let boundPromiseResolve = Promise.resolve.bind(Promise);
     28 let getCount = 0;
     29 let callCount = 0;
     30 
     31 Object.defineProperty(Promise, 'resolve', {
     32  configurable: true,
     33  get() {
     34    getCount += 1;
     35    return function(...args) {
     36      callCount += 1;
     37      return boundPromiseResolve(...args);
     38    };
     39  }
     40 });
     41 
     42 Promise.any([]).then(() => {
     43    $DONE('The promise should be rejected, but was resolved');
     44  }, ({errors}) => {
     45    assert.sameValue(getCount, 1);
     46    assert.sameValue(callCount, 0);
     47    assert.sameValue(errors.length, 0);
     48  }).then($DONE, $DONE);