static-field-anonymous-function-name.js (2489B)
1 // This file was procedurally generated from the following sources: 2 // - src/class-elements/static-field-anonymous-function-name.case 3 // - src/class-elements/default/cls-decl.template 4 /*--- 5 description: Anonymous function receives the name of static fields (field definitions in a class declaration) 6 esid: prod-FieldDefinition 7 features: [class-static-fields-private, class-static-fields-public, class] 8 flags: [generated] 9 info: | 10 Updated Productions 11 12 ClassElement : 13 ... 14 static FieldDefinition ; 15 16 FieldDefinition : 17 ClassElementName Initializer_opt 18 19 ClassDefinitionEvaluation: 20 ... 21 22 27. Let staticFields be a new empty List. 23 28. For each ClassElement e in order from elements, 24 a. If IsStatic of e is false, then 25 ... 26 b. Else, 27 i. Let field be the result of performing PropertyDefinitionEvaluation for m ClassElementEvaluation for e with arguments F and false. 28 c. If field is an abrupt completion, then 29 ... 30 d. If field is not empty, 31 i. If IsStatic of e is false, append field to instanceFields. 32 ii. Otherwise, append field to staticFields. 33 34 34. For each item fieldRecord in order from staticFields, 35 a. Perform ? DefineField(F, field). 36 ... 37 38 DefineField(receiver, fieldRecord) 39 1. Assert: Type(receiver) is Object. 40 2. Assert: fieldRecord is a Record as created by ClassFieldDefinitionEvaluation. 41 3. Let name be fieldRecord.[[Name]]. 42 4. Let initializer be fieldRecord.[[Initializer]]. 43 5. If initializer is not empty, then 44 a. Let initValue be ? Call(initializer, receiver). 45 6. Else, let initValue be undefined. 46 7. If fieldRecord.[[IsAnonymousFunctionDefinition]] is true, then 47 a. Let hasNameProperty be ? HasOwnProperty(initValue, "name"). 48 b. If hasNameProperty is false, perform SetFunctionName(initValue, fieldName). 49 8. If fieldName is a Private Name, 50 a. Perform ? PrivateFieldAdd(fieldName, receiver, initValue). 51 9. Else, 52 a. Assert: IsPropertyKey(fieldName) is true. 53 b. Perform ? CreateDataPropertyOrThrow(receiver, fieldName, initValue). 54 10. Return. 55 56 ---*/ 57 58 59 class C { 60 static #field = () => 'Test262'; 61 static field = function() { return 42; }; 62 63 static accessPrivateField() { 64 return this.#field; 65 } 66 67 } 68 69 assert.sameValue(C.accessPrivateField().name, "#field"); 70 assert.sameValue(C.field.name, "field"); 71 72 reportCompare(0, 0);