Debian Codegraph @

js/src/tests/test262/built-ins/Promise/resolve-thenable-deferred.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: >
6 Resolving with a thenable object value after execution of the executor
7 function
8 es6id: 25.4.3.1
9 info: |
10 [...]
11 8. Let resolvingFunctions be CreateResolvingFunctions(promise).
12 9. Let completion be Call(executor, undefined,
13 «resolvingFunctions.[[Resolve]], resolvingFunctions.[[Reject]]»).
14
15 25.4.1.3.2 Promise Resolve Functions
16 [...]
17 8. Let then be Get(resolution, "then").
18 9. If then is an abrupt completion, then
19 [...]
20 10. Let thenAction be then.[[value]].
21 11. If IsCallable(thenAction) is false, then
22 [...]
23 12. Perform EnqueueJob ("PromiseJobs", PromiseResolveThenableJob,
24 «promise, resolution, thenAction»)
25 flags: [async]
26 ---*/
27
28 var returnValue = null;
29 var value = {};
30 var resolve;
31 var thenable = new Promise(function(resolve) {
32 resolve(value);
33 });
34 var promise = new Promise(function(_resolve) {
35 resolve = _resolve;
36 });
37
38 promise.then(function(val) {
39 if (val !== value) {
40 $DONE('The promise should be fulfilled with the provided value.');
41 return;
42 }
43
44 $DONE();
45 }, function() {
46 $DONE('The promise should not be rejected.');
47 });
48
49 returnValue = resolve(thenable);
50
51 assert.sameValue(returnValue, undefined, '"resolve" return value');