| 1 |
// This file was procedurally generated from the following sources: |
| 2 |
// - src/async-generators/yield-star-sync-throw.case |
| 3 |
// - src/async-generators/default/async-class-expr-static-method.template |
| 4 |
/*--- |
| 5 |
description: execution order for yield* with sync iterator and throw() (Static async generator method as a ClassExpression element) |
| 6 |
esid: prod-AsyncGeneratorMethod |
| 7 |
features: [Symbol.iterator, async-iteration] |
| 8 |
flags: [generated, async] |
| 9 |
info: | |
| 10 |
ClassElement : |
| 11 |
static MethodDefinition |
| 12 |
|
| 13 |
MethodDefinition : |
| 14 |
AsyncGeneratorMethod |
| 15 |
|
| 16 |
Async Generator Function Definitions |
| 17 |
|
| 18 |
AsyncGeneratorMethod : |
| 19 |
async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } |
| 20 |
|
| 21 |
|
| 22 |
YieldExpression: yield * AssignmentExpression |
| 23 |
|
| 24 |
... |
| 25 |
6. Repeat |
| 26 |
... |
| 27 |
b. Else if received.[[Type]] is throw, then |
| 28 |
i. Let throw be ? GetMethod(iterator, "throw"). |
| 29 |
ii. If throw is not undefined, then |
| 30 |
1. Let innerResult be ? Call(throw, iterator, « received.[[Value]] »). |
| 31 |
2. If generatorKind is async, then set innerResult to |
| 32 |
? Await(innerResult). |
| 33 |
... |
| 34 |
5. Let done be ? IteratorComplete(innerResult). |
| 35 |
6. If done is true, then |
| 36 |
a. Return ? IteratorValue(innerResult). |
| 37 |
7. Let received be GeneratorYield(innerResult). |
| 38 |
... |
| 39 |
|
| 40 |
%AsyncFromSyncIteratorPrototype%.throw ( value ) |
| 41 |
|
| 42 |
... |
| 43 |
5. Let throw be GetMethod(syncIterator, "throw"). |
| 44 |
... |
| 45 |
8. Let throwResult be Call(throw, syncIterator, « value »). |
| 46 |
... |
| 47 |
11. Let throwValue be IteratorValue(throwResult). |
| 48 |
... |
| 49 |
13. Let throwDone be IteratorComplete(throwResult). |
| 50 |
... |
| 51 |
16. Perform ! Call(valueWrapperCapability.[[Resolve]], undefined, |
| 52 |
« throwValue »). |
| 53 |
... |
| 54 |
18. Set onFulfilled.[[Done]] to throwDone. |
| 55 |
19. Perform ! PerformPromiseThen(valueWrapperCapability.[[Promise]], |
| 56 |
onFulfilled, undefined, promiseCapability). |
| 57 |
... |
| 58 |
|
| 59 |
---*/ |
| 60 |
var log = []; |
| 61 |
var obj = { |
| 62 |
[Symbol.iterator]() { |
| 63 |
var throwCount = 0; |
| 64 |
return { |
| 65 |
name: "syncIterator", |
| 66 |
get next() { |
| 67 |
log.push({ name: "get next" }); |
| 68 |
return function() { |
| 69 |
return { |
| 70 |
value: "next-value-1", |
| 71 |
done: false |
| 72 |
}; |
| 73 |
}; |
| 74 |
}, |
| 75 |
get throw() { |
| 76 |
log.push({ |
| 77 |
name: "get throw", |
| 78 |
thisValue: this |
| 79 |
}); |
| 80 |
return function() { |
| 81 |
log.push({ |
| 82 |
name: "call throw", |
| 83 |
thisValue: this, |
| 84 |
args: [...arguments] |
| 85 |
}); |
| 86 |
|
| 87 |
throwCount++; |
| 88 |
if (throwCount == 1) { |
| 89 |
return { |
| 90 |
name: "throw-result-1", |
| 91 |
get value() { |
| 92 |
log.push({ |
| 93 |
name: "get throw value (1)", |
| 94 |
thisValue: this |
| 95 |
}); |
| 96 |
return "throw-value-1"; |
| 97 |
}, |
| 98 |
get done() { |
| 99 |
log.push({ |
| 100 |
name: "get throw done (1)", |
| 101 |
thisValue: this |
| 102 |
}); |
| 103 |
return false; |
| 104 |
} |
| 105 |
}; |
| 106 |
} |
| 107 |
|
| 108 |
return { |
| 109 |
name: "throw-result-2", |
| 110 |
get value() { |
| 111 |
log.push({ |
| 112 |
name: "get throw value (2)", |
| 113 |
thisValue: this |
| 114 |
}); |
| 115 |
return "throw-value-2"; |
| 116 |
}, |
| 117 |
get done() { |
| 118 |
log.push({ |
| 119 |
name: "get throw done (2)", |
| 120 |
thisValue: this |
| 121 |
}); |
| 122 |
return true; |
| 123 |
} |
| 124 |
}; |
| 125 |
}; |
| 126 |
} |
| 127 |
}; |
| 128 |
} |
| 129 |
}; |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
var callCount = 0; |
| 134 |
|
| 135 |
var C = class { static async *gen() { |
| 136 |
callCount += 1; |
| 137 |
log.push({ name: "before yield*" }); |
| 138 |
var v = yield* obj; |
| 139 |
log.push({ |
| 140 |
name: "after yield*", |
| 141 |
value: v |
| 142 |
}); |
| 143 |
return "return-value"; |
| 144 |
|
| 145 |
}} |
| 146 |
|
| 147 |
var gen = C.gen; |
| 148 |
|
| 149 |
var iter = gen(); |
| 150 |
|
| 151 |
assert.sameValue(log.length, 0, "log.length"); |
| 152 |
|
| 153 |
iter.next().then(v => { |
| 154 |
assert.sameValue(log[0].name, "before yield*"); |
| 155 |
|
| 156 |
assert.sameValue(log[1].name, "get next"); |
| 157 |
|
| 158 |
assert.sameValue(v.value, "next-value-1"); |
| 159 |
assert.sameValue(v.done, false); |
| 160 |
|
| 161 |
assert.sameValue(log.length, 2, "log.length"); |
| 162 |
|
| 163 |
iter.throw("throw-arg-1").then(v => { |
| 164 |
assert.sameValue(log[2].name, "get throw"); |
| 165 |
assert.sameValue(log[2].thisValue.name, "syncIterator", "get throw thisValue"); |
| 166 |
|
| 167 |
assert.sameValue(log[3].name, "call throw"); |
| 168 |
assert.sameValue(log[3].thisValue.name, "syncIterator", "throw thisValue"); |
| 169 |
assert.sameValue(log[3].args.length, 1, "throw args.length"); |
| 170 |
assert.sameValue(log[3].args[0], "throw-arg-1", "throw args[0]"); |
| 171 |
|
| 172 |
assert.sameValue(log[4].name, "get throw done (1)"); |
| 173 |
assert.sameValue(log[4].thisValue.name, "throw-result-1", "get throw done thisValue"); |
| 174 |
|
| 175 |
assert.sameValue(log[5].name, "get throw value (1)"); |
| 176 |
assert.sameValue(log[5].thisValue.name, "throw-result-1", "get throw value thisValue"); |
| 177 |
|
| 178 |
assert.sameValue(v.value, "throw-value-1"); |
| 179 |
assert.sameValue(v.done, false); |
| 180 |
|
| 181 |
assert.sameValue(log.length, 6, "log.length"); |
| 182 |
|
| 183 |
iter.throw("throw-arg-2").then(v => { |
| 184 |
assert.sameValue(log[6].name, "get throw"); |
| 185 |
assert.sameValue(log[6].thisValue.name, "syncIterator", "get throw thisValue"); |
| 186 |
|
| 187 |
assert.sameValue(log[7].name, "call throw"); |
| 188 |
assert.sameValue(log[7].thisValue.name, "syncIterator", "throw thisValue"); |
| 189 |
assert.sameValue(log[7].args.length, 1, "throw args.length"); |
| 190 |
assert.sameValue(log[7].args[0], "throw-arg-2", "throw args[0]"); |
| 191 |
|
| 192 |
assert.sameValue(log[8].name, "get throw done (2)"); |
| 193 |
assert.sameValue(log[8].thisValue.name, "throw-result-2", "get throw done thisValue"); |
| 194 |
|
| 195 |
assert.sameValue(log[9].name, "get throw value (2)"); |
| 196 |
assert.sameValue(log[9].thisValue.name, "throw-result-2", "get throw value thisValue"); |
| 197 |
|
| 198 |
assert.sameValue(log[10].name, "after yield*"); |
| 199 |
assert.sameValue(log[10].value, "throw-value-2"); |
| 200 |
|
| 201 |
assert.sameValue(v.value, "return-value"); |
| 202 |
assert.sameValue(v.done, true); |
| 203 |
|
| 204 |
assert.sameValue(log.length, 11, "log.length"); |
| 205 |
}).then($DONE, $DONE); |
| 206 |
}).catch($DONE); |
| 207 |
}).catch($DONE); |
| 208 |
|
| 209 |
assert.sameValue(callCount, 1); |