yield-star-getiter-async-not-callable-number-throw.js (3142B)
1 // |reftest| async 2 // This file was procedurally generated from the following sources: 3 // - src/async-generators/yield-star-getiter-async-not-callable-number-throw.case 4 // - src/async-generators/default/async-class-decl-private-method.template 5 /*--- 6 description: Throws a TypeError on a non-callable [Symbol.asyncIterator] (number) (Async Generator method as a ClassDeclaration element) 7 esid: prod-AsyncGeneratorPrivateMethod 8 features: [Symbol.iterator, Symbol.asyncIterator, 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 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 3. If func is either undefined or null, return undefined. 43 4. If IsCallable(func) is false, throw a TypeError exception. 44 ... 45 46 ---*/ 47 var obj = { 48 get [Symbol.iterator]() { 49 throw new Test262Error('it should not get Symbol.iterator'); 50 }, 51 [Symbol.asyncIterator]: 0 52 }; 53 54 55 56 var callCount = 0; 57 58 class C { 59 async *#gen() { 60 callCount += 1; 61 yield* obj; 62 throw new Test262Error('abrupt completion closes iter'); 63 64 } 65 get gen() { return this.#gen; } 66 } 67 68 const c = new C(); 69 70 // Test the private fields do not appear as properties before set to value 71 assert( 72 !Object.prototype.hasOwnProperty.call(C.prototype, "#gen"), 73 "#gen does not appear as an own property on C prototype" 74 ); 75 assert( 76 !Object.prototype.hasOwnProperty.call(C, "#gen"), 77 "#gen does not appear as an own property on C constructor" 78 ); 79 assert( 80 !Object.prototype.hasOwnProperty.call(c, "#gen"), 81 "#gen does not appear as an own property on C instance" 82 ); 83 84 var iter = c.gen(); 85 86 iter.next().then(() => { 87 throw new Test262Error('Promise incorrectly fulfilled.'); 88 }, v => { 89 assert.sameValue(v.constructor, TypeError, "TypeError"); 90 91 iter.next().then(({ done, value }) => { 92 assert.sameValue(done, true, 'the iterator is completed'); 93 assert.sameValue(value, undefined, 'value is undefined'); 94 }).then($DONE, $DONE); 95 }).catch($DONE); 96 97 assert.sameValue(callCount, 1); 98 99 // Test the private fields do not appear as properties after set to value 100 assert( 101 !Object.prototype.hasOwnProperty.call(C.prototype, "#gen"), 102 "#gen does not appear as an own property on C prototype" 103 ); 104 assert( 105 !Object.prototype.hasOwnProperty.call(C, "#gen"), 106 "#gen does not appear as an own property on C constructor" 107 ); 108 assert( 109 !Object.prototype.hasOwnProperty.call(c, "#gen"), 110 "#gen does not appear as an own property on C instance" 111 );