summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Promise/any/new-reject-function.js
blob: e99d0272815d39c175b21bcdb380a9bf7a705052 (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
// Copyright (C) 2019 Leo Balter, 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-performpromiseany
description: >
  Each Promise.any element is called with a new Promise.any Reject Element function.
info: |
  Runtime Semantics: PerformPromiseAny ( iteratorRecord, constructor, resultCapability )

  ...
  k. Let rejectElement be ! CreateBuiltinFunction(steps, « [[AlreadyCalled]], [[Index]], [[Errors]], [[Capability]], [[RemainingElements]] »).
  ...
  r. Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], rejectElement »).
  ...

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

function rejectFunction() {}

function Constructor(executor) {
  executor(rejectFunction, Test262Error.thrower);
}
Constructor.resolve = function(v) {
  return v;
};

var callCount1 = 0;
var callCount2 = 0;
var p1OnRejected;

var p1 = {
  then(_, onRejected) {
    callCount1 += 1;
    p1OnRejected = onRejected;
    assert.notSameValue(onRejected, rejectFunction, 'p1.then');
  }
};
var p2 = {
  then(_, onRejected) {
    callCount2 += 1;
    assert.notSameValue(onRejected, rejectFunction, 'p2.then');
    assert.notSameValue(onRejected, p1OnRejected, 'p1.onRejected != p2.onRejected');
  }
};

Promise.any.call(Constructor, [p1, p2]);
assert.sameValue(callCount1, 1, 'p1.then call count');
assert.sameValue(callCount2, 1, 'p2.then call count');


reportCompare(0, 0);