yield-promise-reject-next-yield-star-async-iterator.js (1500B)
1 // |reftest| async 2 // This file was procedurally generated from the following sources: 3 // - src/async-generators/yield-promise-reject-next-yield-star-async-iterator.case 4 // - src/async-generators/default/async-class-decl-static-method.template 5 /*--- 6 description: yield * (async iterator) is treated as throw value (Static async generator method as a ClassDeclaration 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 class C { static async *gen() { 33 callCount += 1; 34 yield * readFile(); 35 36 }} 37 38 var gen = C.gen; 39 40 var iter = gen(); 41 42 iter.next().then(() => { 43 throw new Test262Error("Promise incorrectly resolved."); 44 }, rejectValue => { 45 // yield Promise.reject(error); 46 assert.sameValue(rejectValue, error); 47 48 iter.next().then(({done, value}) => { 49 // iter is closed now. 50 assert.sameValue(done, true, "The value of IteratorResult.done is `true`"); 51 assert.sameValue(value, undefined, "The value of IteratorResult.value is `undefined`"); 52 }).then($DONE, $DONE); 53 }, $DONE).catch($DONE); 54 55 assert.sameValue(callCount, 1);