Debian Codegraph @

js/src/tests/test262/built-ins/Promise/resolve-prms-cstm-then-immed.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 resolved Promise instance whose `then` method has been
7 overridden from within the executor 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 lateCallCount = 0;
31 var thenable = new Promise(function(resolve) {
32 resolve();
33 });
34
35 thenable.then = function(resolve) {
36 resolve(value);
37 };
38
39 var promise = new Promise(function(resolve) {
40 returnValue = resolve(thenable);
41 });
42
43 assert.sameValue(returnValue, undefined, '"resolve" return value');
44
45 thenable.then = function() {
46 lateCallCount += 1;
47 };
48
49 promise.then(function(val) {
50 if (val !== value) {
51 $DONE('The promise should be fulfilled with the provided value.');
52 return;
53 }
54
55 if (lateCallCount > 0) {
56 $DONE('The `then` method should be executed synchronously.');
57 }
58
59 $DONE();
60 }, function() {
61 $DONE('The promise should not be rejected.');
62 });