| 1 |
// This file was procedurally generated from the following sources: |
| 2 |
// - src/class-elements/static-field-declaration.case |
| 3 |
// - src/class-elements/default/cls-decl.template |
| 4 |
/*--- |
| 5 |
description: Static fields are defined using DefineField (field definitions in a class declaration) |
| 6 |
esid: prod-FieldDefinition |
| 7 |
features: [class-static-fields-public, class] |
| 8 |
flags: [generated] |
| 9 |
includes: [propertyHelper.js] |
| 10 |
info: | |
| 11 |
Updated Productions |
| 12 |
|
| 13 |
ClassElement : |
| 14 |
... |
| 15 |
static 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 |
27. Let staticFields 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 |
... |
| 39 |
b. Else, |
| 40 |
i. Let field be the result of performing PropertyDefinitionEvaluation for mClassElementEvaluation for e with arguments F and false. |
| 41 |
c. If field is an abrupt completion, then |
| 42 |
... |
| 43 |
d. If field is not empty, |
| 44 |
i. If IsStatic of e is false, append field to instanceFields. |
| 45 |
ii. Otherwise, append field to staticFields. |
| 46 |
|
| 47 |
34. For each item fieldRecord in order from staticFields, |
| 48 |
a. Perform ? DefineField(F, field). |
| 49 |
... |
| 50 |
|
| 51 |
DefineField(receiver, fieldRecord) |
| 52 |
1. Assert: Type(receiver) is Object. |
| 53 |
2. Assert: fieldRecord is a Record as created by ClassFieldDefinitionEvaluation. |
| 54 |
3. Let name be fieldRecord.[[Name]]. |
| 55 |
4. Let initializer be fieldRecord.[[Initializer]]. |
| 56 |
5. If initializer is not empty, then |
| 57 |
a. Let initValue be ? Call(initializer, receiver). |
| 58 |
6. Else, let initValue be undefined. |
| 59 |
7. If fieldRecord.[[IsAnonymousFunctionDefinition]] is true, then |
| 60 |
a. Let hasNameProperty be ? HasOwnProperty(initValue, "name"). |
| 61 |
b. If hasNameProperty is false, perform SetFunctionName(initValue, fieldName). |
| 62 |
8. If fieldName is a Private Name, |
| 63 |
a. Perform ? PrivateFieldAdd(fieldName, receiver, initValue). |
| 64 |
9. Else, |
| 65 |
a. Assert: IsPropertyKey(fieldName) is true. |
| 66 |
b. Perform ? CreateDataPropertyOrThrow(receiver, fieldName, initValue). |
| 67 |
10. Return. |
| 68 |
|
| 69 |
---*/ |
| 70 |
var computed = 'h'; |
| 71 |
|
| 72 |
|
| 73 |
class C { |
| 74 |
static f = 'test262'; |
| 75 |
static 'g'; |
| 76 |
static 0 = 'bar'; |
| 77 |
static [computed]; |
| 78 |
} |
| 79 |
|
| 80 |
let c = new C(); |
| 81 |
|
| 82 |
assert.sameValue(c.f, undefined); |
| 83 |
assert.sameValue(c.g, undefined); |
| 84 |
assert.sameValue(c.h, undefined); |
| 85 |
assert.sameValue(c[0], undefined); |
| 86 |
|
| 87 |
assert( |
| 88 |
!Object.prototype.hasOwnProperty.call(c, 'f'), |
| 89 |
"f does not appear as an own property on the C instance" |
| 90 |
); |
| 91 |
assert( |
| 92 |
!Object.prototype.hasOwnProperty.call(c, 'g'), |
| 93 |
"g does not appear as an own property on the C instance" |
| 94 |
); |
| 95 |
assert( |
| 96 |
!Object.prototype.hasOwnProperty.call(c, 'h'), |
| 97 |
"h does not appear as an own property on the C instance" |
| 98 |
); |
| 99 |
assert( |
| 100 |
!Object.prototype.hasOwnProperty.call(c, 0), |
| 101 |
"0 does not appear as an own property on the C instance" |
| 102 |
); |
| 103 |
|
| 104 |
verifyProperty(C, 'f', { |
| 105 |
value: 'test262', |
| 106 |
enumerable: true, |
| 107 |
writable: true, |
| 108 |
configurable: true |
| 109 |
}); |
| 110 |
|
| 111 |
verifyProperty(C, 'g', { |
| 112 |
value: undefined, |
| 113 |
enumerable: true, |
| 114 |
writable: true, |
| 115 |
configurable: true |
| 116 |
}); |
| 117 |
|
| 118 |
verifyProperty(C, 0, { |
| 119 |
value: 'bar', |
| 120 |
enumerable: true, |
| 121 |
writable: true, |
| 122 |
configurable: true |
| 123 |
}); |
| 124 |
|
| 125 |
verifyProperty(C, 'h', { |
| 126 |
value: undefined, |
| 127 |
enumerable: true, |
| 128 |
writable: true, |
| 129 |
configurable: true |
| 130 |
}); |
| 131 |
|
| 132 |
reportCompare(0, 0); |