same-line-async-gen-static-private-methods-with-fields.js (3243B)
1 // |reftest| async 2 // This file was procedurally generated from the following sources: 3 // - src/class-elements/static-private-methods-with-fields.case 4 // - src/class-elements/productions/cls-decl-after-same-line-async-gen.template 5 /*--- 6 description: static private methods with fields (field definitions after an async generator in the same line) 7 esid: prod-FieldDefinition 8 features: [class-static-methods-private, class-static-fields-private, class, class-fields-public, async-iteration] 9 flags: [generated, async] 10 includes: [propertyHelper.js] 11 info: | 12 ClassElement : 13 ... 14 static FieldDefinition ; 15 16 FieldDefinition : 17 ClassElementName Initializer_opt 18 19 ClassElementName : 20 PrivateName 21 22 PrivateName : 23 # IdentifierName 24 25 ---*/ 26 27 28 class C { 29 async *m() { return 42; } static #xVal; static #yVal; 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( 49 !Object.prototype.hasOwnProperty.call(c, "m"), 50 "m doesn't appear as an own property on the C instance" 51 ); 52 assert.sameValue(c.m, C.prototype.m); 53 54 verifyProperty(C.prototype, "m", { 55 enumerable: false, 56 configurable: true, 57 writable: true, 58 }, {restore: true}); 59 60 c.m().next().then(function(v) { 61 assert.sameValue(v.value, 42); 62 assert.sameValue(v.done, true); 63 64 function assertions() { 65 // Cover $DONE handler for async cases. 66 function $DONE(error) { 67 if (error) { 68 throw new Test262Error('Test262:AsyncTestFailure') 69 } 70 } 71 // Test the private methods do not appear as properties before set to value 72 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#x"), "test 1"); 73 assert(!Object.prototype.hasOwnProperty.call(C, "#x"), "test 2"); 74 assert(!Object.prototype.hasOwnProperty.call(c, "#x"), "test 3"); 75 76 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#y"), "test 4"); 77 assert(!Object.prototype.hasOwnProperty.call(C, "#y"), "test 5"); 78 assert(!Object.prototype.hasOwnProperty.call(c, "#y"), "test 6"); 79 80 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#xVal"), "test 7"); 81 assert(!Object.prototype.hasOwnProperty.call(C, "#xVal"), "test 8"); 82 assert(!Object.prototype.hasOwnProperty.call(c, "#xVal"), "test 9"); 83 84 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#yVal"), "test 10"); 85 assert(!Object.prototype.hasOwnProperty.call(C, "#yVal"), "test 11"); 86 assert(!Object.prototype.hasOwnProperty.call(c, "#yVal"), "test 12"); 87 88 // Test if private fields can be sucessfully accessed and set to value 89 assert.sameValue(C.x(), 42, "test 13"); 90 assert.sameValue(C.y(), 43, "test 14"); 91 92 // Test the private fields do not appear as properties before after set to value 93 assert(!Object.prototype.hasOwnProperty.call(C, "#x"), "test 15"); 94 assert(!Object.prototype.hasOwnProperty.call(C, "#y"), "test 16"); 95 96 assert(!Object.prototype.hasOwnProperty.call(C, "#xVal"), "test 17"); 97 assert(!Object.prototype.hasOwnProperty.call(C, "#yVal"), "test 18"); 98 } 99 100 return Promise.resolve(assertions()); 101 }).then($DONE, $DONE);