yield-identifier-strict-strict.js (2115B)
1 // |reftest| error:SyntaxError 2 'use strict'; 3 // This file was procedurally generated from the following sources: 4 // - src/generators/yield-identifier-strict.case 5 // - src/generators/default/class-decl-private-method.template 6 /*--- 7 description: It's an early error if the generator body has another function body with yield as an identifier in strict mode. (Generator private method as a ClassDeclaration element) 8 esid: prod-GeneratorPrivateMethod 9 features: [generators, class-methods-private] 10 flags: [generated, onlyStrict] 11 negative: 12 phase: parse 13 type: SyntaxError 14 info: | 15 ClassElement : 16 PrivateMethodDefinition 17 18 MethodDefinition : 19 GeneratorMethod 20 21 14.4 Generator Function Definitions 22 23 GeneratorMethod : 24 * PropertyName ( UniqueFormalParameters ) { GeneratorBody } 25 26 ---*/ 27 $DONOTEVALUATE(); 28 29 var callCount = 0; 30 31 class C { 32 *#gen() { 33 callCount += 1; 34 (function() { 35 var yield; 36 throw new Test262Error(); 37 }()) 38 } 39 get gen() { return this.#gen; } 40 } 41 42 const c = new C(); 43 44 // Test the private fields do not appear as properties before set to value 45 assert( 46 !Object.prototype.hasOwnProperty.call(C.prototype, "#gen"), 47 "Private field '#gen' does not appear as an own property on C prototype" 48 ); 49 assert( 50 !Object.prototype.hasOwnProperty.call(C, "#gen"), 51 "Private field '#gen' does not appear as an own property on C constructor" 52 ); 53 assert( 54 !Object.prototype.hasOwnProperty.call(c, "#gen"), 55 "Private field '#gen' does not appear as an own property on C instance" 56 ); 57 58 var iter = c.gen(); 59 60 61 62 assert.sameValue(callCount, 1); 63 64 // Test the private fields do not appear as properties after set to value 65 assert( 66 !Object.prototype.hasOwnProperty.call(C.prototype, "#gen"), 67 "Private field '#gen' does not appear as an own property on C prototype" 68 ); 69 assert( 70 !Object.prototype.hasOwnProperty.call(C, "#gen"), 71 "Private field '#gen' does not appear as an own property on C constructor" 72 ); 73 assert( 74 !Object.prototype.hasOwnProperty.call(c, "#gen"), 75 "Private field '#gen' does not appear as an own property on C instance" 76 );