Debian Codegraph @

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