yield-star-async-throw.js (8885B)
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-class-decl-static-private-method.template 5 /*--- 6 description: execution order for yield* with async iterator and throw() (Static async generator method as a ClassDeclaration element) 7 esid: prod-AsyncGeneratorPrivateMethod 8 features: [async-iteration, Symbol.asyncIterator, class-static-methods-private] 9 flags: [generated, async] 10 info: | 11 ClassElement : 12 static 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 ? Await(innerResult). 33 ... 34 5. Let done be ? IteratorComplete(innerResult). 35 6. If done is true, then 36 a. Let resultValue be Return ? IteratorValue(innerResult). 37 b. If generatorKind is async, then set resultValue to ? Await(resultValue). 38 c. Return resultValue. 39 7. If generatorKind is async, then let received be AsyncGeneratorYield(? IteratorValue(innerResult)). 40 ... 41 42 AsyncGeneratorYield ( value ) 43 44 ... 45 8. Return ! AsyncGeneratorResolve(generator, value, false). 46 ... 47 48 ---*/ 49 var log = []; 50 var obj = { 51 [Symbol.asyncIterator]() { 52 var throwCount = 0; 53 return { 54 name: "asyncIterator", 55 get next() { 56 log.push({ name: "get next" }); 57 return function() { 58 return { 59 value: "next-value-1", 60 done: false 61 }; 62 }; 63 }, 64 get throw() { 65 log.push({ 66 name: "get throw", 67 thisValue: this 68 }); 69 return function() { 70 log.push({ 71 name: "call throw", 72 thisValue: this, 73 args: [...arguments] 74 }); 75 76 throwCount++; 77 if (throwCount == 1) { 78 return { 79 name: "throw-promise-1", 80 get then() { 81 log.push({ 82 name: "get throw then (1)", 83 thisValue: this 84 }); 85 return function(resolve) { 86 log.push({ 87 name: "call throw then (1)", 88 thisValue: this, 89 args: [...arguments] 90 }); 91 92 resolve({ 93 name: "throw-result-1", 94 get value() { 95 log.push({ 96 name: "get throw value (1)", 97 thisValue: this 98 }); 99 return "throw-value-1"; 100 }, 101 get done() { 102 log.push({ 103 name: "get throw done (1)", 104 thisValue: this 105 }); 106 return false; 107 } 108 }); 109 }; 110 } 111 }; 112 } 113 114 return { 115 name: "throw-promise-2", 116 get then() { 117 log.push({ 118 name: "get throw then (2)", 119 thisValue: this 120 }); 121 return function(resolve) { 122 log.push({ 123 name: "call throw then (2)", 124 thisValue: this, 125 args: [...arguments] 126 }); 127 128 resolve({ 129 name: "throw-result-2", 130 get value() { 131 log.push({ 132 name: "get throw value (2)", 133 thisValue: this 134 }); 135 return "throw-value-2"; 136 }, 137 get done() { 138 log.push({ 139 name: "get throw done (2)", 140 thisValue: this 141 }); 142 return true; 143 } 144 }); 145 }; 146 } 147 }; 148 }; 149 } 150 }; 151 } 152 }; 153 154 155 156 var callCount = 0; 157 158 class C { 159 static async *#gen() { 160 callCount += 1; 161 log.push({ name: "before yield*" }); 162 var v = yield* obj; 163 log.push({ 164 name: "after yield*", 165 value: v 166 }); 167 return "return-value"; 168 169 } 170 static get gen() { return this.#gen; } 171 } 172 173 // Test the private fields do not appear as properties before set to value 174 assert( 175 !Object.prototype.hasOwnProperty.call(C.prototype, "#gen"), 176 "#gen does not appear as an own property on C prototype" 177 ); 178 assert( 179 !Object.prototype.hasOwnProperty.call(C, "#gen"), 180 "#gen does not appear as an own property on C constructor" 181 ); 182 183 var iter = C.gen(); 184 185 assert.sameValue(log.length, 0, "log.length"); 186 187 iter.next().then(v => { 188 assert.sameValue(log[0].name, "before yield*"); 189 190 assert.sameValue(log[1].name, "get next"); 191 192 assert.sameValue(v.value, "next-value-1"); 193 assert.sameValue(v.done, false); 194 195 assert.sameValue(log.length, 2, "log.length"); 196 197 iter.throw("throw-arg-1").then(v => { 198 assert.sameValue(log[2].name, "get throw"); 199 assert.sameValue(log[2].thisValue.name, "asyncIterator", "get throw thisValue"); 200 201 assert.sameValue(log[3].name, "call throw"); 202 assert.sameValue(log[3].thisValue.name, "asyncIterator", "throw thisValue"); 203 assert.sameValue(log[3].args.length, 1, "throw args.length"); 204 assert.sameValue(log[3].args[0], "throw-arg-1", "throw args[0]"); 205 206 assert.sameValue(log[4].name, "get throw then (1)"); 207 assert.sameValue(log[4].thisValue.name, "throw-promise-1", "get throw thisValue"); 208 209 assert.sameValue(log[5].name, "call throw then (1)"); 210 assert.sameValue(log[5].thisValue.name, "throw-promise-1", "throw thisValue"); 211 assert.sameValue(log[5].args.length, 2, "throw then args.length"); 212 assert.sameValue(typeof log[5].args[0], "function", "throw then args[0]"); 213 assert.sameValue(typeof log[5].args[1], "function", "throw then args[1]"); 214 215 assert.sameValue(log[6].name, "get throw done (1)"); 216 assert.sameValue(log[6].thisValue.name, "throw-result-1", "get throw done thisValue"); 217 218 assert.sameValue(log[7].name, "get throw value (1)"); 219 assert.sameValue(log[7].thisValue.name, "throw-result-1", "get throw value thisValue"); 220 221 assert.sameValue(v.value, "throw-value-1"); 222 assert.sameValue(v.done, false); 223 224 assert.sameValue(log.length, 8, "log.length"); 225 226 iter.throw("throw-arg-2").then(v => { 227 assert.sameValue(log[8].name, "get throw"); 228 assert.sameValue(log[8].thisValue.name, "asyncIterator", "get throw thisValue"); 229 230 assert.sameValue(log[9].name, "call throw"); 231 assert.sameValue(log[9].thisValue.name, "asyncIterator", "throw thisValue"); 232 assert.sameValue(log[9].args.length, 1, "throw args.length"); 233 assert.sameValue(log[9].args[0], "throw-arg-2", "throw args[0]"); 234 235 assert.sameValue(log[10].name, "get throw then (2)"); 236 assert.sameValue(log[10].thisValue.name, "throw-promise-2", "get throw thisValue"); 237 238 assert.sameValue(log[11].name, "call throw then (2)"); 239 assert.sameValue(log[11].thisValue.name, "throw-promise-2", "throw thisValue"); 240 assert.sameValue(log[11].args.length, 2, "throw then args.length"); 241 assert.sameValue(typeof log[11].args[0], "function", "throw then args[0]"); 242 assert.sameValue(typeof log[11].args[1], "function", "throw then args[1]"); 243 244 assert.sameValue(log[12].name, "get throw done (2)"); 245 assert.sameValue(log[12].thisValue.name, "throw-result-2", "get throw done thisValue"); 246 247 assert.sameValue(log[13].name, "get throw value (2)"); 248 assert.sameValue(log[13].thisValue.name, "throw-result-2", "get throw value thisValue"); 249 250 assert.sameValue(log[14].name, "after yield*"); 251 assert.sameValue(log[14].value, "throw-value-2"); 252 253 assert.sameValue(v.value, "return-value"); 254 assert.sameValue(v.done, true); 255 256 assert.sameValue(log.length, 15, "log.length"); 257 }).then($DONE, $DONE); 258 }).catch($DONE); 259 }).catch($DONE); 260 261 assert.sameValue(callCount, 1); 262 263 // Test the private fields do not appear as properties after set to value 264 assert( 265 !Object.prototype.hasOwnProperty.call(C.prototype, "#gen"), 266 "#gen does not appear as an own property on C prototype" 267 ); 268 assert( 269 !Object.prototype.hasOwnProperty.call(C, "#gen"), 270 "#gen does not appear as an own property on C constructor" 271 );