yield-star-sync-throw.js (6957B)
1 // |reftest| async 2 // This file was procedurally generated from the following sources: 3 // - src/async-generators/yield-star-sync-throw.case 4 // - src/async-generators/default/async-class-decl-static-private-method.template 5 /*--- 6 description: execution order for yield* with sync iterator and throw() (Static async generator method as a ClassDeclaration element) 7 esid: prod-AsyncGeneratorPrivateMethod 8 features: [Symbol.iterator, async-iteration, 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 33 ? Await(innerResult). 34 ... 35 5. Let done be ? IteratorComplete(innerResult). 36 6. If done is true, then 37 a. Return ? IteratorValue(innerResult). 38 7. Let received be GeneratorYield(innerResult). 39 ... 40 41 %AsyncFromSyncIteratorPrototype%.throw ( value ) 42 43 ... 44 5. Let throw be GetMethod(syncIterator, "throw"). 45 ... 46 8. Let throwResult be Call(throw, syncIterator, « value »). 47 ... 48 11. Let throwValue be IteratorValue(throwResult). 49 ... 50 13. Let throwDone be IteratorComplete(throwResult). 51 ... 52 16. Perform ! Call(valueWrapperCapability.[[Resolve]], undefined, 53 « throwValue »). 54 ... 55 18. Set onFulfilled.[[Done]] to throwDone. 56 19. Perform ! PerformPromiseThen(valueWrapperCapability.[[Promise]], 57 onFulfilled, undefined, promiseCapability). 58 ... 59 60 ---*/ 61 var log = []; 62 var obj = { 63 [Symbol.iterator]() { 64 var throwCount = 0; 65 return { 66 name: "syncIterator", 67 get next() { 68 log.push({ name: "get next" }); 69 return function() { 70 return { 71 value: "next-value-1", 72 done: false 73 }; 74 }; 75 }, 76 get throw() { 77 log.push({ 78 name: "get throw", 79 thisValue: this 80 }); 81 return function() { 82 log.push({ 83 name: "call throw", 84 thisValue: this, 85 args: [...arguments] 86 }); 87 88 throwCount++; 89 if (throwCount == 1) { 90 return { 91 name: "throw-result-1", 92 get value() { 93 log.push({ 94 name: "get throw value (1)", 95 thisValue: this 96 }); 97 return "throw-value-1"; 98 }, 99 get done() { 100 log.push({ 101 name: "get throw done (1)", 102 thisValue: this 103 }); 104 return false; 105 } 106 }; 107 } 108 109 return { 110 name: "throw-result-2", 111 get value() { 112 log.push({ 113 name: "get throw value (2)", 114 thisValue: this 115 }); 116 return "throw-value-2"; 117 }, 118 get done() { 119 log.push({ 120 name: "get throw done (2)", 121 thisValue: this 122 }); 123 return true; 124 } 125 }; 126 }; 127 } 128 }; 129 } 130 }; 131 132 133 134 var callCount = 0; 135 136 class C { 137 static async *#gen() { 138 callCount += 1; 139 log.push({ name: "before yield*" }); 140 var v = yield* obj; 141 log.push({ 142 name: "after yield*", 143 value: v 144 }); 145 return "return-value"; 146 147 } 148 static get gen() { return this.#gen; } 149 } 150 151 // Test the private fields do not appear as properties before set to value 152 assert( 153 !Object.prototype.hasOwnProperty.call(C.prototype, "#gen"), 154 "#gen does not appear as an own property on C prototype" 155 ); 156 assert( 157 !Object.prototype.hasOwnProperty.call(C, "#gen"), 158 "#gen does not appear as an own property on C constructor" 159 ); 160 161 var iter = C.gen(); 162 163 assert.sameValue(log.length, 0, "log.length"); 164 165 iter.next().then(v => { 166 assert.sameValue(log[0].name, "before yield*"); 167 168 assert.sameValue(log[1].name, "get next"); 169 170 assert.sameValue(v.value, "next-value-1"); 171 assert.sameValue(v.done, false); 172 173 assert.sameValue(log.length, 2, "log.length"); 174 175 iter.throw("throw-arg-1").then(v => { 176 assert.sameValue(log[2].name, "get throw"); 177 assert.sameValue(log[2].thisValue.name, "syncIterator", "get throw thisValue"); 178 179 assert.sameValue(log[3].name, "call throw"); 180 assert.sameValue(log[3].thisValue.name, "syncIterator", "throw thisValue"); 181 assert.sameValue(log[3].args.length, 1, "throw args.length"); 182 assert.sameValue(log[3].args[0], "throw-arg-1", "throw args[0]"); 183 184 assert.sameValue(log[4].name, "get throw done (1)"); 185 assert.sameValue(log[4].thisValue.name, "throw-result-1", "get throw done thisValue"); 186 187 assert.sameValue(log[5].name, "get throw value (1)"); 188 assert.sameValue(log[5].thisValue.name, "throw-result-1", "get throw value thisValue"); 189 190 assert.sameValue(v.value, "throw-value-1"); 191 assert.sameValue(v.done, false); 192 193 assert.sameValue(log.length, 6, "log.length"); 194 195 iter.throw().then(v => { 196 assert.sameValue(log[6].name, "get throw"); 197 assert.sameValue(log[6].thisValue.name, "syncIterator", "get throw thisValue"); 198 199 assert.sameValue(log[7].name, "call throw"); 200 assert.sameValue(log[7].thisValue.name, "syncIterator", "throw thisValue"); 201 assert.sameValue(log[7].args.length, 1, "throw args.length"); 202 assert.sameValue(log[7].args[0], undefined, "throw args[0]"); 203 204 assert.sameValue(log[8].name, "get throw done (2)"); 205 assert.sameValue(log[8].thisValue.name, "throw-result-2", "get throw done thisValue"); 206 207 assert.sameValue(log[9].name, "get throw value (2)"); 208 assert.sameValue(log[9].thisValue.name, "throw-result-2", "get throw value thisValue"); 209 210 assert.sameValue(log[10].name, "after yield*"); 211 assert.sameValue(log[10].value, "throw-value-2"); 212 213 assert.sameValue(v.value, "return-value"); 214 assert.sameValue(v.done, true); 215 216 assert.sameValue(log.length, 11, "log.length"); 217 }).then($DONE, $DONE); 218 }).catch($DONE); 219 }).catch($DONE); 220 221 assert.sameValue(callCount, 1); 222 223 // Test the private fields do not appear as properties after set to value 224 assert( 225 !Object.prototype.hasOwnProperty.call(C.prototype, "#gen"), 226 "#gen does not appear as an own property on C prototype" 227 ); 228 assert( 229 !Object.prototype.hasOwnProperty.call(C, "#gen"), 230 "#gen does not appear as an own property on C constructor" 231 );