named-yield-star-async-throw.js (7955B)
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-expression-named.template 5 /*--- 6 description: execution order for yield* with async iterator and throw() (Named async generator expression) 7 esid: prod-AsyncGeneratorExpression 8 features: [async-iteration, Symbol.asyncIterator] 9 flags: [generated, async] 10 info: | 11 Async Generator Function Definitions 12 13 AsyncGeneratorExpression : 14 async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { 15 AsyncGeneratorBody } 16 17 18 YieldExpression: yield * AssignmentExpression 19 20 ... 21 6. Repeat 22 ... 23 b. Else if received.[[Type]] is throw, then 24 i. Let throw be ? GetMethod(iterator, "throw"). 25 ii. If throw is not undefined, then 26 1. Let innerResult be ? Call(throw, iterator, « received.[[Value]] »). 27 2. If generatorKind is async, then set innerResult to ? Await(innerResult). 28 ... 29 5. Let done be ? IteratorComplete(innerResult). 30 6. If done is true, then 31 a. Let resultValue be Return ? IteratorValue(innerResult). 32 b. If generatorKind is async, then set resultValue to ? Await(resultValue). 33 c. Return resultValue. 34 7. If generatorKind is async, then let received be AsyncGeneratorYield(? IteratorValue(innerResult)). 35 ... 36 37 AsyncGeneratorYield ( value ) 38 39 ... 40 8. Return ! AsyncGeneratorResolve(generator, value, false). 41 ... 42 43 ---*/ 44 var log = []; 45 var obj = { 46 [Symbol.asyncIterator]() { 47 var throwCount = 0; 48 return { 49 name: "asyncIterator", 50 get next() { 51 log.push({ name: "get next" }); 52 return function() { 53 return { 54 value: "next-value-1", 55 done: false 56 }; 57 }; 58 }, 59 get throw() { 60 log.push({ 61 name: "get throw", 62 thisValue: this 63 }); 64 return function() { 65 log.push({ 66 name: "call throw", 67 thisValue: this, 68 args: [...arguments] 69 }); 70 71 throwCount++; 72 if (throwCount == 1) { 73 return { 74 name: "throw-promise-1", 75 get then() { 76 log.push({ 77 name: "get throw then (1)", 78 thisValue: this 79 }); 80 return function(resolve) { 81 log.push({ 82 name: "call throw then (1)", 83 thisValue: this, 84 args: [...arguments] 85 }); 86 87 resolve({ 88 name: "throw-result-1", 89 get value() { 90 log.push({ 91 name: "get throw value (1)", 92 thisValue: this 93 }); 94 return "throw-value-1"; 95 }, 96 get done() { 97 log.push({ 98 name: "get throw done (1)", 99 thisValue: this 100 }); 101 return false; 102 } 103 }); 104 }; 105 } 106 }; 107 } 108 109 return { 110 name: "throw-promise-2", 111 get then() { 112 log.push({ 113 name: "get throw then (2)", 114 thisValue: this 115 }); 116 return function(resolve) { 117 log.push({ 118 name: "call throw then (2)", 119 thisValue: this, 120 args: [...arguments] 121 }); 122 123 resolve({ 124 name: "throw-result-2", 125 get value() { 126 log.push({ 127 name: "get throw value (2)", 128 thisValue: this 129 }); 130 return "throw-value-2"; 131 }, 132 get done() { 133 log.push({ 134 name: "get throw done (2)", 135 thisValue: this 136 }); 137 return true; 138 } 139 }); 140 }; 141 } 142 }; 143 }; 144 } 145 }; 146 } 147 }; 148 149 150 151 var callCount = 0; 152 153 var gen = async function *g() { 154 callCount += 1; 155 log.push({ name: "before yield*" }); 156 var v = yield* obj; 157 log.push({ 158 name: "after yield*", 159 value: v 160 }); 161 return "return-value"; 162 163 }; 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);