summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Promise/any/reject-immed.js
blob: 33d445e1de4b952ce5dc189f752895ff9e10b831 (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
// |reftest| async
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-promise.any
description: Rejecting through immediate invocation of the provided resolving function
info: |
    ...
    Let promiseCapability be NewPromiseCapability(C).
    ...
    Let result be PerformPromiseAny(iteratorRecord, promiseCapability, C).
    ...

    Runtime Semantics: PerformPromiseAny
    ...
    8. Repeat
       ...
       r. Perform ? Invoke(nextPromise, "then",
          « resultCapability.[[Resolve]], rejectElement »).


    Promise.any Reject Element Functions
    ...
    6. Return RejectPromise(promise, reason).
flags: [async]
features: [Promise.any, arrow-function]
---*/

let callCount = 0;
let thenable = {
  then(_, reject) {
    callCount++;
    reject('reason');
  }
};

Promise.any([thenable])
  .then(() => {
    $DONE('The promise should not be fulfilled.');
  }, (error) => {
    assert.sameValue(callCount, 1, "callCount === 1");
    assert(error instanceof AggregateError, "error instanceof AggregateError");
    assert.sameValue(error.errors[0], "reason", "error.errors[0] === 'reason'");
    $DONE();
  });