after-same-line-static-gen-static-private-fields.js (2138B)
1 // This file was procedurally generated from the following sources: 2 // - src/class-elements/static-private-fields.case 3 // - src/class-elements/productions/cls-decl-after-same-line-static-gen.template 4 /*--- 5 description: static private fields (field definitions after a static generator in the same line) 6 esid: prod-FieldDefinition 7 features: [class-static-fields-private, generators, 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 class C { 28 static *m() { return 42; } static #x; static #y; 29 static x() { 30 this.#x = 42; 31 return this.#x; 32 } 33 static y() { 34 this.#y = 43; 35 return this.#y; 36 } 37 } 38 39 var c = new C(); 40 41 assert.sameValue(C.m().next().value, 42); 42 assert( 43 !Object.prototype.hasOwnProperty.call(c, "m"), 44 "m doesn't appear as an own property on the C instance" 45 ); 46 assert( 47 !Object.prototype.hasOwnProperty.call(C.prototype, "m"), 48 "m doesn't appear as an own property on the C prototype" 49 ); 50 51 verifyProperty(C, "m", { 52 enumerable: false, 53 configurable: true, 54 writable: true, 55 }); 56 57 // Test the private fields do not appear as properties before set to value 58 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#x"), "test 1"); 59 assert(!Object.prototype.hasOwnProperty.call(C, "#x"), "test 2"); 60 assert(!Object.prototype.hasOwnProperty.call(c, "#x"), "test 3"); 61 62 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#y"), "test 4"); 63 assert(!Object.prototype.hasOwnProperty.call(C, "#y"), "test 5"); 64 assert(!Object.prototype.hasOwnProperty.call(c, "#y"), "test 6"); 65 66 // Test if private fields can be sucessfully accessed and set to value 67 assert.sameValue(C.x(), 42, "test 7"); 68 assert.sameValue(C.y(), 43, "test 8"); 69 70 // Test the private fields do not appear as properties before after set to value 71 assert(!Object.prototype.hasOwnProperty.call(C, "#x"), "test 9"); 72 assert(!Object.prototype.hasOwnProperty.call(C, "#y"), "test 10"); 73 74 reportCompare(0, 0);