Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/built-ins/Promise/resolve/resolve-thenable.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: Resolving with a thenable object value
5 es6id: 25.4.4.5
6 info: |
7 [...]
8 6. Let resolveResult be Call(promiseCapability.[[Resolve]], undefined,
9 «x»).
10 [...]
11
12 25.4.1.3.2 Promise Resolve Functions
13 [...]
14 8. Let then be Get(resolution, "then").
15 9. If then is an abrupt completion, then
16 [...]
17 10. Let thenAction be then.[[value]].
18 11. If IsCallable(thenAction) is false, then
19 [...]
20 12. Perform EnqueueJob ("PromiseJobs", PromiseResolveThenableJob,
21 «promise, resolution, thenAction»)
22 flags: [async]
23 ---*/
24
25 var value = {};
26 var thenable = {
27 then: function(resolve) {
28 resolve(value);
29 }
30 };
31
32 Promise.resolve(thenable).then(function(val) {
33 if (val !== value) {
34 $DONE('The promise should be fulfilled with the provided value.');
35 return;
36 }
37
38 $DONE();
39 }, function() {
40 $DONE('The promise should not be rejected.');
41 });