summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Promise/any/invoke-resolve-return.js
blob: ba5bd6be67aab150330242d814f5f1ae57d96942 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Use of the value returned by the constructor's `resolve` method.
esid: sec-promise.any
info: |
  Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability).

  PerformPromiseAny

  Repeat
    ...
    i. Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »).
    ...
    r. Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], rejectElement »).

features: [Promise.any]
---*/

let originalCallCount = 0;
let newCallCount = 0;
let P = function(executor) {
  executor(function() {}, function() {});
};
P.resolve = function() {
  return newThenable;
};

let originalThenable = {
  then() {
    originalCallCount += 1;
  }
};
let newThenable = {
  then() {
    newCallCount += 1;
  }
};

Promise.any.call(P, [originalThenable]);

assert.sameValue(originalCallCount, 0, 'original `then` method not invoked');
assert.sameValue(newCallCount, 1, 'new `then` method invoked exactly once');

reportCompare(0, 0);