Debian Codegraph @

js/src/tests/test262/language/statements/class/elements/async-gen-private-method-static/yield-star-sync-next.js

raw
1 // |reftest| async
2 // This file was procedurally generated from the following sources:
3 // - src/async-generators/yield-star-sync-next.case
4 // - src/async-generators/default/async-class-decl-static-private-method.template
5 /*---
6 description: execution order for yield* with sync iterator and next() (Static async generator method as a ClassDeclaration 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 YieldExpression: yield * AssignmentExpression
24
25 ...
26 2. Let value be ? GetValue(exprRef).
27 3. Let generatorKind be ! GetGeneratorKind().
28 4. Let iterator be ? GetIterator(value, generatorKind).
29 5. Let received be NormalCompletion(undefined).
30 6. Repeat
31 a. If received.[[Type]] is normal, then
32 i. Let innerResult be ? IteratorNext(iterator, received.[[Value]]).
33 ii. Let innerResult be ? Invoke(iterator, "next",
34 « received.[[Value]] »).
35 iii. If generatorKind is async, then set innerResult to
36 ? Await(innerResult).
37 ...
38 v. Let done be ? IteratorComplete(innerResult).
39 vi. If done is true, then
40 1. Return ? IteratorValue(innerResult).
41 vii. Let received be GeneratorYield(innerResult).
42 ...
43
44 GetIterator ( obj [ , hint ] )
45
46 ...
47 3. If hint is async,
48 a. Set method to ? GetMethod(obj, @@asyncIterator).
49 b. If method is undefined,
50 i. Let syncMethod be ? GetMethod(obj, @@iterator).
51 ii. Let syncIterator be ? Call(syncMethod, obj).
52 iii. Return ? CreateAsyncFromSyncIterator(syncIterator).
53 ...
54
55 %AsyncFromSyncIteratorPrototype%.next ( value )
56
57 ...
58 5. Let nextResult be IteratorNext(syncIterator, value).
59 ...
60 7. Let nextValue be IteratorValue(nextResult).
61 ...
62 9. Let nextDone be IteratorComplete(nextResult).
63 ...
64 12. Perform ! Call(valueWrapperCapability.[[Resolve]], undefined,
65 « nextValue »).
66 ...
67 14. Set onFulfilled.[[Done]] to nextDone.
68 15. Perform ! PerformPromiseThen(valueWrapperCapability.[[Promise]],
69 onFulfilled, undefined, promiseCapability).
70 ...
71
72 Async Iterator Value Unwrap Functions
73
74 1. Return ! CreateIterResultObject(value, F.[[Done]]).
75
76 ---*/
77 var log = [];
78 var obj = {
79 get [Symbol.iterator]() {
80 log.push({
81 name: "get [Symbol.iterator]",
82 thisValue: this
83 });
84 return function() {
85 log.push({
86 name: "call [Symbol.iterator]",
87 thisValue: this,
88 args: [...arguments]
89 });
90 var nextCount = 0;
91 return {
92 name: "syncIterator",
93 get next() {
94 log.push({
95 name: "get next",
96 thisValue: this
97 });
98 return function() {
99 log.push({
100 name: "call next",
101 thisValue: this,
102 args: [...arguments]
103 });
104
105 nextCount++;
106 if (nextCount == 1) {
107 return {
108 name: "next-result-1",
109 get value() {
110 log.push({
111 name: "get next value (1)",
112 thisValue: this
113 });
114 return "next-value-1";
115 },
116 get done() {
117 log.push({
118 name: "get next done (1)",
119 thisValue: this
120 });
121 return false;
122 }
123 };
124 }
125
126 return {
127 name: "next-result-2",
128 get value() {
129 log.push({
130 name: "get next value (2)",
131 thisValue: this
132 });
133 return "next-value-2";
134 },
135 get done() {
136 log.push({
137 name: "get next done (2)",
138 thisValue: this
139 });
140 return true;
141 }
142 };
143 };
144 }
145 };
146 };
147 },
148 get [Symbol.asyncIterator]() {
149 log.push({ name: "get [Symbol.asyncIterator]" });
150 return null;
151 }
152 };
153
154
155
156 var callCount = 0;
157
158 class C {
159 static async *#gen() {
160 callCount += 1;
161 log.push({ name: "before yield*" });
162 var v = yield* obj;
163 log.push({
164 name: "after yield*",
165 value: v
166 });
167 return "return-value";
168
169 }
170 static get gen() { return this.#gen; }
171 }
172
173 // Test the private fields do not appear as properties before set to value
174 assert(
175 !Object.prototype.hasOwnProperty.call(C.prototype, "#gen"),
176 "#gen does not appear as an own property on C prototype"
177 );
178 assert(
179 !Object.prototype.hasOwnProperty.call(C, "#gen"),
180 "#gen does not appear as an own property on C constructor"
181 );
182
183 var iter = C.gen();
184
185 assert.sameValue(log.length, 0, "log.length");
186
187 iter.next("next-arg-1").then(v => {
188 assert.sameValue(log[0].name, "before yield*");
189
190 assert.sameValue(log[1].name, "get [Symbol.asyncIterator]");
191
192 assert.sameValue(log[2].name, "get [Symbol.iterator]");
193 assert.sameValue(log[2].thisValue, obj, "get [Symbol.iterator] thisValue");
194
195 assert.sameValue(log[3].name, "call [Symbol.iterator]");
196 assert.sameValue(log[3].thisValue, obj, "[Symbol.iterator] thisValue");
197 assert.sameValue(log[3].args.length, 0, "[Symbol.iterator] args.length");
198
199 assert.sameValue(log[4].name, "get next");
200 assert.sameValue(log[4].thisValue.name, "syncIterator", "get next thisValue");
201
202 assert.sameValue(log[5].name, "call next");
203 assert.sameValue(log[5].thisValue.name, "syncIterator", "next thisValue");
204 assert.sameValue(log[5].args.length, 1, "next args.length");
205 assert.sameValue(log[5].args[0], undefined, "next args[0]");
206
207 assert.sameValue(log[6].name, "get next done (1)");
208 assert.sameValue(log[6].thisValue.name, "next-result-1", "get next done thisValue");
209
210 assert.sameValue(log[7].name, "get next value (1)");
211 assert.sameValue(log[7].thisValue.name, "next-result-1", "get next value thisValue");
212
213 assert.sameValue(v.value, "next-value-1");
214 assert.sameValue(v.done, false);
215
216 assert.sameValue(log.length, 8, "log.length");
217
218 iter.next("next-arg-2").then(v => {
219 assert.sameValue(log[8].name, "call next");
220 assert.sameValue(log[8].thisValue.name, "syncIterator", "next thisValue");
221 assert.sameValue(log[8].args.length, 1, "next args.length");
222 assert.sameValue(log[8].args[0], "next-arg-2", "next args[0]");
223
224 assert.sameValue(log[9].name, "get next done (2)");
225 assert.sameValue(log[9].thisValue.name, "next-result-2", "get next done thisValue");
226
227 assert.sameValue(log[10].name, "get next value (2)");
228 assert.sameValue(log[10].thisValue.name, "next-result-2", "get next value thisValue");
229
230 assert.sameValue(log[11].name, "after yield*");
231 assert.sameValue(log[11].value, "next-value-2");
232
233 assert.sameValue(v.value, "return-value");
234 assert.sameValue(v.done, true);
235
236 assert.sameValue(log.length, 12, "log.length");
237 }).then($DONE, $DONE);
238 }).catch($DONE);
239
240 assert.sameValue(callCount, 1);
241
242 // Test the private fields do not appear as properties after set to value
243 assert(
244 !Object.prototype.hasOwnProperty.call(C.prototype, "#gen"),
245 "#gen does not appear as an own property on C prototype"
246 );
247 assert(
248 !Object.prototype.hasOwnProperty.call(C, "#gen"),
249 "#gen does not appear as an own property on C constructor"
250 );