new-sc-line-gen-static-private-methods-with-fields.js (2819B)
1 // This file was procedurally generated from the following sources: 2 // - src/class-elements/static-private-methods-with-fields.case 3 // - src/class-elements/productions/cls-decl-new-sc-line-generator.template 4 /*--- 5 description: static private methods with fields (field definitions followed by a method in a new line with a semicolon) 6 esid: prod-FieldDefinition 7 features: [class-static-methods-private, class-static-fields-private, class, class-fields-public, generators] 8 flags: [generated] 9 includes: [propertyHelper.js] 10 info: | 11 ClassElement : 12 ... 13 static FieldDefinition ; 14 15 FieldDefinition : 16 ClassElementName Initializer_opt 17 18 ClassElementName : 19 PrivateName 20 21 PrivateName : 22 # IdentifierName 23 24 ---*/ 25 26 27 class C { 28 static #xVal; static #yVal; 29 *m() { return 42; } 30 static #x(value) { 31 this.#xVal = value; 32 return this.#xVal; 33 } 34 static #y(value) { 35 this.#yVal = value; 36 return this.#yVal; 37 } 38 static x() { 39 return this.#x(42); 40 } 41 static y() { 42 return this.#y(43); 43 } 44 } 45 46 var c = new C(); 47 48 assert.sameValue(c.m().next().value, 42); 49 assert.sameValue(c.m, C.prototype.m); 50 assert( 51 !Object.prototype.hasOwnProperty.call(c, "m"), 52 "m doesn't appear as an own property on the C instance" 53 ); 54 55 verifyProperty(C.prototype, "m", { 56 enumerable: false, 57 configurable: true, 58 writable: true, 59 }); 60 61 // Test the private methods do not appear as properties before set to value 62 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#x"), "test 1"); 63 assert(!Object.prototype.hasOwnProperty.call(C, "#x"), "test 2"); 64 assert(!Object.prototype.hasOwnProperty.call(c, "#x"), "test 3"); 65 66 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#y"), "test 4"); 67 assert(!Object.prototype.hasOwnProperty.call(C, "#y"), "test 5"); 68 assert(!Object.prototype.hasOwnProperty.call(c, "#y"), "test 6"); 69 70 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#xVal"), "test 7"); 71 assert(!Object.prototype.hasOwnProperty.call(C, "#xVal"), "test 8"); 72 assert(!Object.prototype.hasOwnProperty.call(c, "#xVal"), "test 9"); 73 74 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#yVal"), "test 10"); 75 assert(!Object.prototype.hasOwnProperty.call(C, "#yVal"), "test 11"); 76 assert(!Object.prototype.hasOwnProperty.call(c, "#yVal"), "test 12"); 77 78 // Test if private fields can be sucessfully accessed and set to value 79 assert.sameValue(C.x(), 42, "test 13"); 80 assert.sameValue(C.y(), 43, "test 14"); 81 82 // Test the private fields do not appear as properties before after set to value 83 assert(!Object.prototype.hasOwnProperty.call(C, "#x"), "test 15"); 84 assert(!Object.prototype.hasOwnProperty.call(C, "#y"), "test 16"); 85 86 assert(!Object.prototype.hasOwnProperty.call(C, "#xVal"), "test 17"); 87 assert(!Object.prototype.hasOwnProperty.call(C, "#yVal"), "test 18"); 88 89 reportCompare(0, 0);