Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/language/expressions/async-generator/yield-star-async-throw.js

raw
1 // This file was procedurally generated from the following sources:
2 // - src/async-generators/yield-star-async-throw.case
3 // - src/async-generators/default/async-expression.template
4 /*---
5 description: execution order for yield* with async iterator and throw() (Unnamed async generator expression)
6 esid: prod-AsyncGeneratorExpression
7 features: [async-iteration, Symbol.asyncIterator]
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 ...
20 6. Repeat
21 ...
22 b. Else if received.[[Type]] is throw, then
23 i. Let throw be ? GetMethod(iterator, "throw").
24 ii. If throw is not undefined, then
25 1. Let innerResult be ? Call(throw, iterator, « received.[[Value]] »).
26 2. If generatorKind is async, then set innerResult to ? Await(innerResult).
27 ...
28 5. Let done be ? IteratorComplete(innerResult).
29 6. If done is true, then
30 a. Let resultValue be Return ? IteratorValue(innerResult).
31 b. If generatorKind is async, then set resultValue to ? Await(resultValue).
32 c. Return resultValue.
33 7. If generatorKind is async, then let received be AsyncGeneratorYield(? IteratorValue(innerResult)).
34 ...
35
36 AsyncGeneratorYield ( value )
37
38 ...
39 8. Return ! AsyncGeneratorResolve(generator, value, false).
40 ...
41
42 ---*/
43 var log = [];
44 var obj = {
45 [Symbol.asyncIterator]() {
46 var throwCount = 0;
47 return {
48 name: "asyncIterator",
49 get next() {
50 log.push({ name: "get next" });
51 return function() {
52 return {
53 value: "next-value-1",
54 done: false
55 };
56 };
57 },
58 get throw() {
59 log.push({
60 name: "get throw",
61 thisValue: this
62 });
63 return function() {
64 log.push({
65 name: "call throw",
66 thisValue: this,
67 args: [...arguments]
68 });
69
70 throwCount++;
71 if (throwCount == 1) {
72 return {
73 name: "throw-promise-1",
74 get then() {
75 log.push({
76 name: "get throw then (1)",
77 thisValue: this
78 });
79 return function(resolve) {
80 log.push({
81 name: "call throw then (1)",
82 thisValue: this,
83 args: [...arguments]
84 });
85
86 resolve({
87 name: "throw-result-1",
88 get value() {
89 log.push({
90 name: "get throw value (1)",
91 thisValue: this
92 });
93 return "throw-value-1";
94 },
95 get done() {
96 log.push({
97 name: "get throw done (1)",
98 thisValue: this
99 });
100 return false;
101 }
102 });
103 };
104 }
105 };
106 }
107
108 return {
109 name: "throw-promise-2",
110 get then() {
111 log.push({
112 name: "get throw then (2)",
113 thisValue: this
114 });
115 return function(resolve) {
116 log.push({
117 name: "call throw then (2)",
118 thisValue: this,
119 args: [...arguments]
120 });
121
122 resolve({
123 name: "throw-result-2",
124 get value() {
125 log.push({
126 name: "get throw value (2)",
127 thisValue: this
128 });
129 return "throw-value-2";
130 },
131 get done() {
132 log.push({
133 name: "get throw done (2)",
134 thisValue: this
135 });
136 return true;
137 }
138 });
139 };
140 }
141 };
142 };
143 }
144 };
145 }
146 };
147
148
149
150 var callCount = 0;
151
152 var gen = async function *() {
153 callCount += 1;
154 log.push({ name: "before yield*" });
155 var v = yield* obj;
156 log.push({
157 name: "after yield*",
158 value: v
159 });
160 return "return-value";
161
162 };
163
164 var iter = gen();
165
166 assert.sameValue(log.length, 0, "log.length");
167
168 iter.next().then(v => {
169 assert.sameValue(log[0].name, "before yield*");
170
171 assert.sameValue(log[1].name, "get next");
172
173 assert.sameValue(v.value, "next-value-1");
174 assert.sameValue(v.done, false);
175
176 assert.sameValue(log.length, 2, "log.length");
177
178 iter.throw("throw-arg-1").then(v => {
179 assert.sameValue(log[2].name, "get throw");
180 assert.sameValue(log[2].thisValue.name, "asyncIterator", "get throw thisValue");
181
182 assert.sameValue(log[3].name, "call throw");
183 assert.sameValue(log[3].thisValue.name, "asyncIterator", "throw thisValue");
184 assert.sameValue(log[3].args.length, 1, "throw args.length");
185 assert.sameValue(log[3].args[0], "throw-arg-1", "throw args[0]");
186
187 assert.sameValue(log[4].name, "get throw then (1)");
188 assert.sameValue(log[4].thisValue.name, "throw-promise-1", "get throw thisValue");
189
190 assert.sameValue(log[5].name, "call throw then (1)");
191 assert.sameValue(log[5].thisValue.name, "throw-promise-1", "throw thisValue");
192 assert.sameValue(log[5].args.length, 2, "throw then args.length");
193 assert.sameValue(typeof log[5].args[0], "function", "throw then args[0]");
194 assert.sameValue(typeof log[5].args[1], "function", "throw then args[1]");
195
196 assert.sameValue(log[6].name, "get throw done (1)");
197 assert.sameValue(log[6].thisValue.name, "throw-result-1", "get throw done thisValue");
198
199 assert.sameValue(log[7].name, "get throw value (1)");
200 assert.sameValue(log[7].thisValue.name, "throw-result-1", "get throw value thisValue");
201
202 assert.sameValue(v.value, "throw-value-1");
203 assert.sameValue(v.done, false);
204
205 assert.sameValue(log.length, 8, "log.length");
206
207 iter.throw("throw-arg-2").then(v => {
208 assert.sameValue(log[8].name, "get throw");
209 assert.sameValue(log[8].thisValue.name, "asyncIterator", "get throw thisValue");
210
211 assert.sameValue(log[9].name, "call throw");
212 assert.sameValue(log[9].thisValue.name, "asyncIterator", "throw thisValue");
213 assert.sameValue(log[9].args.length, 1, "throw args.length");
214 assert.sameValue(log[9].args[0], "throw-arg-2", "throw args[0]");
215
216 assert.sameValue(log[10].name, "get throw then (2)");
217 assert.sameValue(log[10].thisValue.name, "throw-promise-2", "get throw thisValue");
218
219 assert.sameValue(log[11].name, "call throw then (2)");
220 assert.sameValue(log[11].thisValue.name, "throw-promise-2", "throw thisValue");
221 assert.sameValue(log[11].args.length, 2, "throw then args.length");
222 assert.sameValue(typeof log[11].args[0], "function", "throw then args[0]");
223 assert.sameValue(typeof log[11].args[1], "function", "throw then args[1]");
224
225 assert.sameValue(log[12].name, "get throw done (2)");
226 assert.sameValue(log[12].thisValue.name, "throw-result-2", "get throw done thisValue");
227
228 assert.sameValue(log[13].name, "get throw value (2)");
229 assert.sameValue(log[13].thisValue.name, "throw-result-2", "get throw value thisValue");
230
231 assert.sameValue(log[14].name, "after yield*");
232 assert.sameValue(log[14].value, "throw-value-2");
233
234 assert.sameValue(v.value, "return-value");
235 assert.sameValue(v.done, true);
236
237 assert.sameValue(log.length, 15, "log.length");
238 }).then($DONE, $DONE);
239 }).catch($DONE);
240 }).catch($DONE);
241
242 assert.sameValue(callCount, 1);