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