Debian Codegraph @

js/src/tests/test262/built-ins/Promise/resolve-self.js

raw
1 // |reftest| async
2 // Copyright (C) 2016 the V8 project authors. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
4 /*---
5 description: Resolving with a reference to the promise itself
6 es6id: 25.4.3.1
7 info: |
8 [...]
9 8. Let resolvingFunctions be CreateResolvingFunctions(promise).
10 9. Let completion be Call(executor, undefined,
11 «resolvingFunctions.[[Resolve]], resolvingFunctions.[[Reject]]»).
12
13 25.4.1.3.2 Promise Resolve Functions
14 [...]
15 6. If SameValue(resolution, promise) is true, then
16 a. Let selfResolutionError be a newly created TypeError object.
17 b. Return RejectPromise(promise, selfResolutionError).
18 flags: [async]
19 ---*/
20
21 var returnValue = null;
22 var resolve;
23 var promise = new Promise(function(_resolve) {
24 resolve = _resolve;
25 });
26
27 promise.then(function() {
28 $DONE('The promise should not be fulfilled.');
29 }, function(reason) {
30 if (!reason) {
31 $DONE('The promise should be rejected with a value.');
32 return;
33 }
34
35 if (reason.constructor !== TypeError) {
36 $DONE('The promise should be rejected with a TypeError instance.');
37 return;
38 }
39
40 $DONE();
41 });
42
43 returnValue = resolve(promise);
44
45 assert.sameValue(returnValue, undefined, '"resolve" return value');