| 1 |
// This file was procedurally generated from the following sources: |
| 2 |
// - src/class-elements/static-private-setter.case |
| 3 |
// - src/class-elements/default/cls-decl.template |
| 4 |
/*--- |
| 5 |
description: static private setter declaration and usage (field definitions in a class declaration) |
| 6 |
esid: prod-FieldDefinition |
| 7 |
features: [class-static-methods-private, class] |
| 8 |
flags: [generated] |
| 9 |
info: | |
| 10 |
MethodDefinition : |
| 11 |
get ClassElementName () { FunctionBody } |
| 12 |
set ClassElementName ( PropertySetParameterList ) { FunctionBody } |
| 13 |
|
| 14 |
ClassTail : ClassHeritage { ClassBody } |
| 15 |
... |
| 16 |
33. If PrivateBoundIdentifiers of ClassBody contains a Private Name P such that P's [[Kind]] field is either "method" or "accessor" and P's [[Brand]] is F, |
| 17 |
a. PrivateBrandAdd(F, F). |
| 18 |
34. For each item fieldRecord in order from staticFields, |
| 19 |
a. Perform ? DefineField(F, field). |
| 20 |
|
| 21 |
PrivateFieldGet (P, O) |
| 22 |
1. Assert: P is a Private Name. |
| 23 |
2. If O is not an object, throw a TypeError exception. |
| 24 |
3. If P.[[Kind]] is "field", |
| 25 |
... |
| 26 |
4. Perform ? PrivateBrandCheck(O, P). |
| 27 |
5. If P.[[Kind]] is "method", |
| 28 |
... |
| 29 |
6. Else, |
| 30 |
a. Assert: P.[[Kind]] is "accessor". |
| 31 |
b. If P does not have a [[Get]] field, throw a TypeError exception. |
| 32 |
c. Let getter be P.[[Get]]. |
| 33 |
d. Return ? Call(getter, O). |
| 34 |
|
| 35 |
PrivateBrandCheck(O, P) |
| 36 |
1. If O.[[PrivateBrands]] does not contain an entry e such that SameValue(e, P.[[Brand]]) is true, |
| 37 |
a. Throw a TypeError exception. |
| 38 |
|
| 39 |
---*/ |
| 40 |
|
| 41 |
|
| 42 |
class C { |
| 43 |
static set #f(v) { |
| 44 |
this._v = v; |
| 45 |
} |
| 46 |
|
| 47 |
static access() { |
| 48 |
this.#f = 'Test262'; |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
C.access(); |
| 53 |
assert.sameValue(C._v, 'Test262'); |
| 54 |
assert.throws(TypeError, function() { |
| 55 |
C.access.call({}); |
| 56 |
}, 'Accessed static private setter from an arbitrary object'); |
| 57 |
|
| 58 |
reportCompare(0, 0); |