yield-star-getiter-async-undefined-sync-get-abrupt.js (2038B)
1 // |reftest| async 2 // This file was procedurally generated from the following sources: 3 // - src/async-generators/yield-star-getiter-async-undefined-sync-get-abrupt.case 4 // - src/async-generators/default/async-expression.template 5 /*--- 6 description: Abrupt completion while getting @@iterator after undefined @@asyncIterator (Unnamed async generator expression) 7 esid: prod-AsyncGeneratorExpression 8 features: [Symbol.iterator, Symbol.asyncIterator, async-iteration] 9 flags: [generated, async] 10 info: | 11 Async Generator Function Definitions 12 13 AsyncGeneratorExpression : 14 async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { 15 AsyncGeneratorBody } 16 17 18 YieldExpression: yield * AssignmentExpression 19 20 1. Let exprRef be the result of evaluating AssignmentExpression. 21 2. Let value be ? GetValue(exprRef). 22 3. Let generatorKind be ! GetGeneratorKind(). 23 4. Let iterator be ? GetIterator(value, generatorKind). 24 ... 25 26 GetIterator ( obj [ , hint ] ) 27 28 ... 29 3. If hint is async, 30 a. Set method to ? GetMethod(obj, @@asyncIterator). 31 b. If method is undefined, 32 i. Let syncMethod be ? GetMethod(obj, @@iterator). 33 ... 34 35 GetMethod ( V, P ) 36 37 ... 38 2. Let func be ? GetV(V, P). 39 ... 40 41 ---*/ 42 var calls = 0; 43 var reason = {}; 44 var obj = { 45 get [Symbol.iterator]() { 46 throw reason; 47 }, 48 get [Symbol.asyncIterator]() { 49 calls += 1; 50 return undefined; 51 } 52 }; 53 54 55 56 var callCount = 0; 57 58 var gen = async function *() { 59 callCount += 1; 60 yield* obj; 61 throw new Test262Error('abrupt completion closes iter'); 62 63 }; 64 65 var iter = gen(); 66 67 iter.next().then(() => { 68 throw new Test262Error('Promise incorrectly fulfilled.'); 69 }, v => { 70 assert.sameValue(v, reason, 'reject reason'); 71 assert.sameValue(calls, 1); 72 73 iter.next().then(({ done, value }) => { 74 assert.sameValue(done, true, 'the iterator is completed'); 75 assert.sameValue(value, undefined, 'value is undefined'); 76 }).then($DONE, $DONE); 77 }).catch($DONE); 78 79 assert.sameValue(callCount, 1);