summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Promise/prototype/then/rxn-handler-rejected-next.js
blob: d88d3e1a48450896a1d7b47eb7e4d6ec6d0560f3 (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
// |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.
/*---
description: All queued jobs should be executed in series
es6id: 25.4.2.1
info: |
    [...]
    7. If handlerResult is an abrupt completion, then
       a. Let status be Call(promiseCapability.[[Reject]], undefined,
          «handlerResult.[[value]]»).
       b. NextJob Completion(status).
    8. Let status be Call(promiseCapability.[[Resolve]], undefined,
       «handlerResult.[[value]]»).
    9. NextJob Completion(status).
flags: [async]
---*/

var promise = new Promise(function(_, reject) {
  reject();
});
var log = '';

promise.then(function() {
  log += 'A';
}, function() {
  log += 'a';
});

promise.then(function() {
  log += 'B';
}, function() {
  log += 'b';
});

promise.then(function() {
  log += 'C';
}, function() {
  log += 'c';
});

promise.then(function() {
  $DONE('This promise should not be fulfilled.');
}, function() {
  if (log !== 'abc') {
    $DONE(
      'Expected each "onFulfilled" handler to be invoked exactly once in series. ' +
      'Expected: abc. Actual: ' + log
    );
    return;
  }

  $DONE();
});