yield-star-getiter-sync-not-callable-number-throw.js (3049B)
1 // |reftest| async 2 // This file was procedurally generated from the following sources: 3 // - src/async-generators/yield-star-getiter-sync-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.iterator] (number) (Async Generator method as a ClassDeclaration element) 7 esid: prod-AsyncGeneratorPrivateMethod 8 features: [Symbol.iterator, 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 b. If method is undefined, 37 i. Let syncMethod be ? GetMethod(obj, @@iterator). 38 ... 39 40 GetMethod ( V, P ) 41 42 ... 43 2. Let func be ? GetV(V, P). 44 ... 45 4. If IsCallable(func) is false, throw a TypeError exception. 46 ... 47 48 ---*/ 49 var obj = { 50 [Symbol.iterator]: 0 51 }; 52 53 54 55 var callCount = 0; 56 57 class C { 58 async *#gen() { 59 callCount += 1; 60 yield* obj; 61 throw new Test262Error('abrupt completion closes iter'); 62 63 } 64 get gen() { return this.#gen; } 65 } 66 67 const c = new C(); 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 assert( 79 !Object.prototype.hasOwnProperty.call(c, "#gen"), 80 "#gen does not appear as an own property on C instance" 81 ); 82 83 var iter = c.gen(); 84 85 iter.next().then(() => { 86 throw new Test262Error('Promise incorrectly fulfilled.'); 87 }, v => { 88 assert.sameValue(v.constructor, TypeError, "TypeError"); 89 90 iter.next().then(({ done, value }) => { 91 assert.sameValue(done, true, 'the iterator is completed'); 92 assert.sameValue(value, undefined, 'value is undefined'); 93 }).then($DONE, $DONE); 94 }).catch($DONE); 95 96 assert.sameValue(callCount, 1); 97 98 // Test the private fields do not appear as properties after set to value 99 assert( 100 !Object.prototype.hasOwnProperty.call(C.prototype, "#gen"), 101 "#gen does not appear as an own property on C prototype" 102 ); 103 assert( 104 !Object.prototype.hasOwnProperty.call(C, "#gen"), 105 "#gen does not appear as an own property on C constructor" 106 ); 107 assert( 108 !Object.prototype.hasOwnProperty.call(c, "#gen"), 109 "#gen does not appear as an own property on C instance" 110 );