async-gen-yield-star-getiter-sync-get-abrupt.js (1857B)
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-obj-method.template 5 /*--- 6 description: Abrupt completion while getting [Symbol.iterator] (Async generator method) 7 esid: prod-AsyncGeneratorMethod 8 features: [Symbol.iterator, Symbol.asyncIterator, async-iteration] 9 flags: [generated, async] 10 info: | 11 Async Generator Function Definitions 12 13 AsyncGeneratorMethod : 14 async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } 15 16 17 YieldExpression: yield * AssignmentExpression 18 19 1. Let exprRef be the result of evaluating AssignmentExpression. 20 2. Let value be ? GetValue(exprRef). 21 3. Let generatorKind be ! GetGeneratorKind(). 22 4. Let iterator be ? GetIterator(value, generatorKind). 23 ... 24 25 GetIterator ( obj [ , hint ] ) 26 27 ... 28 3. If hint is async, 29 a. Set method to ? GetMethod(obj, @@asyncIterator). 30 b. If method is undefined, 31 i. Let syncMethod be ? GetMethod(obj, @@iterator). 32 ... 33 34 GetMethod ( V, P ) 35 36 ... 37 2. Let func be ? GetV(V, P). 38 ... 39 40 ---*/ 41 var reason = {}; 42 var obj = { 43 get [Symbol.iterator]() { 44 throw reason; 45 } 46 }; 47 48 49 var callCount = 0; 50 51 var gen = { 52 async *method() { 53 callCount += 1; 54 yield* obj; 55 throw new Test262Error('abrupt completion closes iter'); 56 57 } 58 }.method; 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);