Debian Codegraph @

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

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