multiple-definitions-static-private-methods-with-fields.js (3914B)
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-multiple-definitions.template 4 /*--- 5 description: static private methods with fields (multiple fields definitions) 6 esid: prod-FieldDefinition 7 features: [class-static-methods-private, class-static-fields-private, class, class-fields-public] 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 var C = class { 28 foo = "foobar"; 29 m() { return 42 } 30 static #xVal; static #yVal 31 m2() { return 39 } 32 bar = "barbaz"; 33 static #x(value) { 34 this.#xVal = value; 35 return this.#xVal; 36 } 37 static #y(value) { 38 this.#yVal = value; 39 return this.#yVal; 40 } 41 static x() { 42 return this.#x(42); 43 } 44 static y() { 45 return this.#y(43); 46 } 47 } 48 49 var c = new C(); 50 51 assert.sameValue(c.m(), 42); 52 assert( 53 !Object.prototype.hasOwnProperty.call(c, "m"), 54 "m doesn't appear as an own property on the C instance" 55 ); 56 assert.sameValue(c.m, C.prototype.m); 57 58 verifyProperty(C.prototype, "m", { 59 enumerable: false, 60 configurable: true, 61 writable: true, 62 }); 63 64 assert.sameValue(c.m2(), 39); 65 assert( 66 !Object.prototype.hasOwnProperty.call(c, "m2"), 67 "m2 doesn't appear as an own property on the C instance" 68 ); 69 assert.sameValue(c.m2, C.prototype.m2); 70 71 verifyProperty(C.prototype, "m2", { 72 enumerable: false, 73 configurable: true, 74 writable: true, 75 }); 76 77 assert.sameValue(c.foo, "foobar"); 78 assert( 79 !Object.prototype.hasOwnProperty.call(C, "foo"), 80 "foo doesn't appear as an own property on the C constructor" 81 ); 82 assert( 83 !Object.prototype.hasOwnProperty.call(C.prototype, "foo"), 84 "foo doesn't appear as an own property on the C prototype" 85 ); 86 87 verifyProperty(c, "foo", { 88 value: "foobar", 89 enumerable: true, 90 configurable: true, 91 writable: true, 92 }); 93 94 assert.sameValue(c.bar, "barbaz"); 95 assert( 96 !Object.prototype.hasOwnProperty.call(C, "bar"), 97 "bar doesn't appear as an own property on the C constructor" 98 ); 99 assert( 100 !Object.prototype.hasOwnProperty.call(C.prototype, "bar"), 101 "bar doesn't appear as an own property on the C prototype" 102 ); 103 104 verifyProperty(c, "bar", { 105 value: "barbaz", 106 enumerable: true, 107 configurable: true, 108 writable: true, 109 }); 110 111 // Test the private methods do not appear as properties before set to value 112 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#x"), "test 1"); 113 assert(!Object.prototype.hasOwnProperty.call(C, "#x"), "test 2"); 114 assert(!Object.prototype.hasOwnProperty.call(c, "#x"), "test 3"); 115 116 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#y"), "test 4"); 117 assert(!Object.prototype.hasOwnProperty.call(C, "#y"), "test 5"); 118 assert(!Object.prototype.hasOwnProperty.call(c, "#y"), "test 6"); 119 120 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#xVal"), "test 7"); 121 assert(!Object.prototype.hasOwnProperty.call(C, "#xVal"), "test 8"); 122 assert(!Object.prototype.hasOwnProperty.call(c, "#xVal"), "test 9"); 123 124 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#yVal"), "test 10"); 125 assert(!Object.prototype.hasOwnProperty.call(C, "#yVal"), "test 11"); 126 assert(!Object.prototype.hasOwnProperty.call(c, "#yVal"), "test 12"); 127 128 // Test if private fields can be sucessfully accessed and set to value 129 assert.sameValue(C.x(), 42, "test 13"); 130 assert.sameValue(C.y(), 43, "test 14"); 131 132 // Test the private fields do not appear as properties before after set to value 133 assert(!Object.prototype.hasOwnProperty.call(C, "#x"), "test 15"); 134 assert(!Object.prototype.hasOwnProperty.call(C, "#y"), "test 16"); 135 136 assert(!Object.prototype.hasOwnProperty.call(C, "#xVal"), "test 17"); 137 assert(!Object.prototype.hasOwnProperty.call(C, "#yVal"), "test 18"); 138 139 reportCompare(0, 0);