js/src/tests/test262/language/expressions/object/method-definition/async-gen-yield-star-next-then-get-abrupt.js
raw symbols SCIP| 1 | // |reftest| async |
| 2 | // This file was procedurally generated from the following sources: |
| 3 | // - src/async-generators/yield-star-next-then-get-abrupt.case |
| 4 | // - src/async-generators/default/async-obj-method.template |
| 5 | /*--- |
| 6 | description: Return abrupt after getting next().then (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 | ... |
| 26 | |
| 27 | Await |
| 28 | |
| 29 | ... |
| 30 | 2. Let promiseCapability be ! NewPromiseCapability(%Promise%). |
| 31 | 3. Perform ! Call(promiseCapability.[[Resolve]], undefined, « promise »). |
| 32 | ... |
| 33 | |
| 34 | Promise Resolve Functions |
| 35 | |
| 36 | ... |
| 37 | 8. Let then be Get(resolution, "then"). |
| 38 | ... |
| 39 | 10. Get thenAction be then.[[Value]]. |
| 40 | ... |
| 41 | 12. Perform EnqueueJob("PromiseJobs", PromiseResolveThenableJob, « promise, |
| 42 | resolution, thenAction »). |
| 43 | ... |
| 44 | |
| 45 | ---*/ |
| 46 | var reason = {}; |
| 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 { |
| 55 | get then() { |
| 56 | throw reason; |
| 57 | } |
| 58 | }; |
| 59 | } |
| 60 | }; |
| 61 | } |
| 62 | }; |
| 63 | |
| 64 | |
| 65 | var callCount = 0; |
| 66 | |
| 67 | var gen = { |
| 68 | async *method() { |
| 69 | callCount += 1; |
| 70 | yield* obj; |
| 71 | throw new Test262Error('abrupt completion closes iter'); |
| 72 | |
| 73 | } |
| 74 | }.method; |
| 75 | |
| 76 | var iter = gen(); |
| 77 | |
| 78 | iter.next().then(() => { |
| 79 | throw new Test262Error('Promise incorrectly fulfilled.'); |
| 80 | }, v => { |
| 81 | assert.sameValue(v, reason, 'reject reason'); |
| 82 | |
| 83 | iter.next().then(({ done, value }) => { |
| 84 | assert.sameValue(done, true, 'the iterator is completed'); |
| 85 | assert.sameValue(value, undefined, 'value is undefined'); |
| 86 | }).then($DONE, $DONE); |
| 87 | }).catch($DONE); |
| 88 | |
| 89 | assert.sameValue(callCount, 1); |