Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/built-ins/Promise/race/reject-ignored-deferred.js

raw
1 // Copyright (C) 2016 the V8 project authors. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3 /*---
4 description: >
5 Resolved promises ignore rejections through deferred invocation of the
6 provided resolving function
7 es6id: 25.4.4.3
8 info: |
9 [...]
10 6. Let promiseCapability be NewPromiseCapability(C).
11 [...]
12 11. Let result be PerformPromiseRace(iteratorRecord, promiseCapability, C).
13 [...]
14
15 25.4.4.3.1 Runtime Semantics: PerformPromiseRace
16 1. Repeat
17 [...]
18 j. Let result be Invoke(nextPromise, "then",
19 «promiseCapability.[[Resolve]], promiseCapability.[[Reject]]»).
20
21 25.4.1.3.1 Promise Reject Functions
22 [...]
23 2. Let promise be the value of F's [[Promise]] internal slot.
24 3. Let alreadyResolved be the value of F's [[AlreadyResolved]] internal
25 slot.
26 4. If alreadyResolved.[[value]] is true, return undefined.
27 flags: [async]
28 ---*/
29
30 var fulfiller = {
31 then: function(resolve) {
32 new Promise(function(resolve) {
33 resolve();
34 })
35 .then(function() {
36 resolve();
37 });
38 }
39 };
40 var rejector = {
41 then: function(_, reject) {
42 new Promise(function(resolve) {
43 resolve();
44 })
45 .then(function() {
46 reject();
47 });
48 }
49 };
50
51 Promise.race([fulfiller, rejector])
52 .then(function() {
53 $DONE();
54 }, function() {
55 $DONE('The promise should not be rejected.');
56 });