field-declaration.js (2355B)
1 // This file was procedurally generated from the following sources: 2 // - src/class-elements/field-declaration.case 3 // - src/class-elements/default/cls-decl.template 4 /*--- 5 description: Fields are defined (field definitions in a class declaration) 6 esid: prod-FieldDefinition 7 features: [class-fields-public, class] 8 flags: [generated] 9 includes: [propertyHelper.js] 10 info: | 11 Updated Productions 12 13 ClassElement : 14 ... 15 FieldDefinition ; 16 17 FieldDefinition : 18 ClassElementName Initializer_opt 19 20 ClassElementName : 21 PropertyName 22 23 PropertyName : 24 LiteralPropertyName 25 ComputedPropertyName 26 27 LiteralPropertyName : 28 IdentifierName 29 StringLiteral 30 NumericLiteral 31 32 ClassDefinitionEvaluation: 33 ... 34 35 26. Let instanceFields be a new empty List. 36 28. For each ClassElement e in order from elements, 37 a. If IsStatic of e is false, then 38 i. Let field be the result of performing ClassElementEvaluation for e with arguments proto and false. 39 b. ... 40 c. ... 41 d. If field is not empty, append field to instanceFields. 42 43 ... 44 45 30. Set F.[[Fields]] to instanceFields. 46 ... 47 48 ---*/ 49 var computed = 'h'; 50 51 52 class C { 53 f = 'test262'; 54 'g'; 55 0 = 'bar'; 56 [computed]; 57 } 58 59 let c = new C(); 60 61 assert.sameValue(C.f, undefined); 62 assert.sameValue(C.g, undefined); 63 assert.sameValue(C.h, undefined); 64 assert.sameValue(C[0], undefined); 65 66 assert( 67 !Object.prototype.hasOwnProperty.call(C, 'f'), 68 "f does not appear as an own property on C constructor" 69 ); 70 assert( 71 !Object.prototype.hasOwnProperty.call(C, 'g'), 72 "g does not appear as an own property on C constructor" 73 ); 74 assert( 75 !Object.prototype.hasOwnProperty.call(C, 'h'), 76 "h does not appear as an own property on C constructor" 77 ); 78 assert( 79 !Object.prototype.hasOwnProperty.call(C, 0), 80 "0 does not appear as an own property on C constructor" 81 ); 82 83 verifyProperty(c, 'f', { 84 value: 'test262', 85 enumerable: true, 86 writable: true, 87 configurable: true 88 }); 89 90 verifyProperty(c, 'g', { 91 value: undefined, 92 enumerable: true, 93 writable: true, 94 configurable: true 95 }); 96 97 verifyProperty(c, 0, { 98 value: 'bar', 99 enumerable: true, 100 writable: true, 101 configurable: true 102 }); 103 104 verifyProperty(c, 'h', { 105 value: undefined, 106 enumerable: true, 107 writable: true, 108 configurable: true 109 }); 110 111 reportCompare(0, 0);