| 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 an object with a "poisoned" `then` property |
| 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 |
a. Return RejectPromise(promise, then.[[value]]). |
| 43 |
flags: [async] |
| 44 |
---*/ |
| 45 |
|
| 46 |
var value = {}; |
| 47 |
var promise; |
| 48 |
|
| 49 |
try { |
| 50 |
Object.defineProperty(Array.prototype, 'then', { |
| 51 |
get: function() { |
| 52 |
throw value; |
| 53 |
}, |
| 54 |
configurable: true |
| 55 |
}); |
| 56 |
|
| 57 |
promise = Promise.all([]); |
| 58 |
} finally { |
| 59 |
delete Array.prototype.then; |
| 60 |
} |
| 61 |
|
| 62 |
promise.then(function() { |
| 63 |
$DONE('The promise should not be fulfilled.'); |
| 64 |
}, function(val) { |
| 65 |
if (val !== value) { |
| 66 |
$DONE('The promise should be rejected with the expected value.'); |
| 67 |
return; |
| 68 |
} |
| 69 |
|
| 70 |
$DONE(); |
| 71 |
}); |