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

/*---
esid: sec-promise.any-reject-element-functions
description: >
  Cannot change result value of rejected Promise.any element after Promise.any() returned.
info: |
  Promise.any Reject Element Functions

  Let alreadyCalled be the value of F's [[AlreadyCalled]] internal slot.
  If alreadyCalled.[[value]] is true, return undefined.
  Set alreadyCalled.[[value]] to true.

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

let callCount = 0;
let errorArray;

function Constructor(executor) {
  executor(Test262Error.thrower, (error) => {
    callCount++;
    errorArray = error.errors;
  });
}
Constructor.resolve = function(v) {
  return v;
};

let p1OnRejected;

let p1 = {
  then(onFulfilled, onRejected) {
    p1OnRejected = onRejected;
    onRejected("onRejectedValue");
  }
};

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

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

assert.sameValue(callCount, 1, "callCount after call to any()");
assert.sameValue(errorArray[0], "onRejectedValue", "errorArray after call to any()");

p1OnRejected("unexpectedonRejectedValue");

assert.sameValue(errorArray[0], "onRejectedValue", "errorArray[0] === 'onRejectedValue', after call to p1OnRejected()");

reportCompare(0, 0);