yield-promise-reject-next-for-await-of-async-iterator.js (1548B)
1 // |reftest| async 2 // This file was procedurally generated from the following sources: 3 // - src/async-generators/yield-promise-reject-next-for-await-of-async-iterator.case 4 // - src/async-generators/default/async-class-expr-static-method.template 5 /*--- 6 description: yield * [Promise.reject(value)] is treated as throw value (Static async generator method as a ClassExpression element) 7 esid: prod-AsyncGeneratorMethod 8 features: [async-iteration] 9 flags: [generated, async] 10 info: | 11 ClassElement : 12 static MethodDefinition 13 14 MethodDefinition : 15 AsyncGeneratorMethod 16 17 Async Generator Function Definitions 18 19 AsyncGeneratorMethod : 20 async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } 21 22 ---*/ 23 let error = new Error(); 24 async function * readFile() { 25 yield Promise.reject(error); 26 yield "unreachable"; 27 } 28 29 30 var callCount = 0; 31 32 var C = class { static async *gen() { 33 callCount += 1; 34 for await (let line of readFile()) { 35 yield line; 36 } 37 }} 38 39 var gen = C.gen; 40 41 var iter = gen(); 42 43 iter.next().then(() => { 44 throw new Test262Error("Promise incorrectly resolved."); 45 }, rejectValue => { 46 47 // yield Promise.reject(error); 48 assert.sameValue(rejectValue, error); 49 50 iter.next().then(({done, value}) => { 51 // iter is closed now. 52 assert.sameValue(done, true, "The value of IteratorResult.done is `true`"); 53 assert.sameValue(value, undefined, "The value of IteratorResult.value is `undefined`"); 54 }).then($DONE, $DONE); 55 }).catch($DONE); 56 57 assert.sameValue(callCount, 1);