Debian Codegraph @

js/src/tests/test262/language/statements/class/async-gen-method-static/yield-star-async-throw.js

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