same-line-async-gen-private-names.js (2397B)
1 // |reftest| async 2 // This file was procedurally generated from the following sources: 3 // - src/class-elements/private-names.case 4 // - src/class-elements/productions/cls-expr-after-same-line-async-gen.template 5 /*--- 6 description: private names (field definitions after an async generator in the same line) 7 esid: prod-FieldDefinition 8 features: [class-fields-private, class, class-fields-public, async-iteration] 9 flags: [generated, async] 10 includes: [propertyHelper.js] 11 info: | 12 ClassElement : 13 ... 14 FieldDefinition ; 15 16 FieldDefinition : 17 ClassElementName Initializer_opt 18 19 ClassElementName : 20 PrivateName 21 22 PrivateName : 23 # IdentifierName 24 25 ---*/ 26 27 28 var C = class { 29 async *m() { return 42; } #x; #y; 30 x() { 31 this.#x = 42; 32 return this.#x; 33 } 34 y() { 35 this.#y = 43; 36 return this.#y; 37 } 38 } 39 40 var c = new C(); 41 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.sameValue(c.m, C.prototype.m); 47 48 verifyProperty(C.prototype, "m", { 49 enumerable: false, 50 configurable: true, 51 writable: true, 52 }, {restore: true}); 53 54 c.m().next().then(function(v) { 55 assert.sameValue(v.value, 42); 56 assert.sameValue(v.done, true); 57 58 function assertions() { 59 // Cover $DONE handler for async cases. 60 function $DONE(error) { 61 if (error) { 62 throw new Test262Error('Test262:AsyncTestFailure') 63 } 64 } 65 // Test the private fields do not appear as properties before set to value 66 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#x"), "test 1"); 67 assert(!Object.prototype.hasOwnProperty.call(C, "#x"), "test 2"); 68 assert(!Object.prototype.hasOwnProperty.call(c, "#x"), "test 3"); 69 70 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#y"), "test 4"); 71 assert(!Object.prototype.hasOwnProperty.call(C, "#y"), "test 5"); 72 assert(!Object.prototype.hasOwnProperty.call(c, "#y"), "test 6"); 73 74 // Test if private fields can be sucessfully accessed and set to value 75 assert.sameValue(c.x(), 42, "test 7"); 76 assert.sameValue(c.y(), 43, "test 8"); 77 78 // Test the private fields do not appear as properties before after set to value 79 assert(!Object.prototype.hasOwnProperty.call(c, "#x"), "test 9"); 80 assert(!Object.prototype.hasOwnProperty.call(c, "#y"), "test 10"); 81 } 82 83 return Promise.resolve(assertions()); 84 }).then($DONE, $DONE);