Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/language/expressions/object/method-definition/async-gen-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-obj-method.template
4 /*---
5 description: execution order for yield* with sync iterator and throw() (Async generator method)
6 esid: prod-AsyncGeneratorMethod
7 features: [Symbol.iterator, async-iteration]
8 flags: [generated, async]
9 info: |
10 Async Generator Function Definitions
11
12 AsyncGeneratorMethod :
13 async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody }
14
15
16 YieldExpression: yield * AssignmentExpression
17
18 ...
19 6. Repeat
20 ...
21 b. Else if received.[[Type]] is throw, then
22 i. Let throw be ? GetMethod(iterator, "throw").
23 ii. If throw is not undefined, then
24 1. Let innerResult be ? Call(throw, iterator, « received.[[Value]] »).
25 2. If generatorKind is async, then set innerResult to
26 ? Await(innerResult).
27 ...
28 5. Let done be ? IteratorComplete(innerResult).
29 6. If done is true, then
30 a. Return ? IteratorValue(innerResult).
31 7. Let received be GeneratorYield(innerResult).
32 ...
33
34 %AsyncFromSyncIteratorPrototype%.throw ( value )
35
36 ...
37 5. Let throw be GetMethod(syncIterator, "throw").
38 ...
39 8. Let throwResult be Call(throw, syncIterator, « value »).
40 ...
41 11. Let throwValue be IteratorValue(throwResult).
42 ...
43 13. Let throwDone be IteratorComplete(throwResult).
44 ...
45 16. Perform ! Call(valueWrapperCapability.[[Resolve]], undefined,
46 « throwValue »).
47 ...
48 18. Set onFulfilled.[[Done]] to throwDone.
49 19. Perform ! PerformPromiseThen(valueWrapperCapability.[[Promise]],
50 onFulfilled, undefined, promiseCapability).
51 ...
52
53 ---*/
54 var log = [];
55 var obj = {
56 [Symbol.iterator]() {
57 var throwCount = 0;
58 return {
59 name: "syncIterator",
60 get next() {
61 log.push({ name: "get next" });
62 return function() {
63 return {
64 value: "next-value-1",
65 done: false
66 };
67 };
68 },
69 get throw() {
70 log.push({
71 name: "get throw",
72 thisValue: this
73 });
74 return function() {
75 log.push({
76 name: "call throw",
77 thisValue: this,
78 args: [...arguments]
79 });
80
81 throwCount++;
82 if (throwCount == 1) {
83 return {
84 name: "throw-result-1",
85 get value() {
86 log.push({
87 name: "get throw value (1)",
88 thisValue: this
89 });
90 return "throw-value-1";
91 },
92 get done() {
93 log.push({
94 name: "get throw done (1)",
95 thisValue: this
96 });
97 return false;
98 }
99 };
100 }
101
102 return {
103 name: "throw-result-2",
104 get value() {
105 log.push({
106 name: "get throw value (2)",
107 thisValue: this
108 });
109 return "throw-value-2";
110 },
111 get done() {
112 log.push({
113 name: "get throw done (2)",
114 thisValue: this
115 });
116 return true;
117 }
118 };
119 };
120 }
121 };
122 }
123 };
124
125
126 var callCount = 0;
127
128 var gen = {
129 async *method() {
130 callCount += 1;
131 log.push({ name: "before yield*" });
132 var v = yield* obj;
133 log.push({
134 name: "after yield*",
135 value: v
136 });
137 return "return-value";
138
139 }
140 }.method;
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);