test262/test/built-ins/Promise/any/iter-arg-is-poisoned.js

43 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-11-27 22:07:46 +01:00
// Copyright (C) 2019 Sergey Rubanov. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-promise.any
description: >
Promise.any(poisoned iterable) rejects with whatever error is thrown.
2019-11-27 22:07:46 +01:00
info: |
Promise.any ( iterable )
...
3. Let iteratorRecord be GetIterator(iterable).
4. IfAbruptRejectPromise(iteratorRecord, promiseCapability).
2019-11-27 22:07:46 +01:00
...
#sec-getiterator
GetIterator ( obj [ , hint [ , method ] ] )
...
Let iterator be ? Call(method, obj).
...
2020-03-24 17:10:16 +01:00
features: [Promise.any, Symbol, Symbol.iterator, arrow-function]
2019-11-27 22:07:46 +01:00
flags: [async]
---*/
var poison = [];
Object.defineProperty(poison, Symbol.iterator, {
get() {
throw new Test262Error();
2019-11-27 22:07:46 +01:00
}
});
try {
Promise.any(poison).then(() => {
2019-11-27 22:07:46 +01:00
$DONE('The promise should be rejected, but was resolved');
}, (error) => {
assert.sameValue(Object.getPrototypeOf(error), Test262Error.prototype);
assert(error instanceof Test262Error);
2019-11-27 22:07:46 +01:00
}).then($DONE, $DONE);
} catch (error) {
$DONE(`The promise should be rejected, but threw an exception: ${error.message}`);
}