Debian Codegraph @

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