Debian Codegraph @

js/src/tests/test262/language/expressions/async-generator/yield-star-async-next.js

raw
1 // |reftest| async
2 // This file was procedurally generated from the following sources:
3 // - src/async-generators/yield-star-async-next.case
4 // - src/async-generators/default/async-expression.template
5 /*---
6 description: Execution order for yield* with async iterator and next() (Unnamed async generator expression)
7 esid: prod-AsyncGeneratorExpression
8 features: [Symbol.iterator, async-iteration, Symbol.asyncIterator]
9 flags: [generated, async]
10 info: |
11 Async Generator Function Definitions
12
13 AsyncGeneratorExpression :
14 async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) {
15 AsyncGeneratorBody }
16
17
18
19 ---*/
20 var log = [];
21 var obj = {
22 get [Symbol.iterator]() {
23 log.push({ name: "get [Symbol.iterator]" });
24 },
25 get [Symbol.asyncIterator]() {
26 log.push({
27 name: "get [Symbol.asyncIterator]",
28 thisValue: this
29 });
30 return function() {
31 log.push({
32 name: "call [Symbol.asyncIterator]",
33 thisValue: this,
34 args: [...arguments]
35 });
36 var nextCount = 0;
37 return {
38 name: "asyncIterator",
39 get next() {
40 log.push({
41 name: "get next",
42 thisValue: this
43 });
44 return function() {
45 log.push({
46 name: "call next",
47 thisValue: this,
48 args: [...arguments]
49 });
50
51 nextCount++;
52 if (nextCount == 1) {
53 return {
54 name: "next-promise-1",
55 get then() {
56 log.push({
57 name: "get next then (1)",
58 thisValue: this
59 });
60 return function(resolve) {
61 log.push({
62 name: "call next then (1)",
63 thisValue: this,
64 args: [...arguments]
65 });
66
67 resolve({
68 name: "next-result-1",
69 get value() {
70 log.push({
71 name: "get next value (1)",
72 thisValue: this
73 });
74 return "next-value-1";
75 },
76 get done() {
77 log.push({
78 name: "get next done (1)",
79 thisValue: this
80 });
81 return false;
82 }
83 });
84 };
85 }
86 };
87 }
88
89 return {
90 name: "next-promise-2",
91 get then() {
92 log.push({
93 name: "get next then (2)",
94 thisValue: this
95 });
96 return function(resolve) {
97 log.push({
98 name: "call next then (2)",
99 thisValue: this,
100 args: [...arguments]
101 });
102
103 resolve({
104 name: "next-result-2",
105 get value() {
106 log.push({
107 name: "get next value (2)",
108 thisValue: this
109 });
110 return "next-value-2";
111 },
112 get done() {
113 log.push({
114 name: "get next done (2)",
115 thisValue: this
116 });
117 return true;
118 }
119 });
120 };
121 }
122 };
123 };
124 }
125 };
126 };
127 }
128 };
129
130
131
132 var callCount = 0;
133
134 var gen = async function *() {
135 callCount += 1;
136 log.push({ name: "before yield*" });
137 var v = yield* obj;
138 log.push({
139 name: "after yield*",
140 value: v
141 });
142 return "return-value";
143
144 };
145
146 var iter = gen();
147
148 assert.sameValue(log.length, 0, "log.length");
149
150 iter.next("next-arg-1").then(v => {
151 assert.sameValue(log[0].name, "before yield*");
152
153 assert.sameValue(log[1].name, "get [Symbol.asyncIterator]");
154 assert.sameValue(log[1].thisValue, obj, "get [Symbol.asyncIterator] thisValue");
155
156 assert.sameValue(log[2].name, "call [Symbol.asyncIterator]");
157 assert.sameValue(log[2].thisValue, obj, "[Symbol.asyncIterator] thisValue");
158 assert.sameValue(log[2].args.length, 0, "[Symbol.asyncIterator] args.length");
159
160 assert.sameValue(log[3].name, "get next");
161 assert.sameValue(log[3].thisValue.name, "asyncIterator", "get next thisValue");
162
163 assert.sameValue(log[4].name, "call next");
164 assert.sameValue(log[4].thisValue.name, "asyncIterator", "next thisValue");
165 assert.sameValue(log[4].args.length, 1, "next args.length");
166 assert.sameValue(log[4].args[0], undefined, "next args[0]");
167
168 assert.sameValue(log[5].name, "get next then (1)");
169 assert.sameValue(log[5].thisValue.name, "next-promise-1", "get next then thisValue");
170
171 assert.sameValue(log[6].name, "call next then (1)");
172 assert.sameValue(log[6].thisValue.name, "next-promise-1", "next then thisValue");
173 assert.sameValue(log[6].args.length, 2, "next then args.length");
174 assert.sameValue(typeof log[6].args[0], "function", "next then args[0]");
175 assert.sameValue(typeof log[6].args[1], "function", "next then args[1]");
176
177 assert.sameValue(log[7].name, "get next done (1)");
178 assert.sameValue(log[7].thisValue.name, "next-result-1", "get next done thisValue");
179
180 assert.sameValue(log[8].name, "get next value (1)");
181 assert.sameValue(log[8].thisValue.name, "next-result-1", "get next value thisValue");
182
183 assert.sameValue(v.value, "next-value-1");
184 assert.sameValue(v.done, false);
185
186 assert.sameValue(log.length, 9, "log.length");
187
188 iter.next("next-arg-2").then(v => {
189 assert.sameValue(log[9].name, "call next");
190 assert.sameValue(log[9].thisValue.name, "asyncIterator", "next thisValue");
191 assert.sameValue(log[9].args.length, 1, "next args.length");
192 assert.sameValue(log[9].args[0], "next-arg-2", "next args[0]");
193
194 assert.sameValue(log[10].name, "get next then (2)");
195 assert.sameValue(log[10].thisValue.name, "next-promise-2", "get next then thisValue");
196
197 assert.sameValue(log[11].name, "call next then (2)");
198 assert.sameValue(log[11].thisValue.name, "next-promise-2", "next then thisValue");
199 assert.sameValue(log[11].args.length, 2, "next then args.length");
200 assert.sameValue(typeof log[11].args[0], "function", "next then args[0]");
201 assert.sameValue(typeof log[11].args[1], "function", "next then args[1]");
202
203 assert.sameValue(log[12].name, "get next done (2)");
204 assert.sameValue(log[12].thisValue.name, "next-result-2", "get next done thisValue");
205
206 assert.sameValue(log[13].name, "get next value (2)");
207 assert.sameValue(log[13].thisValue.name, "next-result-2", "get next value thisValue");
208
209 assert.sameValue(log[14].name, "after yield*");
210 assert.sameValue(log[14].value, "next-value-2");
211
212 assert.sameValue(v.value, "return-value");
213 assert.sameValue(v.done, true);
214
215 assert.sameValue(log.length, 15, "log.length");
216 }).then($DONE, $DONE);
217 }).catch($DONE);
218
219 assert.sameValue(callCount, 1);