0
# Private Field Helpers
1
2
Runtime implementation of private class fields and methods, providing encapsulation features for classes.
3
4
## Capabilities
5
6
### Private Instance Fields
7
8
#### _class_private_field_get
9
10
Gets the value of a private instance field.
11
12
```javascript { .api }
13
/**
14
* Gets the value of a private instance field
15
* @param {Object} receiver - The instance containing the private field
16
* @param {WeakMap} privateMap - WeakMap storing private field values
17
* @returns {any} The private field value
18
* @throws {TypeError} If private field not found
19
*/
20
function _class_private_field_get(receiver, privateMap): any;
21
```
22
23
**Usage Example:**
24
25
```javascript
26
// For a private field #value
27
const privateValue = _class_private_field_get(this, _value);
28
```
29
30
#### _class_private_field_set
31
32
Sets the value of a private instance field.
33
34
```javascript { .api }
35
/**
36
* Sets the value of a private instance field
37
* @param {Object} receiver - The instance containing the private field
38
* @param {WeakMap} privateMap - WeakMap storing private field values
39
* @param {any} value - Value to set
40
* @returns {any} The set value
41
*/
42
function _class_private_field_set(receiver, privateMap, value): any;
43
```
44
45
#### _class_private_field_init
46
47
Initializes a private instance field.
48
49
```javascript { .api }
50
/**
51
* Initializes a private instance field
52
* @param {Object} obj - The instance to initialize
53
* @param {WeakMap} privateMap - WeakMap to store the private field
54
* @param {any} value - Initial value
55
*/
56
function _class_private_field_init(obj, privateMap, value): void;
57
```
58
59
#### _class_private_field_update
60
61
Updates a private instance field with an operation.
62
63
```javascript { .api }
64
/**
65
* Updates a private instance field with an operation
66
* @param {Object} receiver - The instance containing the private field
67
* @param {WeakMap} privateMap - WeakMap storing private field values
68
* @param {Function} updateFn - Update function
69
* @returns {any} The updated value
70
*/
71
function _class_private_field_update(receiver, privateMap, updateFn): any;
72
```
73
74
#### _class_private_field_destructure
75
76
Handles destructuring of private fields.
77
78
```javascript { .api }
79
/**
80
* Handles destructuring of private fields
81
* @param {Object} receiver - The instance containing the private field
82
* @param {WeakMap} privateMap - WeakMap storing private field values
83
* @returns {any} The private field value for destructuring
84
*/
85
function _class_private_field_destructure(receiver, privateMap): any;
86
```
87
88
### Private Instance Methods
89
90
#### _class_private_method_get
91
92
Gets a private instance method.
93
94
```javascript { .api }
95
/**
96
* Gets a private instance method
97
* @param {Object} receiver - The instance containing the private method
98
* @param {WeakSet} privateSet - WeakSet tracking private method access
99
* @param {Function} fn - The private method function
100
* @returns {Function} The private method bound to receiver
101
*/
102
function _class_private_method_get(receiver, privateSet, fn): Function;
103
```
104
105
#### _class_private_method_init
106
107
Initializes a private instance method.
108
109
```javascript { .api }
110
/**
111
* Initializes a private instance method
112
* @param {Object} obj - The instance to initialize
113
* @param {WeakSet} privateSet - WeakSet to track private method access
114
*/
115
function _class_private_method_init(obj, privateSet): void;
116
```
117
118
#### _class_private_method_set
119
120
Throws error when attempting to set a private method (read-only).
121
122
```javascript { .api }
123
/**
124
* Throws error when attempting to set a private method
125
* @throws {TypeError} Private methods are read-only
126
*/
127
function _class_private_method_set(): never;
128
```
129
130
### Private Static Fields
131
132
#### _class_static_private_field_spec_get
133
134
Gets the value of a private static field.
135
136
```javascript { .api }
137
/**
138
* Gets the value of a private static field
139
* @param {Object} receiver - The class or instance
140
* @param {Function} classConstructor - The class constructor
141
* @param {Object} descriptor - Private field descriptor
142
* @returns {any} The private static field value
143
*/
144
function _class_static_private_field_spec_get(receiver, classConstructor, descriptor): any;
145
```
146
147
#### _class_static_private_field_spec_set
148
149
Sets the value of a private static field.
150
151
```javascript { .api }
152
/**
153
* Sets the value of a private static field
154
* @param {Object} receiver - The class or instance
155
* @param {Function} classConstructor - The class constructor
156
* @param {Object} descriptor - Private field descriptor
157
* @param {any} value - Value to set
158
* @returns {any} The set value
159
*/
160
function _class_static_private_field_spec_set(receiver, classConstructor, descriptor, value): any;
161
```
162
163
#### _class_static_private_field_update
164
165
Updates a private static field with an operation.
166
167
```javascript { .api }
168
/**
169
* Updates a private static field with an operation
170
* @param {Object} receiver - The class or instance
171
* @param {Function} classConstructor - The class constructor
172
* @param {Object} descriptor - Private field descriptor
173
* @param {Function} updateFn - Update function
174
* @returns {any} The updated value
175
*/
176
function _class_static_private_field_update(receiver, classConstructor, descriptor, updateFn): any;
177
```
178
179
#### _class_static_private_field_destructure
180
181
Handles destructuring of private static fields.
182
183
```javascript { .api }
184
/**
185
* Handles destructuring of private static fields
186
* @param {Object} receiver - The class or instance
187
* @param {Function} classConstructor - The class constructor
188
* @param {Object} descriptor - Private field descriptor
189
* @returns {any} The private static field value for destructuring
190
*/
191
function _class_static_private_field_destructure(receiver, classConstructor, descriptor): any;
192
```
193
194
### Private Static Methods
195
196
#### _class_static_private_method_get
197
198
Gets a private static method.
199
200
```javascript { .api }
201
/**
202
* Gets a private static method
203
* @param {Object} receiver - The class or instance
204
* @param {Function} classConstructor - The class constructor
205
* @param {Function} method - The private static method
206
* @returns {Function} The private static method
207
*/
208
function _class_static_private_method_get(receiver, classConstructor, method): Function;
209
```
210
211
### Private Field Utilities
212
213
#### _class_check_private_static_access
214
215
Checks access to private static members.
216
217
```javascript { .api }
218
/**
219
* Checks access to private static members
220
* @param {Object} receiver - The receiver object
221
* @param {Function} classConstructor - The class constructor
222
* @throws {TypeError} If access is invalid
223
*/
224
function _class_check_private_static_access(receiver, classConstructor): void;
225
```
226
227
#### _class_check_private_static_field_descriptor
228
229
Checks private static field descriptor validity.
230
231
```javascript { .api }
232
/**
233
* Checks private static field descriptor validity
234
* @param {Object} descriptor - Field descriptor to check
235
* @param {string} action - Action being performed
236
* @throws {TypeError} If descriptor is invalid for action
237
*/
238
function _class_check_private_static_field_descriptor(descriptor, action): void;
239
```
240
241
#### _check_private_redeclaration
242
243
Checks for private field redeclaration errors.
244
245
```javascript { .api }
246
/**
247
* Checks for private field redeclaration errors
248
* @param {Object} obj - Object being checked
249
* @param {WeakMap|WeakSet} privateCollection - Private field collection
250
* @throws {SyntaxError} If private field already declared
251
*/
252
function _check_private_redeclaration(obj, privateCollection): void;
253
```
254
255
### Loose Mode Private Fields
256
257
#### _class_private_field_loose_base
258
259
Gets the base object for loose mode private field access.
260
261
```javascript { .api }
262
/**
263
* Gets the base object for loose mode private field access
264
* @param {Object} receiver - The receiver object
265
* @param {Object} privateKey - Private field key
266
* @returns {Object} Base object for private field access
267
*/
268
function _class_private_field_loose_base(receiver, privateKey): Object;
269
```
270
271
#### _class_private_field_loose_key
272
273
Gets the key for loose mode private field access.
274
275
```javascript { .api }
276
/**
277
* Gets the key for loose mode private field access
278
* @param {string} name - Private field name
279
* @returns {string} Mangled private field key
280
*/
281
function _class_private_field_loose_key(name): string;
282
```