summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Promise/any/reject-ignored-deferred.js
blob: 4e98e1ab013909b9b7cff5a74ffb1887bd4886b6 (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
// |reftest| async
// 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
description: >
    Resolved promises ignore rejections through deferred invocation of the
    provided resolving function
info: |
  Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability).

  Runtime Semantics: PerformPromiseAny

  ...
  Let remainingElementsCount be a new Record { [[value]]: 1 }.
  ...
  8.d ...
    ii. Set remainingElementsCount.[[value]] to remainingElementsCount.[[value]] − 1.
    iii. If remainingElementsCount.[[value]] is 0,
      1. Let error be a newly created AggregateError object.
      2. Perform ! DefinePropertyOrThrow(error, "errors", Property Descriptor { [[Configurable]]: true, [[Enumerable]]: false, [[Writable]]: true, [[Value]]: errors }).
      3. Return ThrowCompletion(error).
  ...

  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.
  ...

flags: [async]
features: [Promise.any, arrow-function]
---*/

let callCount = 0;
let fulfiller = {
  then(resolve) {
    new Promise((resolve) => {
        callCount++;
        resolve();
      })
      .then(() => {
        callCount++;
        resolve();
      });
  }
};
let rejector = {
  then(resolve, reject) {
    new Promise((resolve) => {
        callCount++;
        resolve();
      })
      .then(() => {
        callCount++;
        resolve();
        reject();
      });
  }
};

Promise.all([fulfiller, rejector])
  .then(() => {
    assert.sameValue(callCount, 4, "callCount === 4");
    $DONE();
  }, () => {
    $DONE("The promise should not be rejected.");
  });