new-resolve-function.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright (C) 2015 André Bargull. All rights reserved.
  2. // This code is governed by the BSD license found in the LICENSE file.
  3. /*---
  4. es6id: 25.4.4.1.1
  5. description: >
  6. Each Promise.all element is called with a new Promise.all Resolve Element function.
  7. info: |
  8. Runtime Semantics: PerformPromiseAll( iteratorRecord, constructor, resultCapability)
  9. ...
  10. k. Let resolveElement be a new built-in function object as defined in Promise.all Resolve Element Functions.
  11. ...
  12. r. Let result be Invoke(nextPromise, "then", «resolveElement, resultCapability.[[Reject]]»).
  13. ...
  14. ---*/
  15. function resolveFunction() {}
  16. function Constructor(executor) {
  17. executor(resolveFunction, Test262Error.thrower);
  18. }
  19. Constructor.resolve = function(v) {
  20. return v;
  21. };
  22. var callCount1 = 0,
  23. callCount2 = 0;
  24. var p1OnFulfilled;
  25. var p1 = {
  26. then: function(onFulfilled, onRejected) {
  27. callCount1 += 1;
  28. p1OnFulfilled = onFulfilled;
  29. assert.notSameValue(onFulfilled, resolveFunction, "p1.then");
  30. }
  31. };
  32. var p2 = {
  33. then: function(onFulfilled, onRejected) {
  34. callCount2 += 1;
  35. assert.notSameValue(onFulfilled, resolveFunction, "p2.then");
  36. assert.notSameValue(onFulfilled, p1OnFulfilled, "p1.onFulfilled != p2.onFulfilled");
  37. }
  38. };
  39. Promise.all.call(Constructor, [p1, p2]);
  40. assert.sameValue(callCount1, 1, "p1.then call count");
  41. assert.sameValue(callCount2, 1, "p2.then call count");