Debian Codegraph @

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

raw
1 // |reftest| async
2 // Copyright (C) 2019 Sergey Rubanov. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
4
5 /*---
6 esid: sec-promise.any
7 description: >
8 Promise.any(poisoned iterable) rejects with whatever error is thrown.
9 info: |
10 Promise.any ( iterable )
11
12 ...
13 3. Let iteratorRecord be GetIterator(iterable).
14 4. IfAbruptRejectPromise(iteratorRecord, promiseCapability).
15 ...
16
17 #sec-getiterator
18 GetIterator ( obj [ , hint [ , method ] ] )
19
20 ...
21 Let iterator be ? Call(method, obj).
22 ...
23 features: [Promise.any, Symbol, Symbol.iterator, arrow-function]
24 flags: [async]
25 ---*/
26
27 var poison = [];
28 Object.defineProperty(poison, Symbol.iterator, {
29 get() {
30 throw new Test262Error();
31 }
32 });
33
34 try {
35 Promise.any(poison).then(() => {
36 $DONE('The promise should be rejected, but was resolved');
37 }, (error) => {
38 assert.sameValue(Object.getPrototypeOf(error), Test262Error.prototype);
39 assert(error instanceof Test262Error);
40 }).then($DONE, $DONE);
41 } catch (error) {
42 $DONE(`The promise should be rejected, but threw an exception: ${error.message}`);
43 }