regular-definitions-static-private-methods-with-fields.js (2413B)
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-expr-regular-definitions.template 4 /*--- 5 description: static private methods with fields (regular fields defintion) 6 esid: prod-FieldDefinition 7 features: [class-static-methods-private, class-static-fields-private, class, class-fields-public] 8 flags: [generated] 9 info: | 10 ClassElement : 11 ... 12 static FieldDefinition ; 13 14 FieldDefinition : 15 ClassElementName Initializer_opt 16 17 ClassElementName : 18 PrivateName 19 20 PrivateName : 21 # IdentifierName 22 23 ---*/ 24 25 26 var C = class { 27 static #xVal; static #yVal 28 static #x(value) { 29 this.#xVal = value; 30 return this.#xVal; 31 } 32 static #y(value) { 33 this.#yVal = value; 34 return this.#yVal; 35 } 36 static x() { 37 return this.#x(42); 38 } 39 static y() { 40 return this.#y(43); 41 } 42 } 43 44 var c = new C(); 45 46 // Test the private methods do not appear as properties before set to value 47 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#x"), "test 1"); 48 assert(!Object.prototype.hasOwnProperty.call(C, "#x"), "test 2"); 49 assert(!Object.prototype.hasOwnProperty.call(c, "#x"), "test 3"); 50 51 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#y"), "test 4"); 52 assert(!Object.prototype.hasOwnProperty.call(C, "#y"), "test 5"); 53 assert(!Object.prototype.hasOwnProperty.call(c, "#y"), "test 6"); 54 55 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#xVal"), "test 7"); 56 assert(!Object.prototype.hasOwnProperty.call(C, "#xVal"), "test 8"); 57 assert(!Object.prototype.hasOwnProperty.call(c, "#xVal"), "test 9"); 58 59 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#yVal"), "test 10"); 60 assert(!Object.prototype.hasOwnProperty.call(C, "#yVal"), "test 11"); 61 assert(!Object.prototype.hasOwnProperty.call(c, "#yVal"), "test 12"); 62 63 // Test if private fields can be sucessfully accessed and set to value 64 assert.sameValue(C.x(), 42, "test 13"); 65 assert.sameValue(C.y(), 43, "test 14"); 66 67 // Test the private fields do not appear as properties before after set to value 68 assert(!Object.prototype.hasOwnProperty.call(C, "#x"), "test 15"); 69 assert(!Object.prototype.hasOwnProperty.call(C, "#y"), "test 16"); 70 71 assert(!Object.prototype.hasOwnProperty.call(C, "#xVal"), "test 17"); 72 assert(!Object.prototype.hasOwnProperty.call(C, "#yVal"), "test 18"); 73 74 reportCompare(0, 0);