| 1 |
// This file was procedurally generated from the following sources: |
| 2 |
// - src/async-generators/yield-star-next-non-object-ignores-then.case |
| 3 |
// - src/async-generators/default/async-expression.template |
| 4 |
/*--- |
| 5 |
description: If next() value is not-object, do not access respective then property (Unnamed async generator expression) |
| 6 |
esid: prod-AsyncGeneratorExpression |
| 7 |
features: [Symbol.iterator, Symbol.asyncIterator, async-iteration] |
| 8 |
flags: [generated, async] |
| 9 |
info: | |
| 10 |
Async Generator Function Definitions |
| 11 |
|
| 12 |
AsyncGeneratorExpression : |
| 13 |
async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { |
| 14 |
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 |
|
| 62 |
var callCount = 0; |
| 63 |
|
| 64 |
var gen = async function *() { |
| 65 |
callCount += 1; |
| 66 |
yield* obj; |
| 67 |
throw new Test262Error('abrupt completion closes iter'); |
| 68 |
|
| 69 |
}; |
| 70 |
|
| 71 |
var iter = gen(); |
| 72 |
|
| 73 |
iter.next().then(() => { |
| 74 |
throw new Test262Error('Promise incorrectly fulfilled.'); |
| 75 |
}, v => { |
| 76 |
assert.sameValue(v.constructor, TypeError, 'TypeError'); |
| 77 |
|
| 78 |
iter.next().then(({ done, value }) => { |
| 79 |
assert.sameValue(done, true, 'the iterator is completed'); |
| 80 |
assert.sameValue(value, undefined, 'value is undefined'); |
| 81 |
}).then($DONE, $DONE); |
| 82 |
}).catch($DONE); |
| 83 |
|
| 84 |
assert.sameValue(callCount, 1); |