named-yield-star-getiter-sync-get-abrupt.js (1881B)
1 // |reftest| async 2 // This file was procedurally generated from the following sources: 3 // - src/async-generators/yield-star-getiter-sync-get-abrupt.case 4 // - src/async-generators/default/async-expression-named.template 5 /*--- 6 description: Abrupt completion while getting [Symbol.iterator] (Named 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 reason = {}; 43 var obj = { 44 get [Symbol.iterator]() { 45 throw reason; 46 } 47 }; 48 49 50 51 var callCount = 0; 52 53 var gen = async function *g() { 54 callCount += 1; 55 yield* obj; 56 throw new Test262Error('abrupt completion closes iter'); 57 58 }; 59 60 var iter = gen(); 61 62 iter.next().then(() => { 63 throw new Test262Error('Promise incorrectly fulfilled.'); 64 }, v => { 65 assert.sameValue(v, reason, "reject reason"); 66 67 iter.next().then(({ done, value }) => { 68 assert.sameValue(done, true, 'the iterator is completed'); 69 assert.sameValue(value, undefined, 'value is undefined'); 70 }).then($DONE, $DONE); 71 }).catch($DONE); 72 73 assert.sameValue(callCount, 1);