Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/built-ins/Promise/all/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.1
6 info: |
7 [...]
8 6. Let promiseCapability be NewPromiseCapability(C).
9 [...]
10 11. Let result be PerformPromiseAll(iteratorRecord, C, promiseCapability).
11 [...]
12
13 25.4.4.1.1 Runtime Semantics: PerformPromiseAll
14 [...]
15 6. Repeat
16 [...]
17 d. If next is false,
18 [...]
19 iii. If remainingElementsCount.[[value]] is 0,
20 1. Let valuesArray be CreateArrayFromList(values).
21 2. Let resolveResult be Call(resultCapability.[[Resolve]],
22 undefined, «valuesArray»).
23 3. ReturnIfAbrupt(resolveResult)
24 iv. Return resultCapability.[[Promise]].
25
26 7.3.16 CreateArrayFromList (elements)
27 [...]
28 2. Let array be ArrayCreate(0) (see 9.4.2.2).
29
30 9.4.2.2 ArrayCreate(length, proto)
31 [...]
32 4. If the proto argument was not passed, let proto be the intrinsic object
33 %ArrayPrototype%.
34 5. Let A be a newly created Array exotic object.
35 [...]
36 8. Set the [[Prototype]] internal slot of A to proto.
37
38 25.4.1.3.2 Promise Resolve Functions
39 [...]
40 8. Let then be Get(resolution, "then").
41 9. If then is an abrupt completion, then
42 [...]
43 10. Let thenAction be then.[[value]].
44 11. If IsCallable(thenAction) is false, then
45 [...]
46 12. Perform EnqueueJob ("PromiseJobs", PromiseResolveThenableJob,
47 «promise, resolution, thenAction»)
48 flags: [async]
49 ---*/
50
51 var value = {};
52 var promise;
53
54 try {
55 Array.prototype.then = function(resolve) {
56 resolve(value);
57 };
58
59 promise = Promise.all([]);
60 } finally {
61 delete Array.prototype.then;
62 }
63
64 promise.then(function(val) {
65 if (val !== value) {
66 $DONE('The promise should be resolved with the expected value.');
67 return;
68 }
69
70 $DONE();
71 }, function() {
72 $DONE('The promise should not be rejected.');
73 });