invoke-resolve-on-values-every-iteration-of-promise.js 944 B

12345678910111213141516171819202122232425262728293031323334
  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: >
  5. Invocation of the constructor's `resolve` method for iterable with non-promise values
  6. esid: sec-promise.allSettled
  7. info: |
  8. 5. Let result be PerformPromiseAllSettled(iteratorRecord, C, promiseCapability).
  9. Runtime Semantics: PerformPromiseAllSettled
  10. 8. Repeat
  11. ...
  12. i. Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »).
  13. flags: [async]
  14. features: [Promise.allSettled, arrow-function]
  15. ---*/
  16. let values = [1, 2, 3];
  17. let callCount = 0;
  18. let boundPromiseResolve = Promise.resolve.bind(Promise);
  19. Promise.resolve = function(...args) {
  20. callCount += 1;
  21. return boundPromiseResolve(...args);
  22. };
  23. Promise.allSettled(values)
  24. .then(() => {
  25. assert.sameValue(callCount, 3, '`Promise.resolve` invoked once for every iterated value');
  26. }).then($DONE, $DONE);