| 1 |
// This file was procedurally generated from the following sources: |
| 2 |
// - src/class-elements/private-static-method-shadowed-by-method-on-nested-class.case |
| 3 |
// - src/class-elements/default/cls-expr.template |
| 4 |
/*--- |
| 5 |
description: PrivateName of private static method can be shadowed on inner classes by a private method (field definitions in a class expression) |
| 6 |
esid: prod-FieldDefinition |
| 7 |
features: [class-static-methods-private, class-static-fields-public, class-methods-private, 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 |
var C = class { |
| 67 |
static #m() { return 'outer class'; } |
| 68 |
|
| 69 |
static methodAccess() { |
| 70 |
return this.#m(); |
| 71 |
} |
| 72 |
|
| 73 |
static B = class { |
| 74 |
#m() { return 'inner class'; } |
| 75 |
|
| 76 |
static access(o) { |
| 77 |
return o.#m(); |
| 78 |
} |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
assert.sameValue(C.methodAccess(), 'outer class'); |
| 83 |
|
| 84 |
let b = new C.B(); |
| 85 |
|
| 86 |
assert.sameValue(C.B.access(b), 'inner class'); |
| 87 |
|
| 88 |
assert.throws(TypeError, function() { |
| 89 |
C.B.access(C); |
| 90 |
}, 'accessed private method from an arbritary object'); |
| 91 |
|
| 92 |
reportCompare(0, 0); |