test262/test/built-ins/Promise/any/capability-reject-throws-no...

69 lines
1.6 KiB
JavaScript
Raw Normal View History

2020-05-20 19:26:25 +02:00
// Copyright (C) 2020 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-promise.any
description: >
Iterator is not closed when the "resolve" capability returns an abrupt
completion.
info: |
Let C be the this value.
Let promiseCapability be ? NewPromiseCapability(C).
Let iteratorRecord be GetIterator(iterable).
IfAbruptRejectPromise(iteratorRecord, promiseCapability).
Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability).
If result is an abrupt completion, then
If iteratorRecord.[[Done]] is false, set result to IteratorClose(iteratorRecord, result).
IfAbruptRejectPromise(result, promiseCapability).
Return Completion(result).
2020-06-03 18:54:30 +02:00
flags: [async]
2020-05-20 19:26:25 +02:00
features: [Promise.any, Symbol.iterator]
---*/
2020-06-03 18:54:30 +02:00
let callCount = 0;
2020-05-20 19:26:25 +02:00
let nextCount = 0;
let returnCount = 0;
2020-06-03 18:54:30 +02:00
let iter = {
[Symbol.iterator]() {
callCount++;
return {
next() {
callCount++
nextCount++;
return {
done: true
};
},
return() {
callCount++;
returnCount++;
return {};
}
};
}
2020-05-20 19:26:25 +02:00
};
2020-06-03 18:54:30 +02:00
function P(executor) {
callCount++;
return new Promise((_, reject) => {
callCount++;
executor(() => {
callCount++;
$ERROR();
}, () => {
callCount++;
reject(new Test262Error('reject throws'));
2020-05-20 19:26:25 +02:00
});
});
};
P.resolve = Promise.resolve;
2020-06-03 18:54:30 +02:00
Promise.any.call(P, iter).then(
() => {
$DONE('The promise should be rejected.');
}, (reason) => {
assert.sameValue(nextCount, 1);
assert.sameValue(returnCount, 0);
assert.sameValue(callCount, 5);
}).then($DONE, $DONE);