yield-star-next-non-object-ignores-then.js (2323B)
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-expression.template 5 /*--- 6 description: If next() value is not-object, do not access respective then property (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 6. Repeat 21 a. If received.[[Type]] is normal, then 22 ii. Let innerResult be ? Invoke(iterator, "next", 23 « received.[[Value]] »). 24 iii. If generatorKind is async, then set innerResult to 25 ? Await(innerResult). 26 iv. If Type(innerResult) is not Object, throw a TypeError exception. 27 ... 28 29 Await 30 31 ... 32 2. Let promiseCapability be ! NewPromiseCapability(%Promise%). 33 3. Perform ! Call(promiseCapability.[[Resolve]], undefined, « promise »). 34 ... 35 36 Promise Resolve Functions 37 38 ... 39 7. If Type(resolution) is not Object, then 40 a. Return FulfillPromise(promise, resolution). 41 8. Let then be Get(resolution, "then"). 42 ... 43 44 ---*/ 45 Number.prototype.then = function() { 46 throw new Test262Error('Number#then should not be used'); 47 }; 48 var obj = { 49 get [Symbol.iterator]() { 50 throw new Test262Error('it should not get Symbol.iterator'); 51 }, 52 [Symbol.asyncIterator]() { 53 return { 54 next() { 55 return 42; 56 } 57 }; 58 } 59 }; 60 61 62 63 var callCount = 0; 64 65 var gen = async function *() { 66 callCount += 1; 67 yield* obj; 68 throw new Test262Error('abrupt completion closes iter'); 69 70 }; 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);