Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/language/expressions/object/method-definition/async-gen-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-obj-method.template
4 /*---
5 description: execution order for yield* with async iterator and throw() (Async generator method)
6 esid: prod-AsyncGeneratorMethod
7 features: [async-iteration, Symbol.asyncIterator]
8 flags: [generated, async]
9 info: |
10 Async Generator Function Definitions
11
12 AsyncGeneratorMethod :
13 async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody }
14
15
16 YieldExpression: yield * AssignmentExpression
17
18 ...
19 6. Repeat
20 ...
21 b. Else if received.[[Type]] is throw, then
22 i. Let throw be ? GetMethod(iterator, "throw").
23 ii. If throw is not undefined, then
24 1. Let innerResult be ? Call(throw, iterator, « received.[[Value]] »).
25 2. If generatorKind is async, then set innerResult to ? Await(innerResult).
26 ...
27 5. Let done be ? IteratorComplete(innerResult).
28 6. If done is true, then
29 a. Let resultValue be Return ? IteratorValue(innerResult).
30 b. If generatorKind is async, then set resultValue to ? Await(resultValue).
31 c. Return resultValue.
32 7. If generatorKind is async, then let received be AsyncGeneratorYield(? IteratorValue(innerResult)).
33 ...
34
35 AsyncGeneratorYield ( value )
36
37 ...
38 8. Return ! AsyncGeneratorResolve(generator, value, false).
39 ...
40
41 ---*/
42 var log = [];
43 var obj = {
44 [Symbol.asyncIterator]() {
45 var throwCount = 0;
46 return {
47 name: "asyncIterator",
48 get next() {
49 log.push({ name: "get next" });
50 return function() {
51 return {
52 value: "next-value-1",
53 done: false
54 };
55 };
56 },
57 get throw() {
58 log.push({
59 name: "get throw",
60 thisValue: this
61 });
62 return function() {
63 log.push({
64 name: "call throw",
65 thisValue: this,
66 args: [...arguments]
67 });
68
69 throwCount++;
70 if (throwCount == 1) {
71 return {
72 name: "throw-promise-1",
73 get then() {
74 log.push({
75 name: "get throw then (1)",
76 thisValue: this
77 });
78 return function(resolve) {
79 log.push({
80 name: "call throw then (1)",
81 thisValue: this,
82 args: [...arguments]
83 });
84
85 resolve({
86 name: "throw-result-1",
87 get value() {
88 log.push({
89 name: "get throw value (1)",
90 thisValue: this
91 });
92 return "throw-value-1";
93 },
94 get done() {
95 log.push({
96 name: "get throw done (1)",
97 thisValue: this
98 });
99 return false;
100 }
101 });
102 };
103 }
104 };
105 }
106
107 return {
108 name: "throw-promise-2",
109 get then() {
110 log.push({
111 name: "get throw then (2)",
112 thisValue: this
113 });
114 return function(resolve) {
115 log.push({
116 name: "call throw then (2)",
117 thisValue: this,
118 args: [...arguments]
119 });
120
121 resolve({
122 name: "throw-result-2",
123 get value() {
124 log.push({
125 name: "get throw value (2)",
126 thisValue: this
127 });
128 return "throw-value-2";
129 },
130 get done() {
131 log.push({
132 name: "get throw done (2)",
133 thisValue: this
134 });
135 return true;
136 }
137 });
138 };
139 }
140 };
141 };
142 }
143 };
144 }
145 };
146
147
148 var callCount = 0;
149
150 var gen = {
151 async *method() {
152 callCount += 1;
153 log.push({ name: "before yield*" });
154 var v = yield* obj;
155 log.push({
156 name: "after yield*",
157 value: v
158 });
159 return "return-value";
160
161 }
162 }.method;
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);