Debian Codegraph @

js/src/tests/test262/language/expressions/object/method-definition/async-gen-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-obj-method.template
5 /*---
6 description: Execution order for yield* with async iterator and next() (Async generator method)
7 esid: prod-AsyncGeneratorMethod
8 features: [Symbol.iterator, async-iteration, Symbol.asyncIterator]
9 flags: [generated, async]
10 info: |
11 Async Generator Function Definitions
12
13 AsyncGeneratorMethod :
14 async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody }
15
16
17
18 ---*/
19 var log = [];
20 var obj = {
21 get [Symbol.iterator]() {
22 log.push({ name: "get [Symbol.iterator]" });
23 },
24 get [Symbol.asyncIterator]() {
25 log.push({
26 name: "get [Symbol.asyncIterator]",
27 thisValue: this
28 });
29 return function() {
30 log.push({
31 name: "call [Symbol.asyncIterator]",
32 thisValue: this,
33 args: [...arguments]
34 });
35 var nextCount = 0;
36 return {
37 name: "asyncIterator",
38 get next() {
39 log.push({
40 name: "get next",
41 thisValue: this
42 });
43 return function() {
44 log.push({
45 name: "call next",
46 thisValue: this,
47 args: [...arguments]
48 });
49
50 nextCount++;
51 if (nextCount == 1) {
52 return {
53 name: "next-promise-1",
54 get then() {
55 log.push({
56 name: "get next then (1)",
57 thisValue: this
58 });
59 return function(resolve) {
60 log.push({
61 name: "call next then (1)",
62 thisValue: this,
63 args: [...arguments]
64 });
65
66 resolve({
67 name: "next-result-1",
68 get value() {
69 log.push({
70 name: "get next value (1)",
71 thisValue: this
72 });
73 return "next-value-1";
74 },
75 get done() {
76 log.push({
77 name: "get next done (1)",
78 thisValue: this
79 });
80 return false;
81 }
82 });
83 };
84 }
85 };
86 }
87
88 return {
89 name: "next-promise-2",
90 get then() {
91 log.push({
92 name: "get next then (2)",
93 thisValue: this
94 });
95 return function(resolve) {
96 log.push({
97 name: "call next then (2)",
98 thisValue: this,
99 args: [...arguments]
100 });
101
102 resolve({
103 name: "next-result-2",
104 get value() {
105 log.push({
106 name: "get next value (2)",
107 thisValue: this
108 });
109 return "next-value-2";
110 },
111 get done() {
112 log.push({
113 name: "get next done (2)",
114 thisValue: this
115 });
116 return true;
117 }
118 });
119 };
120 }
121 };
122 };
123 }
124 };
125 };
126 }
127 };
128
129
130 var callCount = 0;
131
132 var gen = {
133 async *method() {
134 callCount += 1;
135 log.push({ name: "before yield*" });
136 var v = yield* obj;
137 log.push({
138 name: "after yield*",
139 value: v
140 });
141 return "return-value";
142
143 }
144 }.method;
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);