Debian Codegraph @

js/src/tests/test262/language/statements/class/elements/fields-anonymous-function-length.js

raw
1 // This file was procedurally generated from the following sources:
2 // - src/class-elements/fields-anonymous-function-length.case
3 // - src/class-elements/default/cls-decl.template
4 /*---
5 description: Anonymous functions in field initializer have length properly set (field definitions in a class declaration)
6 esid: prod-FieldDefinition
7 features: [class-fields-private, class-fields-public, class]
8 flags: [generated]
9 info: |
10 Updated Productions
11
12 FieldDefinition :
13 ClassElementName Initializer_opt
14
15 InitializeInstanceFields ( O, constructor )
16 1. Assert: Type ( O ) is Object.
17 2. Assert: constructor is an ECMAScript function object.
18 3. Let fields be the value of constructor.[[Fields]].
19 4. For each item fieldRecord in order from fields,
20 a. Perform ? DefineField(O, fieldRecord).
21 5. Return.
22
23 DefineField(receiver, fieldRecord)
24 1. Assert: Type(receiver) is Object.
25 2. Assert: fieldRecord is a Record as created by ClassFieldDefinitionEvaluation.
26 3. Let name be fieldRecord.[[Name]].
27 4. Let initializer be fieldRecord.[[Initializer]].
28 5. If initializer is not empty, then
29 a. Let initValue be ? Call(initializer, receiver).
30 ...
31
32 ---*/
33
34
35 class C {
36 field = function() {};
37 #field = (a, b, c, d) => undefined;
38
39 accessPrivateField() {
40 return this.#field;
41 }
42 }
43
44 let c = new C();
45 assert.sameValue(c.accessPrivateField().length, 4);
46 assert.sameValue(c.field.length, 0);
47
48 reportCompare(0, 0);