| 1 |
// |reftest| async |
| 2 |
// Copyright (C) 2019 Leo Balter. All rights reserved. |
| 3 |
// This code is governed by the BSD license found in the LICENSE file. |
| 4 |
/*--- |
| 5 |
esid: sec-promise.allsettled |
| 6 |
description: > |
| 7 |
Promise is rejected when the "resolve" capability returns an abrupt |
| 8 |
completion. |
| 9 |
info: | |
| 10 |
... |
| 11 |
3. Let promiseCapability be ? NewPromiseCapability(C). |
| 12 |
... |
| 13 |
6. Let result be PerformPromiseAllSettled(iteratorRecord, C, promiseCapability). |
| 14 |
7. If result is an abrupt completion, then |
| 15 |
a. If iteratorRecord.[[Done]] is false, set result to IteratorClose(iteratorRecord, result). |
| 16 |
b. IfAbruptRejectPromise(result, promiseCapability). |
| 17 |
8. Return Completion(result). |
| 18 |
|
| 19 |
Runtime Semantics: PerformPromiseAllSettled |
| 20 |
|
| 21 |
... |
| 22 |
6. Repeat |
| 23 |
... |
| 24 |
d. If next is false, then |
| 25 |
... |
| 26 |
iii. If remainingElementsCount.[[Value]] is 0, then |
| 27 |
1. Let valuesArray be CreateArrayFromList(values). |
| 28 |
2. Perform ? Call(resultCapability.[[Resolve]], undefined, « valuesArray »). |
| 29 |
|
| 30 |
|
| 31 |
IfAbruptRejectPromise |
| 32 |
|
| 33 |
1. IfAbruptRejectPromise(value, capability). |
| 34 |
flags: [async] |
| 35 |
features: [Promise.allSettled] |
| 36 |
---*/ |
| 37 |
|
| 38 |
var thrown = new Test262Error(); |
| 39 |
var P = function(executor) { |
| 40 |
return new Promise(function(_, reject) { |
| 41 |
executor(function() { |
| 42 |
throw thrown; |
| 43 |
}, reject); |
| 44 |
}); |
| 45 |
}; |
| 46 |
|
| 47 |
P.resolve = function() { |
| 48 |
throw new Test262Error(); |
| 49 |
}; |
| 50 |
|
| 51 |
Promise.allSettled.call(P, []) |
| 52 |
.then(function() { |
| 53 |
$DONE('Promise incorrectly fulfilled.'); |
| 54 |
}, function(reason) { |
| 55 |
if (reason !== thrown) { |
| 56 |
$DONE('Promise rejected with incorrect "reason."'); |
| 57 |
return; |
| 58 |
} |
| 59 |
$DONE(); |
| 60 |
}); |