summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Promise/any/reject-from-same-thenable.js
blob: 9c55285599d0f643b8785d3f314d5bb530da0d20 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Rejecting with a non-thenable object value
esid: sec-promise.any
info: |
  PerformPromiseAny

  Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] + 1.
  Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], rejectElement »).

  Promise.any Reject Element Functions

  Let alreadyCalled be F.[[AlreadyCalled]].
  If alreadyCalled.[[Value]] is true, return undefined.
  Set alreadyCalled.[[Value]] to true.
  ...
features: [Promise.any]
---*/

let callCount = 0;
let error;

function Constructor(executor) {
  function reject(result) {
    callCount += 1;
    error = result;
  }
  executor(() => {throw new Test262Error()}, reject);
}
Constructor.resolve = function(v) {
  return v;
};

let p1OnRejected, p2OnRejected, p3OnRejected;

let p1 = {
  then(_, onRejected) {
    p1OnRejected = onRejected;
  }
};
let p2 = {
  then(_, onRejected) {
    p2OnRejected = onRejected;
  }
};
let p3 = {
  then(_, onRejected) {
    p3OnRejected = onRejected;
  }
};

assert.sameValue(callCount, 0, 'callCount before call to any()');

Promise.any.call(Constructor, [p1, p2, p3]);

assert.sameValue(callCount, 0, 'callCount after call to any()');

p1OnRejected('p1-rejection');
p1OnRejected('p1-rejection-unexpected-1');
p1OnRejected('p1-rejection-unexpected-2');

assert.sameValue(callCount, 0, 'callCount after resolving p1');

p2OnRejected('p2-rejection');
p3OnRejected('p3-rejection');

assert.sameValue(callCount, 1, 'callCount after resolving all elements');

reportCompare(0, 0);