yield-promise-reject-next-yield-star-sync-iterator.js (2444B)
1 // |reftest| async 2 // This file was procedurally generated from the following sources: 3 // - src/async-generators/yield-promise-reject-next-yield-star-sync-iterator.case 4 // - src/async-generators/default/async-class-decl-private-method.template 5 /*--- 6 description: yield * (async iterator) is treated as throw value (Async Generator method as a ClassDeclaration element) 7 esid: prod-AsyncGeneratorPrivateMethod 8 features: [async-iteration, 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 let error = new Error(); 24 let iterable = [ 25 Promise.reject(error), 26 "unreachable" 27 ]; 28 29 30 var callCount = 0; 31 32 class C { 33 async *#gen() { 34 callCount += 1; 35 yield * iterable; 36 } 37 get gen() { return this.#gen; } 38 } 39 40 const c = new C(); 41 42 // Test the private fields do not appear as properties before set to value 43 assert( 44 !Object.prototype.hasOwnProperty.call(C.prototype, "#gen"), 45 "#gen does not appear as an own property on C prototype" 46 ); 47 assert( 48 !Object.prototype.hasOwnProperty.call(C, "#gen"), 49 "#gen does not appear as an own property on C constructor" 50 ); 51 assert( 52 !Object.prototype.hasOwnProperty.call(c, "#gen"), 53 "#gen does not appear as an own property on C instance" 54 ); 55 56 var iter = c.gen(); 57 58 iter.next().then(() => { 59 throw new Test262Error("Promise incorrectly resolved."); 60 }, rejectValue => { 61 // yield Promise.reject(error); 62 assert.sameValue(rejectValue, error); 63 64 iter.next().then(({done, value}) => { 65 // iter is closed now. 66 assert.sameValue(done, true, "The value of IteratorResult.done is `true`"); 67 assert.sameValue(value, undefined, "The value of IteratorResult.value is `undefined`"); 68 }).then($DONE, $DONE); 69 }).catch($DONE); 70 71 assert.sameValue(callCount, 1); 72 73 // Test the private fields do not appear as properties after set to value 74 assert( 75 !Object.prototype.hasOwnProperty.call(C.prototype, "#gen"), 76 "#gen does not appear as an own property on C prototype" 77 ); 78 assert( 79 !Object.prototype.hasOwnProperty.call(C, "#gen"), 80 "#gen does not appear as an own property on C constructor" 81 ); 82 assert( 83 !Object.prototype.hasOwnProperty.call(c, "#gen"), 84 "#gen does not appear as an own property on C instance" 85 );