| 1 |
// This file was procedurally generated from the following sources: |
| 2 |
// - src/class-elements/private-static-field-usage-inside-nested-class.case |
| 3 |
// - src/class-elements/default/cls-decl.template |
| 4 |
/*--- |
| 5 |
description: PrivateName of private static field is available inside inner classes (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 |
CallExpression[Yield, Await]: |
| 13 |
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await] |
| 14 |
SuperCall[?Yield, ?Await] |
| 15 |
CallExpression[?Yield, ?Await]Arguments[?Yield, ?Await] |
| 16 |
CallExpression[?Yield, ?Await][Expression[+In, ?Yield, ?Await]] |
| 17 |
CallExpression[?Yield, ?Await].IdentifierName |
| 18 |
CallExpression[?Yield, ?Await]TemplateLiteral[?Yield, ?Await] |
| 19 |
CallExpression[?Yield, ?Await].PrivateIdentifier |
| 20 |
|
| 21 |
ClassTail : ClassHeritage { ClassBody } |
| 22 |
... |
| 23 |
6. Let classPrivateEnvironment be NewDeclarativeEnvironment(outerPrivateEnvironment). |
| 24 |
7. Let classPrivateEnvRec be classPrivateEnvironment's EnvironmentRecord. |
| 25 |
... |
| 26 |
15. Set the running execution context's LexicalEnvironment to classScope. |
| 27 |
16. Set the running execution context's PrivateEnvironment to classPrivateEnvironment. |
| 28 |
... |
| 29 |
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, |
| 30 |
a. PrivateBrandAdd(F, F). |
| 31 |
34. For each item fieldRecord in order from staticFields, |
| 32 |
a. Perform ? DefineField(F, field). |
| 33 |
|
| 34 |
FieldDefinition : ClassElementName Initializer_opt |
| 35 |
1. Let name be the result of evaluating ClassElementName. |
| 36 |
2. ReturnIfAbrupt(name). |
| 37 |
3. If Initializer_opt is present, |
| 38 |
a. Let lex be the Lexical Environment of the running execution context. |
| 39 |
b. Let formalParameterList be an instance of the production FormalParameters : [empty]. |
| 40 |
c. Let privateScope be the PrivateEnvironment of the running execution context. |
| 41 |
d. Let initializer be FunctionCreate(Method, formalParameterList, Initializer, lex, true, privateScope). |
| 42 |
e. Perform MakeMethod(initializer, homeObject). |
| 43 |
f. Let isAnonymousFunctionDefinition be IsAnonymousFunctionDefinition(Initializer). |
| 44 |
4. Else, |
| 45 |
a. Let initializer be empty. |
| 46 |
b. Let isAnonymousFunctionDeclaration be false. |
| 47 |
5. Return a Record { [[Name]]: name, [[Initializer]]: initializer, [[IsAnonymousFunctionDefinition]]: isAnonymousFunctionDefinition }. |
| 48 |
|
| 49 |
MemberExpression : MemberExpression.PrivateIdentifier |
| 50 |
1. Let baseReference be the result of evaluating MemberExpression. |
| 51 |
2. Let baseValue be ? GetValue(baseReference). |
| 52 |
3. Let bv be ? RequireObjectCoercible(baseValue). |
| 53 |
4. Let fieldNameString be the StringValue of PrivateIdentifier. |
| 54 |
5. Return MakePrivateReference(bv, fieldNameString). |
| 55 |
|
| 56 |
MakePrivateReference(baseValue, privateIdentifier) |
| 57 |
1. Let env be the running execution context's PrivateEnvironment. |
| 58 |
2. Let privateNameBinding be ? ResolveBinding(privateIdentifier, env). |
| 59 |
3. Let privateName be GetValue(privateNameBinding). |
| 60 |
4. Assert: privateName is a Private Name. |
| 61 |
5. Return a value of type Reference whose base value is baseValue, whose referenced name is privateName, whose strict reference flag is true. |
| 62 |
|
| 63 |
---*/ |
| 64 |
|
| 65 |
|
| 66 |
class C { |
| 67 |
static #m = 'outer class'; |
| 68 |
|
| 69 |
static B = class { |
| 70 |
static fieldAccess(o) { |
| 71 |
return o.#m; |
| 72 |
} |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
assert.sameValue(C.B.fieldAccess(C), 'outer class'); |
| 77 |
assert.throws(TypeError, function() { |
| 78 |
C.B.methodAccess(C.B); |
| 79 |
}, 'accessed static private field from an arbritary object'); |
| 80 |
|
| 81 |
reportCompare(0, 0); |