yield-star-getiter-async-get-abrupt.js (2803B)
1 // |reftest| async 2 // This file was procedurally generated from the following sources: 3 // - src/async-generators/yield-star-getiter-async-get-abrupt.case 4 // - src/async-generators/default/async-class-expr-static-private-method.template 5 /*--- 6 description: Abrupt completion while getting [Symbol.asyncIterator] (Static async generator method as a ClassExpression element) 7 esid: prod-AsyncGeneratorPrivateMethod 8 features: [Symbol.iterator, Symbol.asyncIterator, 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 1. Let exprRef be the result of evaluating AssignmentExpression. 26 2. Let value be ? GetValue(exprRef). 27 3. Let generatorKind be ! GetGeneratorKind(). 28 4. Let iterator be ? GetIterator(value, generatorKind). 29 ... 30 31 GetIterator ( obj [ , hint ] ) 32 33 ... 34 3. If hint is async, 35 a. Set method to ? GetMethod(obj, @@asyncIterator). 36 ... 37 38 GetMethod ( V, P ) 39 40 ... 41 2. Let func be ? GetV(V, P). 42 ... 43 44 ---*/ 45 var reason = {}; 46 var obj = { 47 get [Symbol.iterator]() { 48 throw new Test262Error('it should not get Symbol.iterator'); 49 }, 50 get [Symbol.asyncIterator]() { 51 throw reason; 52 } 53 }; 54 55 56 57 var callCount = 0; 58 59 var C = class { 60 static async *#gen() { 61 callCount += 1; 62 yield* obj; 63 throw new Test262Error('abrupt completion closes iter'); 64 65 } 66 static get gen() { return this.#gen; } 67 } 68 69 // Test the private fields do not appear as properties before set to value 70 assert( 71 !Object.prototype.hasOwnProperty.call(C.prototype, "#gen"), 72 "#gen does not appear as an own property on C prototype" 73 ); 74 assert( 75 !Object.prototype.hasOwnProperty.call(C, "#gen"), 76 "#gen does not appear as an own property on C constructor" 77 ); 78 79 var iter = C.gen(); 80 81 iter.next().then(() => { 82 throw new Test262Error('Promise incorrectly fulfilled.'); 83 }, v => { 84 assert.sameValue(v, reason, "reject reason"); 85 86 iter.next().then(({ done, value }) => { 87 assert.sameValue(done, true, 'the iterator is completed'); 88 assert.sameValue(value, undefined, 'value is undefined'); 89 }).then($DONE, $DONE); 90 }).catch($DONE); 91 92 assert.sameValue(callCount, 1); 93 94 // Test the private fields do not appear as properties after set to value 95 assert( 96 !Object.prototype.hasOwnProperty.call(C.prototype, "#gen"), 97 "#gen does not appear as an own property on C prototype" 98 ); 99 assert( 100 !Object.prototype.hasOwnProperty.call(C, "#gen"), 101 "#gen does not appear as an own property on C constructor" 102 );