yield-star-sync-next.js (7976B)
1 // |reftest| async 2 // This file was procedurally generated from the following sources: 3 // - src/async-generators/yield-star-sync-next.case 4 // - src/async-generators/default/async-class-expr-private-method.template 5 /*--- 6 description: execution order for yield* with sync iterator and next() (Async generator method as a ClassExpression element) 7 esid: prod-AsyncGeneratorPrivateMethod 8 features: [Symbol.iterator, async-iteration, Symbol.asyncIterator, class-methods-private] 9 flags: [generated, async] 10 info: | 11 ClassElement : 12 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 2. Let value be ? GetValue(exprRef). 27 3. Let generatorKind be ! GetGeneratorKind(). 28 4. Let iterator be ? GetIterator(value, generatorKind). 29 5. Let received be NormalCompletion(undefined). 30 6. Repeat 31 a. If received.[[Type]] is normal, then 32 i. Let innerResult be ? IteratorNext(iterator, received.[[Value]]). 33 ii. Let innerResult be ? Invoke(iterator, "next", 34 « received.[[Value]] »). 35 iii. If generatorKind is async, then set innerResult to 36 ? Await(innerResult). 37 ... 38 v. Let done be ? IteratorComplete(innerResult). 39 vi. If done is true, then 40 1. Return ? IteratorValue(innerResult). 41 vii. Let received be GeneratorYield(innerResult). 42 ... 43 44 GetIterator ( obj [ , hint ] ) 45 46 ... 47 3. If hint is async, 48 a. Set method to ? GetMethod(obj, @@asyncIterator). 49 b. If method is undefined, 50 i. Let syncMethod be ? GetMethod(obj, @@iterator). 51 ii. Let syncIterator be ? Call(syncMethod, obj). 52 iii. Return ? CreateAsyncFromSyncIterator(syncIterator). 53 ... 54 55 %AsyncFromSyncIteratorPrototype%.next ( value ) 56 57 ... 58 5. Let nextResult be IteratorNext(syncIterator, value). 59 ... 60 7. Let nextValue be IteratorValue(nextResult). 61 ... 62 9. Let nextDone be IteratorComplete(nextResult). 63 ... 64 12. Perform ! Call(valueWrapperCapability.[[Resolve]], undefined, 65 « nextValue »). 66 ... 67 14. Set onFulfilled.[[Done]] to nextDone. 68 15. Perform ! PerformPromiseThen(valueWrapperCapability.[[Promise]], 69 onFulfilled, undefined, promiseCapability). 70 ... 71 72 Async Iterator Value Unwrap Functions 73 74 1. Return ! CreateIterResultObject(value, F.[[Done]]). 75 76 ---*/ 77 var log = []; 78 var obj = { 79 get [Symbol.iterator]() { 80 log.push({ 81 name: "get [Symbol.iterator]", 82 thisValue: this 83 }); 84 return function() { 85 log.push({ 86 name: "call [Symbol.iterator]", 87 thisValue: this, 88 args: [...arguments] 89 }); 90 var nextCount = 0; 91 return { 92 name: "syncIterator", 93 get next() { 94 log.push({ 95 name: "get next", 96 thisValue: this 97 }); 98 return function() { 99 log.push({ 100 name: "call next", 101 thisValue: this, 102 args: [...arguments] 103 }); 104 105 nextCount++; 106 if (nextCount == 1) { 107 return { 108 name: "next-result-1", 109 get value() { 110 log.push({ 111 name: "get next value (1)", 112 thisValue: this 113 }); 114 return "next-value-1"; 115 }, 116 get done() { 117 log.push({ 118 name: "get next done (1)", 119 thisValue: this 120 }); 121 return false; 122 } 123 }; 124 } 125 126 return { 127 name: "next-result-2", 128 get value() { 129 log.push({ 130 name: "get next value (2)", 131 thisValue: this 132 }); 133 return "next-value-2"; 134 }, 135 get done() { 136 log.push({ 137 name: "get next done (2)", 138 thisValue: this 139 }); 140 return true; 141 } 142 }; 143 }; 144 } 145 }; 146 }; 147 }, 148 get [Symbol.asyncIterator]() { 149 log.push({ name: "get [Symbol.asyncIterator]" }); 150 return null; 151 } 152 }; 153 154 155 156 var callCount = 0; 157 158 var C = class { 159 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 get gen() { return this.#gen; } 171 } 172 173 const c = new C(); 174 175 // Test the private fields do not appear as properties before set to value 176 assert( 177 !Object.prototype.hasOwnProperty.call(C.prototype, "#gen"), 178 "#gen does not appear as an own property on C prototype" 179 ); 180 assert( 181 !Object.prototype.hasOwnProperty.call(C, "#gen"), 182 "#gen does not appear as an own property on C constructor" 183 ); 184 assert( 185 !Object.prototype.hasOwnProperty.call(c, "#gen"), 186 "#gen does not appear as an own property on C instance" 187 ); 188 189 var iter = c.gen(); 190 191 assert.sameValue(log.length, 0, "log.length"); 192 193 iter.next("next-arg-1").then(v => { 194 assert.sameValue(log[0].name, "before yield*"); 195 196 assert.sameValue(log[1].name, "get [Symbol.asyncIterator]"); 197 198 assert.sameValue(log[2].name, "get [Symbol.iterator]"); 199 assert.sameValue(log[2].thisValue, obj, "get [Symbol.iterator] thisValue"); 200 201 assert.sameValue(log[3].name, "call [Symbol.iterator]"); 202 assert.sameValue(log[3].thisValue, obj, "[Symbol.iterator] thisValue"); 203 assert.sameValue(log[3].args.length, 0, "[Symbol.iterator] args.length"); 204 205 assert.sameValue(log[4].name, "get next"); 206 assert.sameValue(log[4].thisValue.name, "syncIterator", "get next thisValue"); 207 208 assert.sameValue(log[5].name, "call next"); 209 assert.sameValue(log[5].thisValue.name, "syncIterator", "next thisValue"); 210 assert.sameValue(log[5].args.length, 1, "next args.length"); 211 assert.sameValue(log[5].args[0], undefined, "next args[0]"); 212 213 assert.sameValue(log[6].name, "get next done (1)"); 214 assert.sameValue(log[6].thisValue.name, "next-result-1", "get next done thisValue"); 215 216 assert.sameValue(log[7].name, "get next value (1)"); 217 assert.sameValue(log[7].thisValue.name, "next-result-1", "get next value thisValue"); 218 219 assert.sameValue(v.value, "next-value-1"); 220 assert.sameValue(v.done, false); 221 222 assert.sameValue(log.length, 8, "log.length"); 223 224 iter.next("next-arg-2").then(v => { 225 assert.sameValue(log[8].name, "call next"); 226 assert.sameValue(log[8].thisValue.name, "syncIterator", "next thisValue"); 227 assert.sameValue(log[8].args.length, 1, "next args.length"); 228 assert.sameValue(log[8].args[0], "next-arg-2", "next args[0]"); 229 230 assert.sameValue(log[9].name, "get next done (2)"); 231 assert.sameValue(log[9].thisValue.name, "next-result-2", "get next done thisValue"); 232 233 assert.sameValue(log[10].name, "get next value (2)"); 234 assert.sameValue(log[10].thisValue.name, "next-result-2", "get next value thisValue"); 235 236 assert.sameValue(log[11].name, "after yield*"); 237 assert.sameValue(log[11].value, "next-value-2"); 238 239 assert.sameValue(v.value, "return-value"); 240 assert.sameValue(v.done, true); 241 242 assert.sameValue(log.length, 12, "log.length"); 243 }).then($DONE, $DONE); 244 }).catch($DONE); 245 246 assert.sameValue(callCount, 1); 247 248 // Test the private fields do not appear as properties after set to value 249 assert( 250 !Object.prototype.hasOwnProperty.call(C.prototype, "#gen"), 251 "#gen does not appear as an own property on C prototype" 252 ); 253 assert( 254 !Object.prototype.hasOwnProperty.call(C, "#gen"), 255 "#gen does not appear as an own property on C constructor" 256 ); 257 assert( 258 !Object.prototype.hasOwnProperty.call(c, "#gen"), 259 "#gen does not appear as an own property on C instance" 260 );