Debian Codegraph @

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