summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Promise/allSettled/reject-element-function-multiple-calls.js
blob: 2cbc89007d60cad4338859e9e54f6858141ba600 (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
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-performpromiseallsettled
description: >
  Cannot tamper with remainingElementsCount when Promise.allSettled reject element function is called multiple times.
info: |
  Runtime Semantics: PerformPromiseAllSettled ( iteratorRecord, constructor, resultCapability, )

  If alreadyCalled.[[Value]] is true, return undefined.

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

let rejectCallCount = 0;
let returnValue = {};
let error = new Test262Error();

function Constructor(executor) {
  function reject(value) {
    assert.sameValue(value, error);
    rejectCallCount += 1;
    return returnValue;
  }
  executor(() => {throw error}, reject);
}
Constructor.resolve = function(v) {
  return v;
};
Constructor.reject = function(v) {
  return v;
};

let pOnRejected;

let p = {
  then(onResolved, onRejected) {
    pOnRejected = onRejected;
    onResolved();
  }
};

assert.sameValue(rejectCallCount, 0, 'rejectCallCount before call to allSettled()');

Promise.allSettled.call(Constructor, [p]);

assert.sameValue(rejectCallCount, 1, 'rejectCallCount after call to allSettled()');
assert.sameValue(pOnRejected(), undefined);
assert.sameValue(rejectCallCount, 1, 'rejectCallCount after call to pOnRejected()');
pOnRejected();
assert.sameValue(rejectCallCount, 1, 'rejectCallCount after call to pOnRejected()');



reportCompare(0, 0);