Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/built-ins/Promise/resolve-prms-cstm-then-immed.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 Resolving with a resolved Promise instance whose `then` method has been
6 overridden from within the executor function
7 es6id: 25.4.3.1
8 info: |
9 [...]
10 8. Let resolvingFunctions be CreateResolvingFunctions(promise).
11 9. Let completion be Call(executor, undefined,
12 «resolvingFunctions.[[Resolve]], resolvingFunctions.[[Reject]]»).
13
14 25.4.1.3.2 Promise Resolve Functions
15 [...]
16 8. Let then be Get(resolution, "then").
17 9. If then is an abrupt completion, then
18 [...]
19 10. Let thenAction be then.[[value]].
20 11. If IsCallable(thenAction) is false, then
21 [...]
22 12. Perform EnqueueJob ("PromiseJobs", PromiseResolveThenableJob,
23 «promise, resolution, thenAction»)
24 flags: [async]
25 ---*/
26
27 var returnValue = null;
28 var value = {};
29 var lateCallCount = 0;
30 var thenable = new Promise(function(resolve) {
31 resolve();
32 });
33
34 thenable.then = function(resolve) {
35 resolve(value);
36 };
37
38 var promise = new Promise(function(resolve) {
39 returnValue = resolve(thenable);
40 });
41
42 assert.sameValue(returnValue, undefined, '"resolve" return value');
43
44 thenable.then = function() {
45 lateCallCount += 1;
46 };
47
48 promise.then(function(val) {
49 if (val !== value) {
50 $DONE('The promise should be fulfilled with the provided value.');
51 return;
52 }
53
54 if (lateCallCount > 0) {
55 $DONE('The `then` method should be executed synchronously.');
56 }
57
58 $DONE();
59 }, function() {
60 $DONE('The promise should not be rejected.');
61 });