Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/language/expressions/async-generator/named-yield-star-sync-throw.js

raw
1 // This file was procedurally generated from the following sources:
2 // - src/async-generators/yield-star-sync-throw.case
3 // - src/async-generators/default/async-expression-named.template
4 /*---
5 description: execution order for yield* with sync iterator and throw() (Named async generator expression)
6 esid: prod-AsyncGeneratorExpression
7 features: [Symbol.iterator, async-iteration]
8 flags: [generated, async]
9 info: |
10 Async Generator Function Definitions
11
12 AsyncGeneratorExpression :
13 async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) {
14 AsyncGeneratorBody }
15
16
17 YieldExpression: yield * AssignmentExpression
18
19 ...
20 6. Repeat
21 ...
22 b. Else if received.[[Type]] is throw, then
23 i. Let throw be ? GetMethod(iterator, "throw").
24 ii. If throw is not undefined, then
25 1. Let innerResult be ? Call(throw, iterator, « received.[[Value]] »).
26 2. If generatorKind is async, then set innerResult to
27 ? Await(innerResult).
28 ...
29 5. Let done be ? IteratorComplete(innerResult).
30 6. If done is true, then
31 a. Return ? IteratorValue(innerResult).
32 7. Let received be GeneratorYield(innerResult).
33 ...
34
35 %AsyncFromSyncIteratorPrototype%.throw ( value )
36
37 ...
38 5. Let throw be GetMethod(syncIterator, "throw").
39 ...
40 8. Let throwResult be Call(throw, syncIterator, « value »).
41 ...
42 11. Let throwValue be IteratorValue(throwResult).
43 ...
44 13. Let throwDone be IteratorComplete(throwResult).
45 ...
46 16. Perform ! Call(valueWrapperCapability.[[Resolve]], undefined,
47 « throwValue »).
48 ...
49 18. Set onFulfilled.[[Done]] to throwDone.
50 19. Perform ! PerformPromiseThen(valueWrapperCapability.[[Promise]],
51 onFulfilled, undefined, promiseCapability).
52 ...
53
54 ---*/
55 var log = [];
56 var obj = {
57 [Symbol.iterator]() {
58 var throwCount = 0;
59 return {
60 name: "syncIterator",
61 get next() {
62 log.push({ name: "get next" });
63 return function() {
64 return {
65 value: "next-value-1",
66 done: false
67 };
68 };
69 },
70 get throw() {
71 log.push({
72 name: "get throw",
73 thisValue: this
74 });
75 return function() {
76 log.push({
77 name: "call throw",
78 thisValue: this,
79 args: [...arguments]
80 });
81
82 throwCount++;
83 if (throwCount == 1) {
84 return {
85 name: "throw-result-1",
86 get value() {
87 log.push({
88 name: "get throw value (1)",
89 thisValue: this
90 });
91 return "throw-value-1";
92 },
93 get done() {
94 log.push({
95 name: "get throw done (1)",
96 thisValue: this
97 });
98 return false;
99 }
100 };
101 }
102
103 return {
104 name: "throw-result-2",
105 get value() {
106 log.push({
107 name: "get throw value (2)",
108 thisValue: this
109 });
110 return "throw-value-2";
111 },
112 get done() {
113 log.push({
114 name: "get throw done (2)",
115 thisValue: this
116 });
117 return true;
118 }
119 };
120 };
121 }
122 };
123 }
124 };
125
126
127
128 var callCount = 0;
129
130 var gen = async function *g() {
131 callCount += 1;
132 log.push({ name: "before yield*" });
133 var v = yield* obj;
134 log.push({
135 name: "after yield*",
136 value: v
137 });
138 return "return-value";
139
140 };
141
142 var iter = gen();
143
144 assert.sameValue(log.length, 0, "log.length");
145
146 iter.next().then(v => {
147 assert.sameValue(log[0].name, "before yield*");
148
149 assert.sameValue(log[1].name, "get next");
150
151 assert.sameValue(v.value, "next-value-1");
152 assert.sameValue(v.done, false);
153
154 assert.sameValue(log.length, 2, "log.length");
155
156 iter.throw("throw-arg-1").then(v => {
157 assert.sameValue(log[2].name, "get throw");
158 assert.sameValue(log[2].thisValue.name, "syncIterator", "get throw thisValue");
159
160 assert.sameValue(log[3].name, "call throw");
161 assert.sameValue(log[3].thisValue.name, "syncIterator", "throw thisValue");
162 assert.sameValue(log[3].args.length, 1, "throw args.length");
163 assert.sameValue(log[3].args[0], "throw-arg-1", "throw args[0]");
164
165 assert.sameValue(log[4].name, "get throw done (1)");
166 assert.sameValue(log[4].thisValue.name, "throw-result-1", "get throw done thisValue");
167
168 assert.sameValue(log[5].name, "get throw value (1)");
169 assert.sameValue(log[5].thisValue.name, "throw-result-1", "get throw value thisValue");
170
171 assert.sameValue(v.value, "throw-value-1");
172 assert.sameValue(v.done, false);
173
174 assert.sameValue(log.length, 6, "log.length");
175
176 iter.throw("throw-arg-2").then(v => {
177 assert.sameValue(log[6].name, "get throw");
178 assert.sameValue(log[6].thisValue.name, "syncIterator", "get throw thisValue");
179
180 assert.sameValue(log[7].name, "call throw");
181 assert.sameValue(log[7].thisValue.name, "syncIterator", "throw thisValue");
182 assert.sameValue(log[7].args.length, 1, "throw args.length");
183 assert.sameValue(log[7].args[0], "throw-arg-2", "throw args[0]");
184
185 assert.sameValue(log[8].name, "get throw done (2)");
186 assert.sameValue(log[8].thisValue.name, "throw-result-2", "get throw done thisValue");
187
188 assert.sameValue(log[9].name, "get throw value (2)");
189 assert.sameValue(log[9].thisValue.name, "throw-result-2", "get throw value thisValue");
190
191 assert.sameValue(log[10].name, "after yield*");
192 assert.sameValue(log[10].value, "throw-value-2");
193
194 assert.sameValue(v.value, "return-value");
195 assert.sameValue(v.done, true);
196
197 assert.sameValue(log.length, 11, "log.length");
198 }).then($DONE, $DONE);
199 }).catch($DONE);
200 }).catch($DONE);
201
202 assert.sameValue(callCount, 1);