async-gen-yield-star-next-non-object-ignores-then.js (2304B)
1 // |reftest| async 2 // This file was procedurally generated from the following sources: 3 // - src/async-generators/yield-star-next-non-object-ignores-then.case 4 // - src/async-generators/default/async-obj-method.template 5 /*--- 6 description: If next() value is not-object, do not access respective then property (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 6. Repeat 20 a. If received.[[Type]] is normal, then 21 ii. Let innerResult be ? Invoke(iterator, "next", 22 « received.[[Value]] »). 23 iii. If generatorKind is async, then set innerResult to 24 ? Await(innerResult). 25 iv. If Type(innerResult) is not Object, throw a TypeError exception. 26 ... 27 28 Await 29 30 ... 31 2. Let promiseCapability be ! NewPromiseCapability(%Promise%). 32 3. Perform ! Call(promiseCapability.[[Resolve]], undefined, « promise »). 33 ... 34 35 Promise Resolve Functions 36 37 ... 38 7. If Type(resolution) is not Object, then 39 a. Return FulfillPromise(promise, resolution). 40 8. Let then be Get(resolution, "then"). 41 ... 42 43 ---*/ 44 Number.prototype.then = function() { 45 throw new Test262Error('Number#then should not be used'); 46 }; 47 var obj = { 48 get [Symbol.iterator]() { 49 throw new Test262Error('it should not get Symbol.iterator'); 50 }, 51 [Symbol.asyncIterator]() { 52 return { 53 next() { 54 return 42; 55 } 56 }; 57 } 58 }; 59 60 61 var callCount = 0; 62 63 var gen = { 64 async *method() { 65 callCount += 1; 66 yield* obj; 67 throw new Test262Error('abrupt completion closes iter'); 68 69 } 70 }.method; 71 72 var iter = gen(); 73 74 iter.next().then(() => { 75 throw new Test262Error('Promise incorrectly fulfilled.'); 76 }, v => { 77 assert.sameValue(v.constructor, TypeError, 'TypeError'); 78 79 iter.next().then(({ done, value }) => { 80 assert.sameValue(done, true, 'the iterator is completed'); 81 assert.sameValue(value, undefined, 'value is undefined'); 82 }).then($DONE, $DONE); 83 }).catch($DONE); 84 85 assert.sameValue(callCount, 1);