mirror of https://github.com/tc39/test262.git
Merge pull request #2296 from caiolima/private-static-members-inner-class
Private static members inner class
This commit is contained in:
commit
230ab42698
|
@ -0,0 +1,85 @@
|
|||
// Copyright (C) 2019 Caio Lima (Igalia SL). All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
desc: PrivateName of private static field can be shadowed on inner classes by a private field
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
CallExpression[Yield, Await]:
|
||||
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await]
|
||||
SuperCall[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await]Arguments[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await][Expression[+In, ?Yield, ?Await]]
|
||||
CallExpression[?Yield, ?Await].IdentifierName
|
||||
CallExpression[?Yield, ?Await]TemplateLiteral[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await].PrivateIdentifier
|
||||
|
||||
ClassTail : ClassHeritage { ClassBody }
|
||||
...
|
||||
6. Let classPrivateEnvironment be NewDeclarativeEnvironment(outerPrivateEnvironment).
|
||||
7. Let classPrivateEnvRec be classPrivateEnvironment's EnvironmentRecord.
|
||||
...
|
||||
15. Set the running execution context's LexicalEnvironment to classScope.
|
||||
16. Set the running execution context's PrivateEnvironment to classPrivateEnvironment.
|
||||
...
|
||||
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,
|
||||
a. PrivateBrandAdd(F, F).
|
||||
34. For each item fieldRecord in order from staticFields,
|
||||
a. Perform ? DefineField(F, field).
|
||||
|
||||
FieldDefinition : ClassElementName Initializer_opt
|
||||
1. Let name be the result of evaluating ClassElementName.
|
||||
2. ReturnIfAbrupt(name).
|
||||
3. If Initializer_opt is present,
|
||||
a. Let lex be the Lexical Environment of the running execution context.
|
||||
b. Let formalParameterList be an instance of the production FormalParameters : [empty].
|
||||
c. Let privateScope be the PrivateEnvironment of the running execution context.
|
||||
d. Let initializer be FunctionCreate(Method, formalParameterList, Initializer, lex, true, privateScope).
|
||||
e. Perform MakeMethod(initializer, homeObject).
|
||||
f. Let isAnonymousFunctionDefinition be IsAnonymousFunctionDefinition(Initializer).
|
||||
4. Else,
|
||||
a. Let initializer be empty.
|
||||
b. Let isAnonymousFunctionDeclaration be false.
|
||||
5. Return a Record { [[Name]]: name, [[Initializer]]: initializer, [[IsAnonymousFunctionDefinition]]: isAnonymousFunctionDefinition }.
|
||||
|
||||
MemberExpression : MemberExpression.PrivateIdentifier
|
||||
1. Let baseReference be the result of evaluating MemberExpression.
|
||||
2. Let baseValue be ? GetValue(baseReference).
|
||||
3. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
4. Let fieldNameString be the StringValue of PrivateIdentifier.
|
||||
5. Return MakePrivateReference(bv, fieldNameString).
|
||||
|
||||
MakePrivateReference(baseValue, privateIdentifier)
|
||||
1. Let env be the running execution context's PrivateEnvironment.
|
||||
2. Let privateNameBinding be ? ResolveBinding(privateIdentifier, env).
|
||||
3. Let privateName be GetValue(privateNameBinding).
|
||||
4. Assert: privateName is a Private Name.
|
||||
5. Return a value of type Reference whose base value is baseValue, whose referenced name is privateName, whose strict reference flag is true.
|
||||
template: default
|
||||
features: [class-static-fields-private, class-static-fields-public, class-fields-private]
|
||||
---*/
|
||||
|
||||
//- elements
|
||||
static #m = 'outer class';
|
||||
|
||||
static fieldAccess() {
|
||||
return this.#m;
|
||||
}
|
||||
|
||||
static B = class {
|
||||
#m = 'inner class';
|
||||
static fieldAccess(o) {
|
||||
return o.#m;
|
||||
}
|
||||
}
|
||||
//- assertions
|
||||
assert.sameValue(C.fieldAccess(), 'outer class');
|
||||
|
||||
let b = new C.B();
|
||||
|
||||
assert.sameValue(C.B.fieldAccess(b), 'inner class');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
C.B.fieldAccess(C);
|
||||
}, 'accessed private field from an arbritary object');
|
|
@ -0,0 +1,86 @@
|
|||
// Copyright (C) 2019 Caio Lima (Igalia SL). All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
desc: PrivateName of private static field can be shadowed on inner classes by a private getter
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
CallExpression[Yield, Await]:
|
||||
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await]
|
||||
SuperCall[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await]Arguments[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await][Expression[+In, ?Yield, ?Await]]
|
||||
CallExpression[?Yield, ?Await].IdentifierName
|
||||
CallExpression[?Yield, ?Await]TemplateLiteral[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await].PrivateIdentifier
|
||||
|
||||
ClassTail : ClassHeritage { ClassBody }
|
||||
...
|
||||
6. Let classPrivateEnvironment be NewDeclarativeEnvironment(outerPrivateEnvironment).
|
||||
7. Let classPrivateEnvRec be classPrivateEnvironment's EnvironmentRecord.
|
||||
...
|
||||
15. Set the running execution context's LexicalEnvironment to classScope.
|
||||
16. Set the running execution context's PrivateEnvironment to classPrivateEnvironment.
|
||||
...
|
||||
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,
|
||||
a. PrivateBrandAdd(F, F).
|
||||
34. For each item fieldRecord in order from staticFields,
|
||||
a. Perform ? DefineField(F, field).
|
||||
|
||||
FieldDefinition : ClassElementName Initializer_opt
|
||||
1. Let name be the result of evaluating ClassElementName.
|
||||
2. ReturnIfAbrupt(name).
|
||||
3. If Initializer_opt is present,
|
||||
a. Let lex be the Lexical Environment of the running execution context.
|
||||
b. Let formalParameterList be an instance of the production FormalParameters : [empty].
|
||||
c. Let privateScope be the PrivateEnvironment of the running execution context.
|
||||
d. Let initializer be FunctionCreate(Method, formalParameterList, Initializer, lex, true, privateScope).
|
||||
e. Perform MakeMethod(initializer, homeObject).
|
||||
f. Let isAnonymousFunctionDefinition be IsAnonymousFunctionDefinition(Initializer).
|
||||
4. Else,
|
||||
a. Let initializer be empty.
|
||||
b. Let isAnonymousFunctionDeclaration be false.
|
||||
5. Return a Record { [[Name]]: name, [[Initializer]]: initializer, [[IsAnonymousFunctionDefinition]]: isAnonymousFunctionDefinition }.
|
||||
|
||||
MemberExpression : MemberExpression.PrivateIdentifier
|
||||
1. Let baseReference be the result of evaluating MemberExpression.
|
||||
2. Let baseValue be ? GetValue(baseReference).
|
||||
3. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
4. Let fieldNameString be the StringValue of PrivateIdentifier.
|
||||
5. Return MakePrivateReference(bv, fieldNameString).
|
||||
|
||||
MakePrivateReference(baseValue, privateIdentifier)
|
||||
1. Let env be the running execution context's PrivateEnvironment.
|
||||
2. Let privateNameBinding be ? ResolveBinding(privateIdentifier, env).
|
||||
3. Let privateName be GetValue(privateNameBinding).
|
||||
4. Assert: privateName is a Private Name.
|
||||
5. Return a value of type Reference whose base value is baseValue, whose referenced name is privateName, whose strict reference flag is true.
|
||||
template: default
|
||||
features: [class-static-fields-private, class-static-fields-public, class-methods-private]
|
||||
---*/
|
||||
|
||||
//- elements
|
||||
static #m = 'outer class';
|
||||
|
||||
static fieldAccess() {
|
||||
return this.#m;
|
||||
}
|
||||
|
||||
static B = class {
|
||||
get #m() { return 'inner class'; }
|
||||
|
||||
static access(o) {
|
||||
return o.#m;
|
||||
}
|
||||
}
|
||||
//- assertions
|
||||
assert.sameValue(C.fieldAccess(), 'outer class');
|
||||
|
||||
let b = new C.B();
|
||||
|
||||
assert.sameValue(C.B.access(b), 'inner class');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
C.B.access(C);
|
||||
}, 'accessed private getter from an arbritary object');
|
|
@ -0,0 +1,86 @@
|
|||
// Copyright (C) 2019 Caio Lima (Igalia SL). All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
desc: PrivateName of private static field can be shadowed on inner classes by a private method
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
CallExpression[Yield, Await]:
|
||||
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await]
|
||||
SuperCall[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await]Arguments[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await][Expression[+In, ?Yield, ?Await]]
|
||||
CallExpression[?Yield, ?Await].IdentifierName
|
||||
CallExpression[?Yield, ?Await]TemplateLiteral[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await].PrivateIdentifier
|
||||
|
||||
ClassTail : ClassHeritage { ClassBody }
|
||||
...
|
||||
6. Let classPrivateEnvironment be NewDeclarativeEnvironment(outerPrivateEnvironment).
|
||||
7. Let classPrivateEnvRec be classPrivateEnvironment's EnvironmentRecord.
|
||||
...
|
||||
15. Set the running execution context's LexicalEnvironment to classScope.
|
||||
16. Set the running execution context's PrivateEnvironment to classPrivateEnvironment.
|
||||
...
|
||||
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,
|
||||
a. PrivateBrandAdd(F, F).
|
||||
34. For each item fieldRecord in order from staticFields,
|
||||
a. Perform ? DefineField(F, field).
|
||||
|
||||
FieldDefinition : ClassElementName Initializer_opt
|
||||
1. Let name be the result of evaluating ClassElementName.
|
||||
2. ReturnIfAbrupt(name).
|
||||
3. If Initializer_opt is present,
|
||||
a. Let lex be the Lexical Environment of the running execution context.
|
||||
b. Let formalParameterList be an instance of the production FormalParameters : [empty].
|
||||
c. Let privateScope be the PrivateEnvironment of the running execution context.
|
||||
d. Let initializer be FunctionCreate(Method, formalParameterList, Initializer, lex, true, privateScope).
|
||||
e. Perform MakeMethod(initializer, homeObject).
|
||||
f. Let isAnonymousFunctionDefinition be IsAnonymousFunctionDefinition(Initializer).
|
||||
4. Else,
|
||||
a. Let initializer be empty.
|
||||
b. Let isAnonymousFunctionDeclaration be false.
|
||||
5. Return a Record { [[Name]]: name, [[Initializer]]: initializer, [[IsAnonymousFunctionDefinition]]: isAnonymousFunctionDefinition }.
|
||||
|
||||
MemberExpression : MemberExpression.PrivateIdentifier
|
||||
1. Let baseReference be the result of evaluating MemberExpression.
|
||||
2. Let baseValue be ? GetValue(baseReference).
|
||||
3. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
4. Let fieldNameString be the StringValue of PrivateIdentifier.
|
||||
5. Return MakePrivateReference(bv, fieldNameString).
|
||||
|
||||
MakePrivateReference(baseValue, privateIdentifier)
|
||||
1. Let env be the running execution context's PrivateEnvironment.
|
||||
2. Let privateNameBinding be ? ResolveBinding(privateIdentifier, env).
|
||||
3. Let privateName be GetValue(privateNameBinding).
|
||||
4. Assert: privateName is a Private Name.
|
||||
5. Return a value of type Reference whose base value is baseValue, whose referenced name is privateName, whose strict reference flag is true.
|
||||
template: default
|
||||
features: [class-static-fields-private, class-static-fields-public, class-methods-private]
|
||||
---*/
|
||||
|
||||
//- elements
|
||||
static #m = () => 'outer class';
|
||||
|
||||
static fieldAccess() {
|
||||
return this.#m();
|
||||
}
|
||||
|
||||
static B = class {
|
||||
#m() { return 'inner class'; }
|
||||
|
||||
static access(o) {
|
||||
return o.#m();
|
||||
}
|
||||
}
|
||||
//- assertions
|
||||
assert.sameValue(C.fieldAccess(), 'outer class');
|
||||
|
||||
let b = new C.B();
|
||||
|
||||
assert.sameValue(C.B.access(b), 'inner class');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
C.B.access(C);
|
||||
}, 'accessed private method from an arbritary object');
|
|
@ -0,0 +1,87 @@
|
|||
// Copyright (C) 2019 Caio Lima (Igalia SL). All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
desc: PrivateName of private static field can be shadowed on inner classes by a private setter
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
CallExpression[Yield, Await]:
|
||||
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await]
|
||||
SuperCall[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await]Arguments[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await][Expression[+In, ?Yield, ?Await]]
|
||||
CallExpression[?Yield, ?Await].IdentifierName
|
||||
CallExpression[?Yield, ?Await]TemplateLiteral[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await].PrivateIdentifier
|
||||
|
||||
ClassTail : ClassHeritage { ClassBody }
|
||||
...
|
||||
6. Let classPrivateEnvironment be NewDeclarativeEnvironment(outerPrivateEnvironment).
|
||||
7. Let classPrivateEnvRec be classPrivateEnvironment's EnvironmentRecord.
|
||||
...
|
||||
15. Set the running execution context's LexicalEnvironment to classScope.
|
||||
16. Set the running execution context's PrivateEnvironment to classPrivateEnvironment.
|
||||
...
|
||||
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,
|
||||
a. PrivateBrandAdd(F, F).
|
||||
34. For each item fieldRecord in order from staticFields,
|
||||
a. Perform ? DefineField(F, field).
|
||||
|
||||
FieldDefinition : ClassElementName Initializer_opt
|
||||
1. Let name be the result of evaluating ClassElementName.
|
||||
2. ReturnIfAbrupt(name).
|
||||
3. If Initializer_opt is present,
|
||||
a. Let lex be the Lexical Environment of the running execution context.
|
||||
b. Let formalParameterList be an instance of the production FormalParameters : [empty].
|
||||
c. Let privateScope be the PrivateEnvironment of the running execution context.
|
||||
d. Let initializer be FunctionCreate(Method, formalParameterList, Initializer, lex, true, privateScope).
|
||||
e. Perform MakeMethod(initializer, homeObject).
|
||||
f. Let isAnonymousFunctionDefinition be IsAnonymousFunctionDefinition(Initializer).
|
||||
4. Else,
|
||||
a. Let initializer be empty.
|
||||
b. Let isAnonymousFunctionDeclaration be false.
|
||||
5. Return a Record { [[Name]]: name, [[Initializer]]: initializer, [[IsAnonymousFunctionDefinition]]: isAnonymousFunctionDefinition }.
|
||||
|
||||
MemberExpression : MemberExpression.PrivateIdentifier
|
||||
1. Let baseReference be the result of evaluating MemberExpression.
|
||||
2. Let baseValue be ? GetValue(baseReference).
|
||||
3. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
4. Let fieldNameString be the StringValue of PrivateIdentifier.
|
||||
5. Return MakePrivateReference(bv, fieldNameString).
|
||||
|
||||
MakePrivateReference(baseValue, privateIdentifier)
|
||||
1. Let env be the running execution context's PrivateEnvironment.
|
||||
2. Let privateNameBinding be ? ResolveBinding(privateIdentifier, env).
|
||||
3. Let privateName be GetValue(privateNameBinding).
|
||||
4. Assert: privateName is a Private Name.
|
||||
5. Return a value of type Reference whose base value is baseValue, whose referenced name is privateName, whose strict reference flag is true.
|
||||
template: default
|
||||
features: [class-static-fields-private, class-static-fields-public, class-methods-private]
|
||||
---*/
|
||||
|
||||
//- elements
|
||||
static #m = 'outer class';
|
||||
|
||||
static fieldAccess() {
|
||||
return this.#m;
|
||||
}
|
||||
|
||||
static B = class {
|
||||
set #m(v) { this._v = v; }
|
||||
|
||||
static access(o) {
|
||||
o.#m = 'inner class';
|
||||
}
|
||||
}
|
||||
//- assertions
|
||||
assert.sameValue(C.fieldAccess(), 'outer class');
|
||||
|
||||
let b = new C.B();
|
||||
|
||||
C.B.access(b);
|
||||
assert.sameValue(b._v, 'inner class');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
C.B.access(C);
|
||||
}, 'accessed private setter from an arbritary object');
|
|
@ -0,0 +1,75 @@
|
|||
// Copyright (C) 2019 Caio Lima (Igalia SL). All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
desc: PrivateName of private static field is available inside inner classes
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
CallExpression[Yield, Await]:
|
||||
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await]
|
||||
SuperCall[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await]Arguments[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await][Expression[+In, ?Yield, ?Await]]
|
||||
CallExpression[?Yield, ?Await].IdentifierName
|
||||
CallExpression[?Yield, ?Await]TemplateLiteral[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await].PrivateIdentifier
|
||||
|
||||
ClassTail : ClassHeritage { ClassBody }
|
||||
...
|
||||
6. Let classPrivateEnvironment be NewDeclarativeEnvironment(outerPrivateEnvironment).
|
||||
7. Let classPrivateEnvRec be classPrivateEnvironment's EnvironmentRecord.
|
||||
...
|
||||
15. Set the running execution context's LexicalEnvironment to classScope.
|
||||
16. Set the running execution context's PrivateEnvironment to classPrivateEnvironment.
|
||||
...
|
||||
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,
|
||||
a. PrivateBrandAdd(F, F).
|
||||
34. For each item fieldRecord in order from staticFields,
|
||||
a. Perform ? DefineField(F, field).
|
||||
|
||||
FieldDefinition : ClassElementName Initializer_opt
|
||||
1. Let name be the result of evaluating ClassElementName.
|
||||
2. ReturnIfAbrupt(name).
|
||||
3. If Initializer_opt is present,
|
||||
a. Let lex be the Lexical Environment of the running execution context.
|
||||
b. Let formalParameterList be an instance of the production FormalParameters : [empty].
|
||||
c. Let privateScope be the PrivateEnvironment of the running execution context.
|
||||
d. Let initializer be FunctionCreate(Method, formalParameterList, Initializer, lex, true, privateScope).
|
||||
e. Perform MakeMethod(initializer, homeObject).
|
||||
f. Let isAnonymousFunctionDefinition be IsAnonymousFunctionDefinition(Initializer).
|
||||
4. Else,
|
||||
a. Let initializer be empty.
|
||||
b. Let isAnonymousFunctionDeclaration be false.
|
||||
5. Return a Record { [[Name]]: name, [[Initializer]]: initializer, [[IsAnonymousFunctionDefinition]]: isAnonymousFunctionDefinition }.
|
||||
|
||||
MemberExpression : MemberExpression.PrivateIdentifier
|
||||
1. Let baseReference be the result of evaluating MemberExpression.
|
||||
2. Let baseValue be ? GetValue(baseReference).
|
||||
3. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
4. Let fieldNameString be the StringValue of PrivateIdentifier.
|
||||
5. Return MakePrivateReference(bv, fieldNameString).
|
||||
|
||||
MakePrivateReference(baseValue, privateIdentifier)
|
||||
1. Let env be the running execution context's PrivateEnvironment.
|
||||
2. Let privateNameBinding be ? ResolveBinding(privateIdentifier, env).
|
||||
3. Let privateName be GetValue(privateNameBinding).
|
||||
4. Assert: privateName is a Private Name.
|
||||
5. Return a value of type Reference whose base value is baseValue, whose referenced name is privateName, whose strict reference flag is true.
|
||||
template: default
|
||||
features: [class-static-fields-private, class-static-fields-public]
|
||||
---*/
|
||||
|
||||
//- elements
|
||||
static #m = 'outer class';
|
||||
|
||||
static B = class {
|
||||
static fieldAccess(o) {
|
||||
return o.#m;
|
||||
}
|
||||
}
|
||||
//- assertions
|
||||
assert.sameValue(C.B.fieldAccess(C), 'outer class');
|
||||
assert.throws(TypeError, function() {
|
||||
C.B.methodAccess(C.B);
|
||||
}, 'accessed static private field from an arbritary object');
|
|
@ -0,0 +1,85 @@
|
|||
// Copyright (C) 2019 Caio Lima (Igalia SL). All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
desc: PrivateName of private static method can be shadowed on inner classes by a private field
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
CallExpression[Yield, Await]:
|
||||
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await]
|
||||
SuperCall[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await]Arguments[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await][Expression[+In, ?Yield, ?Await]]
|
||||
CallExpression[?Yield, ?Await].IdentifierName
|
||||
CallExpression[?Yield, ?Await]TemplateLiteral[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await].PrivateIdentifier
|
||||
|
||||
ClassTail : ClassHeritage { ClassBody }
|
||||
...
|
||||
6. Let classPrivateEnvironment be NewDeclarativeEnvironment(outerPrivateEnvironment).
|
||||
7. Let classPrivateEnvRec be classPrivateEnvironment's EnvironmentRecord.
|
||||
...
|
||||
15. Set the running execution context's LexicalEnvironment to classScope.
|
||||
16. Set the running execution context's PrivateEnvironment to classPrivateEnvironment.
|
||||
...
|
||||
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,
|
||||
a. PrivateBrandAdd(F, F).
|
||||
34. For each item fieldRecord in order from staticFields,
|
||||
a. Perform ? DefineField(F, field).
|
||||
|
||||
FieldDefinition : ClassElementName Initializer_opt
|
||||
1. Let name be the result of evaluating ClassElementName.
|
||||
2. ReturnIfAbrupt(name).
|
||||
3. If Initializer_opt is present,
|
||||
a. Let lex be the Lexical Environment of the running execution context.
|
||||
b. Let formalParameterList be an instance of the production FormalParameters : [empty].
|
||||
c. Let privateScope be the PrivateEnvironment of the running execution context.
|
||||
d. Let initializer be FunctionCreate(Method, formalParameterList, Initializer, lex, true, privateScope).
|
||||
e. Perform MakeMethod(initializer, homeObject).
|
||||
f. Let isAnonymousFunctionDefinition be IsAnonymousFunctionDefinition(Initializer).
|
||||
4. Else,
|
||||
a. Let initializer be empty.
|
||||
b. Let isAnonymousFunctionDeclaration be false.
|
||||
5. Return a Record { [[Name]]: name, [[Initializer]]: initializer, [[IsAnonymousFunctionDefinition]]: isAnonymousFunctionDefinition }.
|
||||
|
||||
MemberExpression : MemberExpression.PrivateIdentifier
|
||||
1. Let baseReference be the result of evaluating MemberExpression.
|
||||
2. Let baseValue be ? GetValue(baseReference).
|
||||
3. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
4. Let fieldNameString be the StringValue of PrivateIdentifier.
|
||||
5. Return MakePrivateReference(bv, fieldNameString).
|
||||
|
||||
MakePrivateReference(baseValue, privateIdentifier)
|
||||
1. Let env be the running execution context's PrivateEnvironment.
|
||||
2. Let privateNameBinding be ? ResolveBinding(privateIdentifier, env).
|
||||
3. Let privateName be GetValue(privateNameBinding).
|
||||
4. Assert: privateName is a Private Name.
|
||||
5. Return a value of type Reference whose base value is baseValue, whose referenced name is privateName, whose strict reference flag is true.
|
||||
template: default
|
||||
features: [class-static-methods-private, class-static-fields-public, class-fields-private]
|
||||
---*/
|
||||
|
||||
//- elements
|
||||
static #m() { return 'outer class'; }
|
||||
|
||||
static methodAccess() {
|
||||
return this.#m();
|
||||
}
|
||||
|
||||
static B = class {
|
||||
#m = 'inner class';
|
||||
static fieldAccess(o) {
|
||||
return o.#m;
|
||||
}
|
||||
}
|
||||
//- assertions
|
||||
assert.sameValue(C.methodAccess(), 'outer class');
|
||||
|
||||
let b = new C.B();
|
||||
|
||||
assert.sameValue(C.B.fieldAccess(b), 'inner class');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
C.B.fieldAccess(C);
|
||||
}, 'accessed private field from an arbritary object');
|
|
@ -0,0 +1,86 @@
|
|||
// Copyright (C) 2019 Caio Lima (Igalia SL). All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
desc: PrivateName of private static method can be shadowed on inner classes by a private getter
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
CallExpression[Yield, Await]:
|
||||
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await]
|
||||
SuperCall[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await]Arguments[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await][Expression[+In, ?Yield, ?Await]]
|
||||
CallExpression[?Yield, ?Await].IdentifierName
|
||||
CallExpression[?Yield, ?Await]TemplateLiteral[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await].PrivateIdentifier
|
||||
|
||||
ClassTail : ClassHeritage { ClassBody }
|
||||
...
|
||||
6. Let classPrivateEnvironment be NewDeclarativeEnvironment(outerPrivateEnvironment).
|
||||
7. Let classPrivateEnvRec be classPrivateEnvironment's EnvironmentRecord.
|
||||
...
|
||||
15. Set the running execution context's LexicalEnvironment to classScope.
|
||||
16. Set the running execution context's PrivateEnvironment to classPrivateEnvironment.
|
||||
...
|
||||
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,
|
||||
a. PrivateBrandAdd(F, F).
|
||||
34. For each item fieldRecord in order from staticFields,
|
||||
a. Perform ? DefineField(F, field).
|
||||
|
||||
FieldDefinition : ClassElementName Initializer_opt
|
||||
1. Let name be the result of evaluating ClassElementName.
|
||||
2. ReturnIfAbrupt(name).
|
||||
3. If Initializer_opt is present,
|
||||
a. Let lex be the Lexical Environment of the running execution context.
|
||||
b. Let formalParameterList be an instance of the production FormalParameters : [empty].
|
||||
c. Let privateScope be the PrivateEnvironment of the running execution context.
|
||||
d. Let initializer be FunctionCreate(Method, formalParameterList, Initializer, lex, true, privateScope).
|
||||
e. Perform MakeMethod(initializer, homeObject).
|
||||
f. Let isAnonymousFunctionDefinition be IsAnonymousFunctionDefinition(Initializer).
|
||||
4. Else,
|
||||
a. Let initializer be empty.
|
||||
b. Let isAnonymousFunctionDeclaration be false.
|
||||
5. Return a Record { [[Name]]: name, [[Initializer]]: initializer, [[IsAnonymousFunctionDefinition]]: isAnonymousFunctionDefinition }.
|
||||
|
||||
MemberExpression : MemberExpression.PrivateIdentifier
|
||||
1. Let baseReference be the result of evaluating MemberExpression.
|
||||
2. Let baseValue be ? GetValue(baseReference).
|
||||
3. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
4. Let fieldNameString be the StringValue of PrivateIdentifier.
|
||||
5. Return MakePrivateReference(bv, fieldNameString).
|
||||
|
||||
MakePrivateReference(baseValue, privateIdentifier)
|
||||
1. Let env be the running execution context's PrivateEnvironment.
|
||||
2. Let privateNameBinding be ? ResolveBinding(privateIdentifier, env).
|
||||
3. Let privateName be GetValue(privateNameBinding).
|
||||
4. Assert: privateName is a Private Name.
|
||||
5. Return a value of type Reference whose base value is baseValue, whose referenced name is privateName, whose strict reference flag is true.
|
||||
template: default
|
||||
features: [class-static-methods-private, class-static-fields-public, class-methods-private]
|
||||
---*/
|
||||
|
||||
//- elements
|
||||
static #m() { return 'outer class'; }
|
||||
|
||||
static methodAccess() {
|
||||
return this.#m();
|
||||
}
|
||||
|
||||
static B = class {
|
||||
get #m() { return 'inner class'; }
|
||||
|
||||
static access(o) {
|
||||
return o.#m;
|
||||
}
|
||||
}
|
||||
//- assertions
|
||||
assert.sameValue(C.methodAccess(), 'outer class');
|
||||
|
||||
let b = new C.B();
|
||||
|
||||
assert.sameValue(C.B.access(b), 'inner class');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
C.B.access(C);
|
||||
}, 'accessed private getter from an arbritary object');
|
|
@ -0,0 +1,86 @@
|
|||
// Copyright (C) 2019 Caio Lima (Igalia SL). All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
desc: PrivateName of private static method can be shadowed on inner classes by a private method
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
CallExpression[Yield, Await]:
|
||||
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await]
|
||||
SuperCall[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await]Arguments[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await][Expression[+In, ?Yield, ?Await]]
|
||||
CallExpression[?Yield, ?Await].IdentifierName
|
||||
CallExpression[?Yield, ?Await]TemplateLiteral[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await].PrivateIdentifier
|
||||
|
||||
ClassTail : ClassHeritage { ClassBody }
|
||||
...
|
||||
6. Let classPrivateEnvironment be NewDeclarativeEnvironment(outerPrivateEnvironment).
|
||||
7. Let classPrivateEnvRec be classPrivateEnvironment's EnvironmentRecord.
|
||||
...
|
||||
15. Set the running execution context's LexicalEnvironment to classScope.
|
||||
16. Set the running execution context's PrivateEnvironment to classPrivateEnvironment.
|
||||
...
|
||||
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,
|
||||
a. PrivateBrandAdd(F, F).
|
||||
34. For each item fieldRecord in order from staticFields,
|
||||
a. Perform ? DefineField(F, field).
|
||||
|
||||
FieldDefinition : ClassElementName Initializer_opt
|
||||
1. Let name be the result of evaluating ClassElementName.
|
||||
2. ReturnIfAbrupt(name).
|
||||
3. If Initializer_opt is present,
|
||||
a. Let lex be the Lexical Environment of the running execution context.
|
||||
b. Let formalParameterList be an instance of the production FormalParameters : [empty].
|
||||
c. Let privateScope be the PrivateEnvironment of the running execution context.
|
||||
d. Let initializer be FunctionCreate(Method, formalParameterList, Initializer, lex, true, privateScope).
|
||||
e. Perform MakeMethod(initializer, homeObject).
|
||||
f. Let isAnonymousFunctionDefinition be IsAnonymousFunctionDefinition(Initializer).
|
||||
4. Else,
|
||||
a. Let initializer be empty.
|
||||
b. Let isAnonymousFunctionDeclaration be false.
|
||||
5. Return a Record { [[Name]]: name, [[Initializer]]: initializer, [[IsAnonymousFunctionDefinition]]: isAnonymousFunctionDefinition }.
|
||||
|
||||
MemberExpression : MemberExpression.PrivateIdentifier
|
||||
1. Let baseReference be the result of evaluating MemberExpression.
|
||||
2. Let baseValue be ? GetValue(baseReference).
|
||||
3. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
4. Let fieldNameString be the StringValue of PrivateIdentifier.
|
||||
5. Return MakePrivateReference(bv, fieldNameString).
|
||||
|
||||
MakePrivateReference(baseValue, privateIdentifier)
|
||||
1. Let env be the running execution context's PrivateEnvironment.
|
||||
2. Let privateNameBinding be ? ResolveBinding(privateIdentifier, env).
|
||||
3. Let privateName be GetValue(privateNameBinding).
|
||||
4. Assert: privateName is a Private Name.
|
||||
5. Return a value of type Reference whose base value is baseValue, whose referenced name is privateName, whose strict reference flag is true.
|
||||
template: default
|
||||
features: [class-static-methods-private, class-static-fields-public, class-methods-private]
|
||||
---*/
|
||||
|
||||
//- elements
|
||||
static #m() { return 'outer class'; }
|
||||
|
||||
static methodAccess() {
|
||||
return this.#m();
|
||||
}
|
||||
|
||||
static B = class {
|
||||
#m() { return 'inner class'; }
|
||||
|
||||
static access(o) {
|
||||
return o.#m();
|
||||
}
|
||||
}
|
||||
//- assertions
|
||||
assert.sameValue(C.methodAccess(), 'outer class');
|
||||
|
||||
let b = new C.B();
|
||||
|
||||
assert.sameValue(C.B.access(b), 'inner class');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
C.B.access(C);
|
||||
}, 'accessed private method from an arbritary object');
|
|
@ -0,0 +1,87 @@
|
|||
// Copyright (C) 2019 Caio Lima (Igalia SL). All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
desc: PrivateName of private static method can be shadowed on inner classes by a private setter
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
CallExpression[Yield, Await]:
|
||||
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await]
|
||||
SuperCall[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await]Arguments[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await][Expression[+In, ?Yield, ?Await]]
|
||||
CallExpression[?Yield, ?Await].IdentifierName
|
||||
CallExpression[?Yield, ?Await]TemplateLiteral[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await].PrivateIdentifier
|
||||
|
||||
ClassTail : ClassHeritage { ClassBody }
|
||||
...
|
||||
6. Let classPrivateEnvironment be NewDeclarativeEnvironment(outerPrivateEnvironment).
|
||||
7. Let classPrivateEnvRec be classPrivateEnvironment's EnvironmentRecord.
|
||||
...
|
||||
15. Set the running execution context's LexicalEnvironment to classScope.
|
||||
16. Set the running execution context's PrivateEnvironment to classPrivateEnvironment.
|
||||
...
|
||||
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,
|
||||
a. PrivateBrandAdd(F, F).
|
||||
34. For each item fieldRecord in order from staticFields,
|
||||
a. Perform ? DefineField(F, field).
|
||||
|
||||
FieldDefinition : ClassElementName Initializer_opt
|
||||
1. Let name be the result of evaluating ClassElementName.
|
||||
2. ReturnIfAbrupt(name).
|
||||
3. If Initializer_opt is present,
|
||||
a. Let lex be the Lexical Environment of the running execution context.
|
||||
b. Let formalParameterList be an instance of the production FormalParameters : [empty].
|
||||
c. Let privateScope be the PrivateEnvironment of the running execution context.
|
||||
d. Let initializer be FunctionCreate(Method, formalParameterList, Initializer, lex, true, privateScope).
|
||||
e. Perform MakeMethod(initializer, homeObject).
|
||||
f. Let isAnonymousFunctionDefinition be IsAnonymousFunctionDefinition(Initializer).
|
||||
4. Else,
|
||||
a. Let initializer be empty.
|
||||
b. Let isAnonymousFunctionDeclaration be false.
|
||||
5. Return a Record { [[Name]]: name, [[Initializer]]: initializer, [[IsAnonymousFunctionDefinition]]: isAnonymousFunctionDefinition }.
|
||||
|
||||
MemberExpression : MemberExpression.PrivateIdentifier
|
||||
1. Let baseReference be the result of evaluating MemberExpression.
|
||||
2. Let baseValue be ? GetValue(baseReference).
|
||||
3. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
4. Let fieldNameString be the StringValue of PrivateIdentifier.
|
||||
5. Return MakePrivateReference(bv, fieldNameString).
|
||||
|
||||
MakePrivateReference(baseValue, privateIdentifier)
|
||||
1. Let env be the running execution context's PrivateEnvironment.
|
||||
2. Let privateNameBinding be ? ResolveBinding(privateIdentifier, env).
|
||||
3. Let privateName be GetValue(privateNameBinding).
|
||||
4. Assert: privateName is a Private Name.
|
||||
5. Return a value of type Reference whose base value is baseValue, whose referenced name is privateName, whose strict reference flag is true.
|
||||
template: default
|
||||
features: [class-static-methods-private, class-static-fields-public, class-methods-private]
|
||||
---*/
|
||||
|
||||
//- elements
|
||||
static #m() { return 'outer class'; }
|
||||
|
||||
static methodAccess() {
|
||||
return this.#m();
|
||||
}
|
||||
|
||||
static B = class {
|
||||
set #m(v) { this._v = v; }
|
||||
|
||||
static access(o) {
|
||||
o.#m = 'inner class';
|
||||
}
|
||||
}
|
||||
//- assertions
|
||||
assert.sameValue(C.methodAccess(), 'outer class');
|
||||
|
||||
let b = new C.B();
|
||||
|
||||
C.B.access(b);
|
||||
assert.sameValue(b._v, 'inner class');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
C.B.access(C);
|
||||
}, 'accessed private setter from an arbritary object');
|
|
@ -0,0 +1,77 @@
|
|||
// Copyright (C) 2019 Caio Lima (Igalia SL). All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
desc: PrivateName of private static method is available inside inner classes
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
CallExpression[Yield, Await]:
|
||||
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await]
|
||||
SuperCall[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await]Arguments[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await][Expression[+In, ?Yield, ?Await]]
|
||||
CallExpression[?Yield, ?Await].IdentifierName
|
||||
CallExpression[?Yield, ?Await]TemplateLiteral[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await].PrivateIdentifier
|
||||
|
||||
ClassTail : ClassHeritage { ClassBody }
|
||||
...
|
||||
6. Let classPrivateEnvironment be NewDeclarativeEnvironment(outerPrivateEnvironment).
|
||||
7. Let classPrivateEnvRec be classPrivateEnvironment's EnvironmentRecord.
|
||||
...
|
||||
15. Set the running execution context's LexicalEnvironment to classScope.
|
||||
16. Set the running execution context's PrivateEnvironment to classPrivateEnvironment.
|
||||
...
|
||||
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,
|
||||
a. PrivateBrandAdd(F, F).
|
||||
34. For each item fieldRecord in order from staticFields,
|
||||
a. Perform ? DefineField(F, field).
|
||||
|
||||
FieldDefinition : ClassElementName Initializer_opt
|
||||
1. Let name be the result of evaluating ClassElementName.
|
||||
2. ReturnIfAbrupt(name).
|
||||
3. If Initializer_opt is present,
|
||||
a. Let lex be the Lexical Environment of the running execution context.
|
||||
b. Let formalParameterList be an instance of the production FormalParameters : [empty].
|
||||
c. Let privateScope be the PrivateEnvironment of the running execution context.
|
||||
d. Let initializer be FunctionCreate(Method, formalParameterList, Initializer, lex, true, privateScope).
|
||||
e. Perform MakeMethod(initializer, homeObject).
|
||||
f. Let isAnonymousFunctionDefinition be IsAnonymousFunctionDefinition(Initializer).
|
||||
4. Else,
|
||||
a. Let initializer be empty.
|
||||
b. Let isAnonymousFunctionDeclaration be false.
|
||||
5. Return a Record { [[Name]]: name, [[Initializer]]: initializer, [[IsAnonymousFunctionDefinition]]: isAnonymousFunctionDefinition }.
|
||||
|
||||
MemberExpression : MemberExpression.PrivateIdentifier
|
||||
1. Let baseReference be the result of evaluating MemberExpression.
|
||||
2. Let baseValue be ? GetValue(baseReference).
|
||||
3. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
4. Let fieldNameString be the StringValue of PrivateIdentifier.
|
||||
5. Return MakePrivateReference(bv, fieldNameString).
|
||||
|
||||
MakePrivateReference(baseValue, privateIdentifier)
|
||||
1. Let env be the running execution context's PrivateEnvironment.
|
||||
2. Let privateNameBinding be ? ResolveBinding(privateIdentifier, env).
|
||||
3. Let privateName be GetValue(privateNameBinding).
|
||||
4. Assert: privateName is a Private Name.
|
||||
5. Return a value of type Reference whose base value is baseValue, whose referenced name is privateName, whose strict reference flag is true.
|
||||
template: default
|
||||
features: [class-static-methods-private, class-static-fields-public]
|
||||
---*/
|
||||
|
||||
//- elements
|
||||
static #m() {
|
||||
return 'outer class';
|
||||
}
|
||||
|
||||
static B = class {
|
||||
static methodAccess(o) {
|
||||
return o.#m();
|
||||
}
|
||||
}
|
||||
//- assertions
|
||||
assert.sameValue(C.B.methodAccess(C), 'outer class');
|
||||
assert.throws(TypeError, function() {
|
||||
C.B.methodAccess(C.B);
|
||||
}, 'accessed static private method from an arbritary object');
|
|
@ -0,0 +1,89 @@
|
|||
// This file was procedurally generated from the following sources:
|
||||
// - src/class-elements/private-static-field-shadowed-by-field-on-nested-class.case
|
||||
// - src/class-elements/default/cls-expr.template
|
||||
/*---
|
||||
description: PrivateName of private static field can be shadowed on inner classes by a private field (field definitions in a class expression)
|
||||
esid: prod-FieldDefinition
|
||||
features: [class-static-fields-private, class-static-fields-public, class-fields-private, class]
|
||||
flags: [generated]
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
CallExpression[Yield, Await]:
|
||||
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await]
|
||||
SuperCall[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await]Arguments[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await][Expression[+In, ?Yield, ?Await]]
|
||||
CallExpression[?Yield, ?Await].IdentifierName
|
||||
CallExpression[?Yield, ?Await]TemplateLiteral[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await].PrivateIdentifier
|
||||
|
||||
ClassTail : ClassHeritage { ClassBody }
|
||||
...
|
||||
6. Let classPrivateEnvironment be NewDeclarativeEnvironment(outerPrivateEnvironment).
|
||||
7. Let classPrivateEnvRec be classPrivateEnvironment's EnvironmentRecord.
|
||||
...
|
||||
15. Set the running execution context's LexicalEnvironment to classScope.
|
||||
16. Set the running execution context's PrivateEnvironment to classPrivateEnvironment.
|
||||
...
|
||||
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,
|
||||
a. PrivateBrandAdd(F, F).
|
||||
34. For each item fieldRecord in order from staticFields,
|
||||
a. Perform ? DefineField(F, field).
|
||||
|
||||
FieldDefinition : ClassElementName Initializer_opt
|
||||
1. Let name be the result of evaluating ClassElementName.
|
||||
2. ReturnIfAbrupt(name).
|
||||
3. If Initializer_opt is present,
|
||||
a. Let lex be the Lexical Environment of the running execution context.
|
||||
b. Let formalParameterList be an instance of the production FormalParameters : [empty].
|
||||
c. Let privateScope be the PrivateEnvironment of the running execution context.
|
||||
d. Let initializer be FunctionCreate(Method, formalParameterList, Initializer, lex, true, privateScope).
|
||||
e. Perform MakeMethod(initializer, homeObject).
|
||||
f. Let isAnonymousFunctionDefinition be IsAnonymousFunctionDefinition(Initializer).
|
||||
4. Else,
|
||||
a. Let initializer be empty.
|
||||
b. Let isAnonymousFunctionDeclaration be false.
|
||||
5. Return a Record { [[Name]]: name, [[Initializer]]: initializer, [[IsAnonymousFunctionDefinition]]: isAnonymousFunctionDefinition }.
|
||||
|
||||
MemberExpression : MemberExpression.PrivateIdentifier
|
||||
1. Let baseReference be the result of evaluating MemberExpression.
|
||||
2. Let baseValue be ? GetValue(baseReference).
|
||||
3. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
4. Let fieldNameString be the StringValue of PrivateIdentifier.
|
||||
5. Return MakePrivateReference(bv, fieldNameString).
|
||||
|
||||
MakePrivateReference(baseValue, privateIdentifier)
|
||||
1. Let env be the running execution context's PrivateEnvironment.
|
||||
2. Let privateNameBinding be ? ResolveBinding(privateIdentifier, env).
|
||||
3. Let privateName be GetValue(privateNameBinding).
|
||||
4. Assert: privateName is a Private Name.
|
||||
5. Return a value of type Reference whose base value is baseValue, whose referenced name is privateName, whose strict reference flag is true.
|
||||
|
||||
---*/
|
||||
|
||||
|
||||
var C = class {
|
||||
static #m = 'outer class';
|
||||
|
||||
static fieldAccess() {
|
||||
return this.#m;
|
||||
}
|
||||
|
||||
static B = class {
|
||||
#m = 'inner class';
|
||||
static fieldAccess(o) {
|
||||
return o.#m;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert.sameValue(C.fieldAccess(), 'outer class');
|
||||
|
||||
let b = new C.B();
|
||||
|
||||
assert.sameValue(C.B.fieldAccess(b), 'inner class');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
C.B.fieldAccess(C);
|
||||
}, 'accessed private field from an arbritary object');
|
|
@ -0,0 +1,90 @@
|
|||
// This file was procedurally generated from the following sources:
|
||||
// - src/class-elements/private-static-field-shadowed-by-getter-on-nested-class.case
|
||||
// - src/class-elements/default/cls-expr.template
|
||||
/*---
|
||||
description: PrivateName of private static field can be shadowed on inner classes by a private getter (field definitions in a class expression)
|
||||
esid: prod-FieldDefinition
|
||||
features: [class-static-fields-private, class-static-fields-public, class-methods-private, class]
|
||||
flags: [generated]
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
CallExpression[Yield, Await]:
|
||||
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await]
|
||||
SuperCall[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await]Arguments[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await][Expression[+In, ?Yield, ?Await]]
|
||||
CallExpression[?Yield, ?Await].IdentifierName
|
||||
CallExpression[?Yield, ?Await]TemplateLiteral[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await].PrivateIdentifier
|
||||
|
||||
ClassTail : ClassHeritage { ClassBody }
|
||||
...
|
||||
6. Let classPrivateEnvironment be NewDeclarativeEnvironment(outerPrivateEnvironment).
|
||||
7. Let classPrivateEnvRec be classPrivateEnvironment's EnvironmentRecord.
|
||||
...
|
||||
15. Set the running execution context's LexicalEnvironment to classScope.
|
||||
16. Set the running execution context's PrivateEnvironment to classPrivateEnvironment.
|
||||
...
|
||||
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,
|
||||
a. PrivateBrandAdd(F, F).
|
||||
34. For each item fieldRecord in order from staticFields,
|
||||
a. Perform ? DefineField(F, field).
|
||||
|
||||
FieldDefinition : ClassElementName Initializer_opt
|
||||
1. Let name be the result of evaluating ClassElementName.
|
||||
2. ReturnIfAbrupt(name).
|
||||
3. If Initializer_opt is present,
|
||||
a. Let lex be the Lexical Environment of the running execution context.
|
||||
b. Let formalParameterList be an instance of the production FormalParameters : [empty].
|
||||
c. Let privateScope be the PrivateEnvironment of the running execution context.
|
||||
d. Let initializer be FunctionCreate(Method, formalParameterList, Initializer, lex, true, privateScope).
|
||||
e. Perform MakeMethod(initializer, homeObject).
|
||||
f. Let isAnonymousFunctionDefinition be IsAnonymousFunctionDefinition(Initializer).
|
||||
4. Else,
|
||||
a. Let initializer be empty.
|
||||
b. Let isAnonymousFunctionDeclaration be false.
|
||||
5. Return a Record { [[Name]]: name, [[Initializer]]: initializer, [[IsAnonymousFunctionDefinition]]: isAnonymousFunctionDefinition }.
|
||||
|
||||
MemberExpression : MemberExpression.PrivateIdentifier
|
||||
1. Let baseReference be the result of evaluating MemberExpression.
|
||||
2. Let baseValue be ? GetValue(baseReference).
|
||||
3. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
4. Let fieldNameString be the StringValue of PrivateIdentifier.
|
||||
5. Return MakePrivateReference(bv, fieldNameString).
|
||||
|
||||
MakePrivateReference(baseValue, privateIdentifier)
|
||||
1. Let env be the running execution context's PrivateEnvironment.
|
||||
2. Let privateNameBinding be ? ResolveBinding(privateIdentifier, env).
|
||||
3. Let privateName be GetValue(privateNameBinding).
|
||||
4. Assert: privateName is a Private Name.
|
||||
5. Return a value of type Reference whose base value is baseValue, whose referenced name is privateName, whose strict reference flag is true.
|
||||
|
||||
---*/
|
||||
|
||||
|
||||
var C = class {
|
||||
static #m = 'outer class';
|
||||
|
||||
static fieldAccess() {
|
||||
return this.#m;
|
||||
}
|
||||
|
||||
static B = class {
|
||||
get #m() { return 'inner class'; }
|
||||
|
||||
static access(o) {
|
||||
return o.#m;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert.sameValue(C.fieldAccess(), 'outer class');
|
||||
|
||||
let b = new C.B();
|
||||
|
||||
assert.sameValue(C.B.access(b), 'inner class');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
C.B.access(C);
|
||||
}, 'accessed private getter from an arbritary object');
|
|
@ -0,0 +1,90 @@
|
|||
// This file was procedurally generated from the following sources:
|
||||
// - src/class-elements/private-static-field-shadowed-by-method-on-nested-class.case
|
||||
// - src/class-elements/default/cls-expr.template
|
||||
/*---
|
||||
description: PrivateName of private static field can be shadowed on inner classes by a private method (field definitions in a class expression)
|
||||
esid: prod-FieldDefinition
|
||||
features: [class-static-fields-private, class-static-fields-public, class-methods-private, class]
|
||||
flags: [generated]
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
CallExpression[Yield, Await]:
|
||||
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await]
|
||||
SuperCall[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await]Arguments[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await][Expression[+In, ?Yield, ?Await]]
|
||||
CallExpression[?Yield, ?Await].IdentifierName
|
||||
CallExpression[?Yield, ?Await]TemplateLiteral[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await].PrivateIdentifier
|
||||
|
||||
ClassTail : ClassHeritage { ClassBody }
|
||||
...
|
||||
6. Let classPrivateEnvironment be NewDeclarativeEnvironment(outerPrivateEnvironment).
|
||||
7. Let classPrivateEnvRec be classPrivateEnvironment's EnvironmentRecord.
|
||||
...
|
||||
15. Set the running execution context's LexicalEnvironment to classScope.
|
||||
16. Set the running execution context's PrivateEnvironment to classPrivateEnvironment.
|
||||
...
|
||||
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,
|
||||
a. PrivateBrandAdd(F, F).
|
||||
34. For each item fieldRecord in order from staticFields,
|
||||
a. Perform ? DefineField(F, field).
|
||||
|
||||
FieldDefinition : ClassElementName Initializer_opt
|
||||
1. Let name be the result of evaluating ClassElementName.
|
||||
2. ReturnIfAbrupt(name).
|
||||
3. If Initializer_opt is present,
|
||||
a. Let lex be the Lexical Environment of the running execution context.
|
||||
b. Let formalParameterList be an instance of the production FormalParameters : [empty].
|
||||
c. Let privateScope be the PrivateEnvironment of the running execution context.
|
||||
d. Let initializer be FunctionCreate(Method, formalParameterList, Initializer, lex, true, privateScope).
|
||||
e. Perform MakeMethod(initializer, homeObject).
|
||||
f. Let isAnonymousFunctionDefinition be IsAnonymousFunctionDefinition(Initializer).
|
||||
4. Else,
|
||||
a. Let initializer be empty.
|
||||
b. Let isAnonymousFunctionDeclaration be false.
|
||||
5. Return a Record { [[Name]]: name, [[Initializer]]: initializer, [[IsAnonymousFunctionDefinition]]: isAnonymousFunctionDefinition }.
|
||||
|
||||
MemberExpression : MemberExpression.PrivateIdentifier
|
||||
1. Let baseReference be the result of evaluating MemberExpression.
|
||||
2. Let baseValue be ? GetValue(baseReference).
|
||||
3. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
4. Let fieldNameString be the StringValue of PrivateIdentifier.
|
||||
5. Return MakePrivateReference(bv, fieldNameString).
|
||||
|
||||
MakePrivateReference(baseValue, privateIdentifier)
|
||||
1. Let env be the running execution context's PrivateEnvironment.
|
||||
2. Let privateNameBinding be ? ResolveBinding(privateIdentifier, env).
|
||||
3. Let privateName be GetValue(privateNameBinding).
|
||||
4. Assert: privateName is a Private Name.
|
||||
5. Return a value of type Reference whose base value is baseValue, whose referenced name is privateName, whose strict reference flag is true.
|
||||
|
||||
---*/
|
||||
|
||||
|
||||
var C = class {
|
||||
static #m = () => 'outer class';
|
||||
|
||||
static fieldAccess() {
|
||||
return this.#m();
|
||||
}
|
||||
|
||||
static B = class {
|
||||
#m() { return 'inner class'; }
|
||||
|
||||
static access(o) {
|
||||
return o.#m();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert.sameValue(C.fieldAccess(), 'outer class');
|
||||
|
||||
let b = new C.B();
|
||||
|
||||
assert.sameValue(C.B.access(b), 'inner class');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
C.B.access(C);
|
||||
}, 'accessed private method from an arbritary object');
|
|
@ -0,0 +1,91 @@
|
|||
// This file was procedurally generated from the following sources:
|
||||
// - src/class-elements/private-static-field-shadowed-by-setter-on-nested-class.case
|
||||
// - src/class-elements/default/cls-expr.template
|
||||
/*---
|
||||
description: PrivateName of private static field can be shadowed on inner classes by a private setter (field definitions in a class expression)
|
||||
esid: prod-FieldDefinition
|
||||
features: [class-static-fields-private, class-static-fields-public, class-methods-private, class]
|
||||
flags: [generated]
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
CallExpression[Yield, Await]:
|
||||
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await]
|
||||
SuperCall[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await]Arguments[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await][Expression[+In, ?Yield, ?Await]]
|
||||
CallExpression[?Yield, ?Await].IdentifierName
|
||||
CallExpression[?Yield, ?Await]TemplateLiteral[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await].PrivateIdentifier
|
||||
|
||||
ClassTail : ClassHeritage { ClassBody }
|
||||
...
|
||||
6. Let classPrivateEnvironment be NewDeclarativeEnvironment(outerPrivateEnvironment).
|
||||
7. Let classPrivateEnvRec be classPrivateEnvironment's EnvironmentRecord.
|
||||
...
|
||||
15. Set the running execution context's LexicalEnvironment to classScope.
|
||||
16. Set the running execution context's PrivateEnvironment to classPrivateEnvironment.
|
||||
...
|
||||
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,
|
||||
a. PrivateBrandAdd(F, F).
|
||||
34. For each item fieldRecord in order from staticFields,
|
||||
a. Perform ? DefineField(F, field).
|
||||
|
||||
FieldDefinition : ClassElementName Initializer_opt
|
||||
1. Let name be the result of evaluating ClassElementName.
|
||||
2. ReturnIfAbrupt(name).
|
||||
3. If Initializer_opt is present,
|
||||
a. Let lex be the Lexical Environment of the running execution context.
|
||||
b. Let formalParameterList be an instance of the production FormalParameters : [empty].
|
||||
c. Let privateScope be the PrivateEnvironment of the running execution context.
|
||||
d. Let initializer be FunctionCreate(Method, formalParameterList, Initializer, lex, true, privateScope).
|
||||
e. Perform MakeMethod(initializer, homeObject).
|
||||
f. Let isAnonymousFunctionDefinition be IsAnonymousFunctionDefinition(Initializer).
|
||||
4. Else,
|
||||
a. Let initializer be empty.
|
||||
b. Let isAnonymousFunctionDeclaration be false.
|
||||
5. Return a Record { [[Name]]: name, [[Initializer]]: initializer, [[IsAnonymousFunctionDefinition]]: isAnonymousFunctionDefinition }.
|
||||
|
||||
MemberExpression : MemberExpression.PrivateIdentifier
|
||||
1. Let baseReference be the result of evaluating MemberExpression.
|
||||
2. Let baseValue be ? GetValue(baseReference).
|
||||
3. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
4. Let fieldNameString be the StringValue of PrivateIdentifier.
|
||||
5. Return MakePrivateReference(bv, fieldNameString).
|
||||
|
||||
MakePrivateReference(baseValue, privateIdentifier)
|
||||
1. Let env be the running execution context's PrivateEnvironment.
|
||||
2. Let privateNameBinding be ? ResolveBinding(privateIdentifier, env).
|
||||
3. Let privateName be GetValue(privateNameBinding).
|
||||
4. Assert: privateName is a Private Name.
|
||||
5. Return a value of type Reference whose base value is baseValue, whose referenced name is privateName, whose strict reference flag is true.
|
||||
|
||||
---*/
|
||||
|
||||
|
||||
var C = class {
|
||||
static #m = 'outer class';
|
||||
|
||||
static fieldAccess() {
|
||||
return this.#m;
|
||||
}
|
||||
|
||||
static B = class {
|
||||
set #m(v) { this._v = v; }
|
||||
|
||||
static access(o) {
|
||||
o.#m = 'inner class';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert.sameValue(C.fieldAccess(), 'outer class');
|
||||
|
||||
let b = new C.B();
|
||||
|
||||
C.B.access(b);
|
||||
assert.sameValue(b._v, 'inner class');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
C.B.access(C);
|
||||
}, 'accessed private setter from an arbritary object');
|
|
@ -0,0 +1,79 @@
|
|||
// This file was procedurally generated from the following sources:
|
||||
// - src/class-elements/private-static-field-usage-inside-nested-class.case
|
||||
// - src/class-elements/default/cls-expr.template
|
||||
/*---
|
||||
description: PrivateName of private static field is available inside inner classes (field definitions in a class expression)
|
||||
esid: prod-FieldDefinition
|
||||
features: [class-static-fields-private, class-static-fields-public, class]
|
||||
flags: [generated]
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
CallExpression[Yield, Await]:
|
||||
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await]
|
||||
SuperCall[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await]Arguments[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await][Expression[+In, ?Yield, ?Await]]
|
||||
CallExpression[?Yield, ?Await].IdentifierName
|
||||
CallExpression[?Yield, ?Await]TemplateLiteral[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await].PrivateIdentifier
|
||||
|
||||
ClassTail : ClassHeritage { ClassBody }
|
||||
...
|
||||
6. Let classPrivateEnvironment be NewDeclarativeEnvironment(outerPrivateEnvironment).
|
||||
7. Let classPrivateEnvRec be classPrivateEnvironment's EnvironmentRecord.
|
||||
...
|
||||
15. Set the running execution context's LexicalEnvironment to classScope.
|
||||
16. Set the running execution context's PrivateEnvironment to classPrivateEnvironment.
|
||||
...
|
||||
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,
|
||||
a. PrivateBrandAdd(F, F).
|
||||
34. For each item fieldRecord in order from staticFields,
|
||||
a. Perform ? DefineField(F, field).
|
||||
|
||||
FieldDefinition : ClassElementName Initializer_opt
|
||||
1. Let name be the result of evaluating ClassElementName.
|
||||
2. ReturnIfAbrupt(name).
|
||||
3. If Initializer_opt is present,
|
||||
a. Let lex be the Lexical Environment of the running execution context.
|
||||
b. Let formalParameterList be an instance of the production FormalParameters : [empty].
|
||||
c. Let privateScope be the PrivateEnvironment of the running execution context.
|
||||
d. Let initializer be FunctionCreate(Method, formalParameterList, Initializer, lex, true, privateScope).
|
||||
e. Perform MakeMethod(initializer, homeObject).
|
||||
f. Let isAnonymousFunctionDefinition be IsAnonymousFunctionDefinition(Initializer).
|
||||
4. Else,
|
||||
a. Let initializer be empty.
|
||||
b. Let isAnonymousFunctionDeclaration be false.
|
||||
5. Return a Record { [[Name]]: name, [[Initializer]]: initializer, [[IsAnonymousFunctionDefinition]]: isAnonymousFunctionDefinition }.
|
||||
|
||||
MemberExpression : MemberExpression.PrivateIdentifier
|
||||
1. Let baseReference be the result of evaluating MemberExpression.
|
||||
2. Let baseValue be ? GetValue(baseReference).
|
||||
3. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
4. Let fieldNameString be the StringValue of PrivateIdentifier.
|
||||
5. Return MakePrivateReference(bv, fieldNameString).
|
||||
|
||||
MakePrivateReference(baseValue, privateIdentifier)
|
||||
1. Let env be the running execution context's PrivateEnvironment.
|
||||
2. Let privateNameBinding be ? ResolveBinding(privateIdentifier, env).
|
||||
3. Let privateName be GetValue(privateNameBinding).
|
||||
4. Assert: privateName is a Private Name.
|
||||
5. Return a value of type Reference whose base value is baseValue, whose referenced name is privateName, whose strict reference flag is true.
|
||||
|
||||
---*/
|
||||
|
||||
|
||||
var C = class {
|
||||
static #m = 'outer class';
|
||||
|
||||
static B = class {
|
||||
static fieldAccess(o) {
|
||||
return o.#m;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert.sameValue(C.B.fieldAccess(C), 'outer class');
|
||||
assert.throws(TypeError, function() {
|
||||
C.B.methodAccess(C.B);
|
||||
}, 'accessed static private field from an arbritary object');
|
|
@ -0,0 +1,89 @@
|
|||
// This file was procedurally generated from the following sources:
|
||||
// - src/class-elements/private-static-method-shadowed-by-field-on-nested-class.case
|
||||
// - src/class-elements/default/cls-expr.template
|
||||
/*---
|
||||
description: PrivateName of private static method can be shadowed on inner classes by a private field (field definitions in a class expression)
|
||||
esid: prod-FieldDefinition
|
||||
features: [class-static-methods-private, class-static-fields-public, class-fields-private, class]
|
||||
flags: [generated]
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
CallExpression[Yield, Await]:
|
||||
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await]
|
||||
SuperCall[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await]Arguments[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await][Expression[+In, ?Yield, ?Await]]
|
||||
CallExpression[?Yield, ?Await].IdentifierName
|
||||
CallExpression[?Yield, ?Await]TemplateLiteral[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await].PrivateIdentifier
|
||||
|
||||
ClassTail : ClassHeritage { ClassBody }
|
||||
...
|
||||
6. Let classPrivateEnvironment be NewDeclarativeEnvironment(outerPrivateEnvironment).
|
||||
7. Let classPrivateEnvRec be classPrivateEnvironment's EnvironmentRecord.
|
||||
...
|
||||
15. Set the running execution context's LexicalEnvironment to classScope.
|
||||
16. Set the running execution context's PrivateEnvironment to classPrivateEnvironment.
|
||||
...
|
||||
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,
|
||||
a. PrivateBrandAdd(F, F).
|
||||
34. For each item fieldRecord in order from staticFields,
|
||||
a. Perform ? DefineField(F, field).
|
||||
|
||||
FieldDefinition : ClassElementName Initializer_opt
|
||||
1. Let name be the result of evaluating ClassElementName.
|
||||
2. ReturnIfAbrupt(name).
|
||||
3. If Initializer_opt is present,
|
||||
a. Let lex be the Lexical Environment of the running execution context.
|
||||
b. Let formalParameterList be an instance of the production FormalParameters : [empty].
|
||||
c. Let privateScope be the PrivateEnvironment of the running execution context.
|
||||
d. Let initializer be FunctionCreate(Method, formalParameterList, Initializer, lex, true, privateScope).
|
||||
e. Perform MakeMethod(initializer, homeObject).
|
||||
f. Let isAnonymousFunctionDefinition be IsAnonymousFunctionDefinition(Initializer).
|
||||
4. Else,
|
||||
a. Let initializer be empty.
|
||||
b. Let isAnonymousFunctionDeclaration be false.
|
||||
5. Return a Record { [[Name]]: name, [[Initializer]]: initializer, [[IsAnonymousFunctionDefinition]]: isAnonymousFunctionDefinition }.
|
||||
|
||||
MemberExpression : MemberExpression.PrivateIdentifier
|
||||
1. Let baseReference be the result of evaluating MemberExpression.
|
||||
2. Let baseValue be ? GetValue(baseReference).
|
||||
3. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
4. Let fieldNameString be the StringValue of PrivateIdentifier.
|
||||
5. Return MakePrivateReference(bv, fieldNameString).
|
||||
|
||||
MakePrivateReference(baseValue, privateIdentifier)
|
||||
1. Let env be the running execution context's PrivateEnvironment.
|
||||
2. Let privateNameBinding be ? ResolveBinding(privateIdentifier, env).
|
||||
3. Let privateName be GetValue(privateNameBinding).
|
||||
4. Assert: privateName is a Private Name.
|
||||
5. Return a value of type Reference whose base value is baseValue, whose referenced name is privateName, whose strict reference flag is true.
|
||||
|
||||
---*/
|
||||
|
||||
|
||||
var C = class {
|
||||
static #m() { return 'outer class'; }
|
||||
|
||||
static methodAccess() {
|
||||
return this.#m();
|
||||
}
|
||||
|
||||
static B = class {
|
||||
#m = 'inner class';
|
||||
static fieldAccess(o) {
|
||||
return o.#m;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert.sameValue(C.methodAccess(), 'outer class');
|
||||
|
||||
let b = new C.B();
|
||||
|
||||
assert.sameValue(C.B.fieldAccess(b), 'inner class');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
C.B.fieldAccess(C);
|
||||
}, 'accessed private field from an arbritary object');
|
|
@ -0,0 +1,90 @@
|
|||
// This file was procedurally generated from the following sources:
|
||||
// - src/class-elements/private-static-method-shadowed-by-getter-on-nested-class.case
|
||||
// - src/class-elements/default/cls-expr.template
|
||||
/*---
|
||||
description: PrivateName of private static method can be shadowed on inner classes by a private getter (field definitions in a class expression)
|
||||
esid: prod-FieldDefinition
|
||||
features: [class-static-methods-private, class-static-fields-public, class-methods-private, class]
|
||||
flags: [generated]
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
CallExpression[Yield, Await]:
|
||||
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await]
|
||||
SuperCall[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await]Arguments[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await][Expression[+In, ?Yield, ?Await]]
|
||||
CallExpression[?Yield, ?Await].IdentifierName
|
||||
CallExpression[?Yield, ?Await]TemplateLiteral[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await].PrivateIdentifier
|
||||
|
||||
ClassTail : ClassHeritage { ClassBody }
|
||||
...
|
||||
6. Let classPrivateEnvironment be NewDeclarativeEnvironment(outerPrivateEnvironment).
|
||||
7. Let classPrivateEnvRec be classPrivateEnvironment's EnvironmentRecord.
|
||||
...
|
||||
15. Set the running execution context's LexicalEnvironment to classScope.
|
||||
16. Set the running execution context's PrivateEnvironment to classPrivateEnvironment.
|
||||
...
|
||||
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,
|
||||
a. PrivateBrandAdd(F, F).
|
||||
34. For each item fieldRecord in order from staticFields,
|
||||
a. Perform ? DefineField(F, field).
|
||||
|
||||
FieldDefinition : ClassElementName Initializer_opt
|
||||
1. Let name be the result of evaluating ClassElementName.
|
||||
2. ReturnIfAbrupt(name).
|
||||
3. If Initializer_opt is present,
|
||||
a. Let lex be the Lexical Environment of the running execution context.
|
||||
b. Let formalParameterList be an instance of the production FormalParameters : [empty].
|
||||
c. Let privateScope be the PrivateEnvironment of the running execution context.
|
||||
d. Let initializer be FunctionCreate(Method, formalParameterList, Initializer, lex, true, privateScope).
|
||||
e. Perform MakeMethod(initializer, homeObject).
|
||||
f. Let isAnonymousFunctionDefinition be IsAnonymousFunctionDefinition(Initializer).
|
||||
4. Else,
|
||||
a. Let initializer be empty.
|
||||
b. Let isAnonymousFunctionDeclaration be false.
|
||||
5. Return a Record { [[Name]]: name, [[Initializer]]: initializer, [[IsAnonymousFunctionDefinition]]: isAnonymousFunctionDefinition }.
|
||||
|
||||
MemberExpression : MemberExpression.PrivateIdentifier
|
||||
1. Let baseReference be the result of evaluating MemberExpression.
|
||||
2. Let baseValue be ? GetValue(baseReference).
|
||||
3. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
4. Let fieldNameString be the StringValue of PrivateIdentifier.
|
||||
5. Return MakePrivateReference(bv, fieldNameString).
|
||||
|
||||
MakePrivateReference(baseValue, privateIdentifier)
|
||||
1. Let env be the running execution context's PrivateEnvironment.
|
||||
2. Let privateNameBinding be ? ResolveBinding(privateIdentifier, env).
|
||||
3. Let privateName be GetValue(privateNameBinding).
|
||||
4. Assert: privateName is a Private Name.
|
||||
5. Return a value of type Reference whose base value is baseValue, whose referenced name is privateName, whose strict reference flag is true.
|
||||
|
||||
---*/
|
||||
|
||||
|
||||
var C = class {
|
||||
static #m() { return 'outer class'; }
|
||||
|
||||
static methodAccess() {
|
||||
return this.#m();
|
||||
}
|
||||
|
||||
static B = class {
|
||||
get #m() { return 'inner class'; }
|
||||
|
||||
static access(o) {
|
||||
return o.#m;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert.sameValue(C.methodAccess(), 'outer class');
|
||||
|
||||
let b = new C.B();
|
||||
|
||||
assert.sameValue(C.B.access(b), 'inner class');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
C.B.access(C);
|
||||
}, 'accessed private getter from an arbritary object');
|
|
@ -0,0 +1,90 @@
|
|||
// This file was procedurally generated from the following sources:
|
||||
// - src/class-elements/private-static-method-shadowed-by-method-on-nested-class.case
|
||||
// - src/class-elements/default/cls-expr.template
|
||||
/*---
|
||||
description: PrivateName of private static method can be shadowed on inner classes by a private method (field definitions in a class expression)
|
||||
esid: prod-FieldDefinition
|
||||
features: [class-static-methods-private, class-static-fields-public, class-methods-private, class]
|
||||
flags: [generated]
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
CallExpression[Yield, Await]:
|
||||
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await]
|
||||
SuperCall[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await]Arguments[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await][Expression[+In, ?Yield, ?Await]]
|
||||
CallExpression[?Yield, ?Await].IdentifierName
|
||||
CallExpression[?Yield, ?Await]TemplateLiteral[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await].PrivateIdentifier
|
||||
|
||||
ClassTail : ClassHeritage { ClassBody }
|
||||
...
|
||||
6. Let classPrivateEnvironment be NewDeclarativeEnvironment(outerPrivateEnvironment).
|
||||
7. Let classPrivateEnvRec be classPrivateEnvironment's EnvironmentRecord.
|
||||
...
|
||||
15. Set the running execution context's LexicalEnvironment to classScope.
|
||||
16. Set the running execution context's PrivateEnvironment to classPrivateEnvironment.
|
||||
...
|
||||
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,
|
||||
a. PrivateBrandAdd(F, F).
|
||||
34. For each item fieldRecord in order from staticFields,
|
||||
a. Perform ? DefineField(F, field).
|
||||
|
||||
FieldDefinition : ClassElementName Initializer_opt
|
||||
1. Let name be the result of evaluating ClassElementName.
|
||||
2. ReturnIfAbrupt(name).
|
||||
3. If Initializer_opt is present,
|
||||
a. Let lex be the Lexical Environment of the running execution context.
|
||||
b. Let formalParameterList be an instance of the production FormalParameters : [empty].
|
||||
c. Let privateScope be the PrivateEnvironment of the running execution context.
|
||||
d. Let initializer be FunctionCreate(Method, formalParameterList, Initializer, lex, true, privateScope).
|
||||
e. Perform MakeMethod(initializer, homeObject).
|
||||
f. Let isAnonymousFunctionDefinition be IsAnonymousFunctionDefinition(Initializer).
|
||||
4. Else,
|
||||
a. Let initializer be empty.
|
||||
b. Let isAnonymousFunctionDeclaration be false.
|
||||
5. Return a Record { [[Name]]: name, [[Initializer]]: initializer, [[IsAnonymousFunctionDefinition]]: isAnonymousFunctionDefinition }.
|
||||
|
||||
MemberExpression : MemberExpression.PrivateIdentifier
|
||||
1. Let baseReference be the result of evaluating MemberExpression.
|
||||
2. Let baseValue be ? GetValue(baseReference).
|
||||
3. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
4. Let fieldNameString be the StringValue of PrivateIdentifier.
|
||||
5. Return MakePrivateReference(bv, fieldNameString).
|
||||
|
||||
MakePrivateReference(baseValue, privateIdentifier)
|
||||
1. Let env be the running execution context's PrivateEnvironment.
|
||||
2. Let privateNameBinding be ? ResolveBinding(privateIdentifier, env).
|
||||
3. Let privateName be GetValue(privateNameBinding).
|
||||
4. Assert: privateName is a Private Name.
|
||||
5. Return a value of type Reference whose base value is baseValue, whose referenced name is privateName, whose strict reference flag is true.
|
||||
|
||||
---*/
|
||||
|
||||
|
||||
var C = class {
|
||||
static #m() { return 'outer class'; }
|
||||
|
||||
static methodAccess() {
|
||||
return this.#m();
|
||||
}
|
||||
|
||||
static B = class {
|
||||
#m() { return 'inner class'; }
|
||||
|
||||
static access(o) {
|
||||
return o.#m();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert.sameValue(C.methodAccess(), 'outer class');
|
||||
|
||||
let b = new C.B();
|
||||
|
||||
assert.sameValue(C.B.access(b), 'inner class');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
C.B.access(C);
|
||||
}, 'accessed private method from an arbritary object');
|
|
@ -0,0 +1,91 @@
|
|||
// This file was procedurally generated from the following sources:
|
||||
// - src/class-elements/private-static-method-shadowed-by-setter-on-nested-class.case
|
||||
// - src/class-elements/default/cls-expr.template
|
||||
/*---
|
||||
description: PrivateName of private static method can be shadowed on inner classes by a private setter (field definitions in a class expression)
|
||||
esid: prod-FieldDefinition
|
||||
features: [class-static-methods-private, class-static-fields-public, class-methods-private, class]
|
||||
flags: [generated]
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
CallExpression[Yield, Await]:
|
||||
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await]
|
||||
SuperCall[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await]Arguments[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await][Expression[+In, ?Yield, ?Await]]
|
||||
CallExpression[?Yield, ?Await].IdentifierName
|
||||
CallExpression[?Yield, ?Await]TemplateLiteral[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await].PrivateIdentifier
|
||||
|
||||
ClassTail : ClassHeritage { ClassBody }
|
||||
...
|
||||
6. Let classPrivateEnvironment be NewDeclarativeEnvironment(outerPrivateEnvironment).
|
||||
7. Let classPrivateEnvRec be classPrivateEnvironment's EnvironmentRecord.
|
||||
...
|
||||
15. Set the running execution context's LexicalEnvironment to classScope.
|
||||
16. Set the running execution context's PrivateEnvironment to classPrivateEnvironment.
|
||||
...
|
||||
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,
|
||||
a. PrivateBrandAdd(F, F).
|
||||
34. For each item fieldRecord in order from staticFields,
|
||||
a. Perform ? DefineField(F, field).
|
||||
|
||||
FieldDefinition : ClassElementName Initializer_opt
|
||||
1. Let name be the result of evaluating ClassElementName.
|
||||
2. ReturnIfAbrupt(name).
|
||||
3. If Initializer_opt is present,
|
||||
a. Let lex be the Lexical Environment of the running execution context.
|
||||
b. Let formalParameterList be an instance of the production FormalParameters : [empty].
|
||||
c. Let privateScope be the PrivateEnvironment of the running execution context.
|
||||
d. Let initializer be FunctionCreate(Method, formalParameterList, Initializer, lex, true, privateScope).
|
||||
e. Perform MakeMethod(initializer, homeObject).
|
||||
f. Let isAnonymousFunctionDefinition be IsAnonymousFunctionDefinition(Initializer).
|
||||
4. Else,
|
||||
a. Let initializer be empty.
|
||||
b. Let isAnonymousFunctionDeclaration be false.
|
||||
5. Return a Record { [[Name]]: name, [[Initializer]]: initializer, [[IsAnonymousFunctionDefinition]]: isAnonymousFunctionDefinition }.
|
||||
|
||||
MemberExpression : MemberExpression.PrivateIdentifier
|
||||
1. Let baseReference be the result of evaluating MemberExpression.
|
||||
2. Let baseValue be ? GetValue(baseReference).
|
||||
3. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
4. Let fieldNameString be the StringValue of PrivateIdentifier.
|
||||
5. Return MakePrivateReference(bv, fieldNameString).
|
||||
|
||||
MakePrivateReference(baseValue, privateIdentifier)
|
||||
1. Let env be the running execution context's PrivateEnvironment.
|
||||
2. Let privateNameBinding be ? ResolveBinding(privateIdentifier, env).
|
||||
3. Let privateName be GetValue(privateNameBinding).
|
||||
4. Assert: privateName is a Private Name.
|
||||
5. Return a value of type Reference whose base value is baseValue, whose referenced name is privateName, whose strict reference flag is true.
|
||||
|
||||
---*/
|
||||
|
||||
|
||||
var C = class {
|
||||
static #m() { return 'outer class'; }
|
||||
|
||||
static methodAccess() {
|
||||
return this.#m();
|
||||
}
|
||||
|
||||
static B = class {
|
||||
set #m(v) { this._v = v; }
|
||||
|
||||
static access(o) {
|
||||
o.#m = 'inner class';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert.sameValue(C.methodAccess(), 'outer class');
|
||||
|
||||
let b = new C.B();
|
||||
|
||||
C.B.access(b);
|
||||
assert.sameValue(b._v, 'inner class');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
C.B.access(C);
|
||||
}, 'accessed private setter from an arbritary object');
|
|
@ -0,0 +1,81 @@
|
|||
// This file was procedurally generated from the following sources:
|
||||
// - src/class-elements/private-static-method-usage-inside-nested-class.case
|
||||
// - src/class-elements/default/cls-expr.template
|
||||
/*---
|
||||
description: PrivateName of private static method is available inside inner classes (field definitions in a class expression)
|
||||
esid: prod-FieldDefinition
|
||||
features: [class-static-methods-private, class-static-fields-public, class]
|
||||
flags: [generated]
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
CallExpression[Yield, Await]:
|
||||
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await]
|
||||
SuperCall[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await]Arguments[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await][Expression[+In, ?Yield, ?Await]]
|
||||
CallExpression[?Yield, ?Await].IdentifierName
|
||||
CallExpression[?Yield, ?Await]TemplateLiteral[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await].PrivateIdentifier
|
||||
|
||||
ClassTail : ClassHeritage { ClassBody }
|
||||
...
|
||||
6. Let classPrivateEnvironment be NewDeclarativeEnvironment(outerPrivateEnvironment).
|
||||
7. Let classPrivateEnvRec be classPrivateEnvironment's EnvironmentRecord.
|
||||
...
|
||||
15. Set the running execution context's LexicalEnvironment to classScope.
|
||||
16. Set the running execution context's PrivateEnvironment to classPrivateEnvironment.
|
||||
...
|
||||
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,
|
||||
a. PrivateBrandAdd(F, F).
|
||||
34. For each item fieldRecord in order from staticFields,
|
||||
a. Perform ? DefineField(F, field).
|
||||
|
||||
FieldDefinition : ClassElementName Initializer_opt
|
||||
1. Let name be the result of evaluating ClassElementName.
|
||||
2. ReturnIfAbrupt(name).
|
||||
3. If Initializer_opt is present,
|
||||
a. Let lex be the Lexical Environment of the running execution context.
|
||||
b. Let formalParameterList be an instance of the production FormalParameters : [empty].
|
||||
c. Let privateScope be the PrivateEnvironment of the running execution context.
|
||||
d. Let initializer be FunctionCreate(Method, formalParameterList, Initializer, lex, true, privateScope).
|
||||
e. Perform MakeMethod(initializer, homeObject).
|
||||
f. Let isAnonymousFunctionDefinition be IsAnonymousFunctionDefinition(Initializer).
|
||||
4. Else,
|
||||
a. Let initializer be empty.
|
||||
b. Let isAnonymousFunctionDeclaration be false.
|
||||
5. Return a Record { [[Name]]: name, [[Initializer]]: initializer, [[IsAnonymousFunctionDefinition]]: isAnonymousFunctionDefinition }.
|
||||
|
||||
MemberExpression : MemberExpression.PrivateIdentifier
|
||||
1. Let baseReference be the result of evaluating MemberExpression.
|
||||
2. Let baseValue be ? GetValue(baseReference).
|
||||
3. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
4. Let fieldNameString be the StringValue of PrivateIdentifier.
|
||||
5. Return MakePrivateReference(bv, fieldNameString).
|
||||
|
||||
MakePrivateReference(baseValue, privateIdentifier)
|
||||
1. Let env be the running execution context's PrivateEnvironment.
|
||||
2. Let privateNameBinding be ? ResolveBinding(privateIdentifier, env).
|
||||
3. Let privateName be GetValue(privateNameBinding).
|
||||
4. Assert: privateName is a Private Name.
|
||||
5. Return a value of type Reference whose base value is baseValue, whose referenced name is privateName, whose strict reference flag is true.
|
||||
|
||||
---*/
|
||||
|
||||
|
||||
var C = class {
|
||||
static #m() {
|
||||
return 'outer class';
|
||||
}
|
||||
|
||||
static B = class {
|
||||
static methodAccess(o) {
|
||||
return o.#m();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert.sameValue(C.B.methodAccess(C), 'outer class');
|
||||
assert.throws(TypeError, function() {
|
||||
C.B.methodAccess(C.B);
|
||||
}, 'accessed static private method from an arbritary object');
|
|
@ -0,0 +1,89 @@
|
|||
// This file was procedurally generated from the following sources:
|
||||
// - src/class-elements/private-static-field-shadowed-by-field-on-nested-class.case
|
||||
// - src/class-elements/default/cls-decl.template
|
||||
/*---
|
||||
description: PrivateName of private static field can be shadowed on inner classes by a private field (field definitions in a class declaration)
|
||||
esid: prod-FieldDefinition
|
||||
features: [class-static-fields-private, class-static-fields-public, class-fields-private, class]
|
||||
flags: [generated]
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
CallExpression[Yield, Await]:
|
||||
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await]
|
||||
SuperCall[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await]Arguments[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await][Expression[+In, ?Yield, ?Await]]
|
||||
CallExpression[?Yield, ?Await].IdentifierName
|
||||
CallExpression[?Yield, ?Await]TemplateLiteral[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await].PrivateIdentifier
|
||||
|
||||
ClassTail : ClassHeritage { ClassBody }
|
||||
...
|
||||
6. Let classPrivateEnvironment be NewDeclarativeEnvironment(outerPrivateEnvironment).
|
||||
7. Let classPrivateEnvRec be classPrivateEnvironment's EnvironmentRecord.
|
||||
...
|
||||
15. Set the running execution context's LexicalEnvironment to classScope.
|
||||
16. Set the running execution context's PrivateEnvironment to classPrivateEnvironment.
|
||||
...
|
||||
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,
|
||||
a. PrivateBrandAdd(F, F).
|
||||
34. For each item fieldRecord in order from staticFields,
|
||||
a. Perform ? DefineField(F, field).
|
||||
|
||||
FieldDefinition : ClassElementName Initializer_opt
|
||||
1. Let name be the result of evaluating ClassElementName.
|
||||
2. ReturnIfAbrupt(name).
|
||||
3. If Initializer_opt is present,
|
||||
a. Let lex be the Lexical Environment of the running execution context.
|
||||
b. Let formalParameterList be an instance of the production FormalParameters : [empty].
|
||||
c. Let privateScope be the PrivateEnvironment of the running execution context.
|
||||
d. Let initializer be FunctionCreate(Method, formalParameterList, Initializer, lex, true, privateScope).
|
||||
e. Perform MakeMethod(initializer, homeObject).
|
||||
f. Let isAnonymousFunctionDefinition be IsAnonymousFunctionDefinition(Initializer).
|
||||
4. Else,
|
||||
a. Let initializer be empty.
|
||||
b. Let isAnonymousFunctionDeclaration be false.
|
||||
5. Return a Record { [[Name]]: name, [[Initializer]]: initializer, [[IsAnonymousFunctionDefinition]]: isAnonymousFunctionDefinition }.
|
||||
|
||||
MemberExpression : MemberExpression.PrivateIdentifier
|
||||
1. Let baseReference be the result of evaluating MemberExpression.
|
||||
2. Let baseValue be ? GetValue(baseReference).
|
||||
3. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
4. Let fieldNameString be the StringValue of PrivateIdentifier.
|
||||
5. Return MakePrivateReference(bv, fieldNameString).
|
||||
|
||||
MakePrivateReference(baseValue, privateIdentifier)
|
||||
1. Let env be the running execution context's PrivateEnvironment.
|
||||
2. Let privateNameBinding be ? ResolveBinding(privateIdentifier, env).
|
||||
3. Let privateName be GetValue(privateNameBinding).
|
||||
4. Assert: privateName is a Private Name.
|
||||
5. Return a value of type Reference whose base value is baseValue, whose referenced name is privateName, whose strict reference flag is true.
|
||||
|
||||
---*/
|
||||
|
||||
|
||||
class C {
|
||||
static #m = 'outer class';
|
||||
|
||||
static fieldAccess() {
|
||||
return this.#m;
|
||||
}
|
||||
|
||||
static B = class {
|
||||
#m = 'inner class';
|
||||
static fieldAccess(o) {
|
||||
return o.#m;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert.sameValue(C.fieldAccess(), 'outer class');
|
||||
|
||||
let b = new C.B();
|
||||
|
||||
assert.sameValue(C.B.fieldAccess(b), 'inner class');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
C.B.fieldAccess(C);
|
||||
}, 'accessed private field from an arbritary object');
|
|
@ -0,0 +1,90 @@
|
|||
// This file was procedurally generated from the following sources:
|
||||
// - src/class-elements/private-static-field-shadowed-by-getter-on-nested-class.case
|
||||
// - src/class-elements/default/cls-decl.template
|
||||
/*---
|
||||
description: PrivateName of private static field can be shadowed on inner classes by a private getter (field definitions in a class declaration)
|
||||
esid: prod-FieldDefinition
|
||||
features: [class-static-fields-private, class-static-fields-public, class-methods-private, class]
|
||||
flags: [generated]
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
CallExpression[Yield, Await]:
|
||||
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await]
|
||||
SuperCall[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await]Arguments[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await][Expression[+In, ?Yield, ?Await]]
|
||||
CallExpression[?Yield, ?Await].IdentifierName
|
||||
CallExpression[?Yield, ?Await]TemplateLiteral[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await].PrivateIdentifier
|
||||
|
||||
ClassTail : ClassHeritage { ClassBody }
|
||||
...
|
||||
6. Let classPrivateEnvironment be NewDeclarativeEnvironment(outerPrivateEnvironment).
|
||||
7. Let classPrivateEnvRec be classPrivateEnvironment's EnvironmentRecord.
|
||||
...
|
||||
15. Set the running execution context's LexicalEnvironment to classScope.
|
||||
16. Set the running execution context's PrivateEnvironment to classPrivateEnvironment.
|
||||
...
|
||||
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,
|
||||
a. PrivateBrandAdd(F, F).
|
||||
34. For each item fieldRecord in order from staticFields,
|
||||
a. Perform ? DefineField(F, field).
|
||||
|
||||
FieldDefinition : ClassElementName Initializer_opt
|
||||
1. Let name be the result of evaluating ClassElementName.
|
||||
2. ReturnIfAbrupt(name).
|
||||
3. If Initializer_opt is present,
|
||||
a. Let lex be the Lexical Environment of the running execution context.
|
||||
b. Let formalParameterList be an instance of the production FormalParameters : [empty].
|
||||
c. Let privateScope be the PrivateEnvironment of the running execution context.
|
||||
d. Let initializer be FunctionCreate(Method, formalParameterList, Initializer, lex, true, privateScope).
|
||||
e. Perform MakeMethod(initializer, homeObject).
|
||||
f. Let isAnonymousFunctionDefinition be IsAnonymousFunctionDefinition(Initializer).
|
||||
4. Else,
|
||||
a. Let initializer be empty.
|
||||
b. Let isAnonymousFunctionDeclaration be false.
|
||||
5. Return a Record { [[Name]]: name, [[Initializer]]: initializer, [[IsAnonymousFunctionDefinition]]: isAnonymousFunctionDefinition }.
|
||||
|
||||
MemberExpression : MemberExpression.PrivateIdentifier
|
||||
1. Let baseReference be the result of evaluating MemberExpression.
|
||||
2. Let baseValue be ? GetValue(baseReference).
|
||||
3. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
4. Let fieldNameString be the StringValue of PrivateIdentifier.
|
||||
5. Return MakePrivateReference(bv, fieldNameString).
|
||||
|
||||
MakePrivateReference(baseValue, privateIdentifier)
|
||||
1. Let env be the running execution context's PrivateEnvironment.
|
||||
2. Let privateNameBinding be ? ResolveBinding(privateIdentifier, env).
|
||||
3. Let privateName be GetValue(privateNameBinding).
|
||||
4. Assert: privateName is a Private Name.
|
||||
5. Return a value of type Reference whose base value is baseValue, whose referenced name is privateName, whose strict reference flag is true.
|
||||
|
||||
---*/
|
||||
|
||||
|
||||
class C {
|
||||
static #m = 'outer class';
|
||||
|
||||
static fieldAccess() {
|
||||
return this.#m;
|
||||
}
|
||||
|
||||
static B = class {
|
||||
get #m() { return 'inner class'; }
|
||||
|
||||
static access(o) {
|
||||
return o.#m;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert.sameValue(C.fieldAccess(), 'outer class');
|
||||
|
||||
let b = new C.B();
|
||||
|
||||
assert.sameValue(C.B.access(b), 'inner class');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
C.B.access(C);
|
||||
}, 'accessed private getter from an arbritary object');
|
|
@ -0,0 +1,90 @@
|
|||
// This file was procedurally generated from the following sources:
|
||||
// - src/class-elements/private-static-field-shadowed-by-method-on-nested-class.case
|
||||
// - src/class-elements/default/cls-decl.template
|
||||
/*---
|
||||
description: PrivateName of private static field can be shadowed on inner classes by a private method (field definitions in a class declaration)
|
||||
esid: prod-FieldDefinition
|
||||
features: [class-static-fields-private, class-static-fields-public, class-methods-private, class]
|
||||
flags: [generated]
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
CallExpression[Yield, Await]:
|
||||
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await]
|
||||
SuperCall[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await]Arguments[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await][Expression[+In, ?Yield, ?Await]]
|
||||
CallExpression[?Yield, ?Await].IdentifierName
|
||||
CallExpression[?Yield, ?Await]TemplateLiteral[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await].PrivateIdentifier
|
||||
|
||||
ClassTail : ClassHeritage { ClassBody }
|
||||
...
|
||||
6. Let classPrivateEnvironment be NewDeclarativeEnvironment(outerPrivateEnvironment).
|
||||
7. Let classPrivateEnvRec be classPrivateEnvironment's EnvironmentRecord.
|
||||
...
|
||||
15. Set the running execution context's LexicalEnvironment to classScope.
|
||||
16. Set the running execution context's PrivateEnvironment to classPrivateEnvironment.
|
||||
...
|
||||
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,
|
||||
a. PrivateBrandAdd(F, F).
|
||||
34. For each item fieldRecord in order from staticFields,
|
||||
a. Perform ? DefineField(F, field).
|
||||
|
||||
FieldDefinition : ClassElementName Initializer_opt
|
||||
1. Let name be the result of evaluating ClassElementName.
|
||||
2. ReturnIfAbrupt(name).
|
||||
3. If Initializer_opt is present,
|
||||
a. Let lex be the Lexical Environment of the running execution context.
|
||||
b. Let formalParameterList be an instance of the production FormalParameters : [empty].
|
||||
c. Let privateScope be the PrivateEnvironment of the running execution context.
|
||||
d. Let initializer be FunctionCreate(Method, formalParameterList, Initializer, lex, true, privateScope).
|
||||
e. Perform MakeMethod(initializer, homeObject).
|
||||
f. Let isAnonymousFunctionDefinition be IsAnonymousFunctionDefinition(Initializer).
|
||||
4. Else,
|
||||
a. Let initializer be empty.
|
||||
b. Let isAnonymousFunctionDeclaration be false.
|
||||
5. Return a Record { [[Name]]: name, [[Initializer]]: initializer, [[IsAnonymousFunctionDefinition]]: isAnonymousFunctionDefinition }.
|
||||
|
||||
MemberExpression : MemberExpression.PrivateIdentifier
|
||||
1. Let baseReference be the result of evaluating MemberExpression.
|
||||
2. Let baseValue be ? GetValue(baseReference).
|
||||
3. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
4. Let fieldNameString be the StringValue of PrivateIdentifier.
|
||||
5. Return MakePrivateReference(bv, fieldNameString).
|
||||
|
||||
MakePrivateReference(baseValue, privateIdentifier)
|
||||
1. Let env be the running execution context's PrivateEnvironment.
|
||||
2. Let privateNameBinding be ? ResolveBinding(privateIdentifier, env).
|
||||
3. Let privateName be GetValue(privateNameBinding).
|
||||
4. Assert: privateName is a Private Name.
|
||||
5. Return a value of type Reference whose base value is baseValue, whose referenced name is privateName, whose strict reference flag is true.
|
||||
|
||||
---*/
|
||||
|
||||
|
||||
class C {
|
||||
static #m = () => 'outer class';
|
||||
|
||||
static fieldAccess() {
|
||||
return this.#m();
|
||||
}
|
||||
|
||||
static B = class {
|
||||
#m() { return 'inner class'; }
|
||||
|
||||
static access(o) {
|
||||
return o.#m();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert.sameValue(C.fieldAccess(), 'outer class');
|
||||
|
||||
let b = new C.B();
|
||||
|
||||
assert.sameValue(C.B.access(b), 'inner class');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
C.B.access(C);
|
||||
}, 'accessed private method from an arbritary object');
|
|
@ -0,0 +1,91 @@
|
|||
// This file was procedurally generated from the following sources:
|
||||
// - src/class-elements/private-static-field-shadowed-by-setter-on-nested-class.case
|
||||
// - src/class-elements/default/cls-decl.template
|
||||
/*---
|
||||
description: PrivateName of private static field can be shadowed on inner classes by a private setter (field definitions in a class declaration)
|
||||
esid: prod-FieldDefinition
|
||||
features: [class-static-fields-private, class-static-fields-public, class-methods-private, class]
|
||||
flags: [generated]
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
CallExpression[Yield, Await]:
|
||||
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await]
|
||||
SuperCall[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await]Arguments[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await][Expression[+In, ?Yield, ?Await]]
|
||||
CallExpression[?Yield, ?Await].IdentifierName
|
||||
CallExpression[?Yield, ?Await]TemplateLiteral[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await].PrivateIdentifier
|
||||
|
||||
ClassTail : ClassHeritage { ClassBody }
|
||||
...
|
||||
6. Let classPrivateEnvironment be NewDeclarativeEnvironment(outerPrivateEnvironment).
|
||||
7. Let classPrivateEnvRec be classPrivateEnvironment's EnvironmentRecord.
|
||||
...
|
||||
15. Set the running execution context's LexicalEnvironment to classScope.
|
||||
16. Set the running execution context's PrivateEnvironment to classPrivateEnvironment.
|
||||
...
|
||||
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,
|
||||
a. PrivateBrandAdd(F, F).
|
||||
34. For each item fieldRecord in order from staticFields,
|
||||
a. Perform ? DefineField(F, field).
|
||||
|
||||
FieldDefinition : ClassElementName Initializer_opt
|
||||
1. Let name be the result of evaluating ClassElementName.
|
||||
2. ReturnIfAbrupt(name).
|
||||
3. If Initializer_opt is present,
|
||||
a. Let lex be the Lexical Environment of the running execution context.
|
||||
b. Let formalParameterList be an instance of the production FormalParameters : [empty].
|
||||
c. Let privateScope be the PrivateEnvironment of the running execution context.
|
||||
d. Let initializer be FunctionCreate(Method, formalParameterList, Initializer, lex, true, privateScope).
|
||||
e. Perform MakeMethod(initializer, homeObject).
|
||||
f. Let isAnonymousFunctionDefinition be IsAnonymousFunctionDefinition(Initializer).
|
||||
4. Else,
|
||||
a. Let initializer be empty.
|
||||
b. Let isAnonymousFunctionDeclaration be false.
|
||||
5. Return a Record { [[Name]]: name, [[Initializer]]: initializer, [[IsAnonymousFunctionDefinition]]: isAnonymousFunctionDefinition }.
|
||||
|
||||
MemberExpression : MemberExpression.PrivateIdentifier
|
||||
1. Let baseReference be the result of evaluating MemberExpression.
|
||||
2. Let baseValue be ? GetValue(baseReference).
|
||||
3. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
4. Let fieldNameString be the StringValue of PrivateIdentifier.
|
||||
5. Return MakePrivateReference(bv, fieldNameString).
|
||||
|
||||
MakePrivateReference(baseValue, privateIdentifier)
|
||||
1. Let env be the running execution context's PrivateEnvironment.
|
||||
2. Let privateNameBinding be ? ResolveBinding(privateIdentifier, env).
|
||||
3. Let privateName be GetValue(privateNameBinding).
|
||||
4. Assert: privateName is a Private Name.
|
||||
5. Return a value of type Reference whose base value is baseValue, whose referenced name is privateName, whose strict reference flag is true.
|
||||
|
||||
---*/
|
||||
|
||||
|
||||
class C {
|
||||
static #m = 'outer class';
|
||||
|
||||
static fieldAccess() {
|
||||
return this.#m;
|
||||
}
|
||||
|
||||
static B = class {
|
||||
set #m(v) { this._v = v; }
|
||||
|
||||
static access(o) {
|
||||
o.#m = 'inner class';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert.sameValue(C.fieldAccess(), 'outer class');
|
||||
|
||||
let b = new C.B();
|
||||
|
||||
C.B.access(b);
|
||||
assert.sameValue(b._v, 'inner class');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
C.B.access(C);
|
||||
}, 'accessed private setter from an arbritary object');
|
|
@ -0,0 +1,79 @@
|
|||
// This file was procedurally generated from the following sources:
|
||||
// - src/class-elements/private-static-field-usage-inside-nested-class.case
|
||||
// - src/class-elements/default/cls-decl.template
|
||||
/*---
|
||||
description: PrivateName of private static field is available inside inner classes (field definitions in a class declaration)
|
||||
esid: prod-FieldDefinition
|
||||
features: [class-static-fields-private, class-static-fields-public, class]
|
||||
flags: [generated]
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
CallExpression[Yield, Await]:
|
||||
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await]
|
||||
SuperCall[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await]Arguments[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await][Expression[+In, ?Yield, ?Await]]
|
||||
CallExpression[?Yield, ?Await].IdentifierName
|
||||
CallExpression[?Yield, ?Await]TemplateLiteral[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await].PrivateIdentifier
|
||||
|
||||
ClassTail : ClassHeritage { ClassBody }
|
||||
...
|
||||
6. Let classPrivateEnvironment be NewDeclarativeEnvironment(outerPrivateEnvironment).
|
||||
7. Let classPrivateEnvRec be classPrivateEnvironment's EnvironmentRecord.
|
||||
...
|
||||
15. Set the running execution context's LexicalEnvironment to classScope.
|
||||
16. Set the running execution context's PrivateEnvironment to classPrivateEnvironment.
|
||||
...
|
||||
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,
|
||||
a. PrivateBrandAdd(F, F).
|
||||
34. For each item fieldRecord in order from staticFields,
|
||||
a. Perform ? DefineField(F, field).
|
||||
|
||||
FieldDefinition : ClassElementName Initializer_opt
|
||||
1. Let name be the result of evaluating ClassElementName.
|
||||
2. ReturnIfAbrupt(name).
|
||||
3. If Initializer_opt is present,
|
||||
a. Let lex be the Lexical Environment of the running execution context.
|
||||
b. Let formalParameterList be an instance of the production FormalParameters : [empty].
|
||||
c. Let privateScope be the PrivateEnvironment of the running execution context.
|
||||
d. Let initializer be FunctionCreate(Method, formalParameterList, Initializer, lex, true, privateScope).
|
||||
e. Perform MakeMethod(initializer, homeObject).
|
||||
f. Let isAnonymousFunctionDefinition be IsAnonymousFunctionDefinition(Initializer).
|
||||
4. Else,
|
||||
a. Let initializer be empty.
|
||||
b. Let isAnonymousFunctionDeclaration be false.
|
||||
5. Return a Record { [[Name]]: name, [[Initializer]]: initializer, [[IsAnonymousFunctionDefinition]]: isAnonymousFunctionDefinition }.
|
||||
|
||||
MemberExpression : MemberExpression.PrivateIdentifier
|
||||
1. Let baseReference be the result of evaluating MemberExpression.
|
||||
2. Let baseValue be ? GetValue(baseReference).
|
||||
3. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
4. Let fieldNameString be the StringValue of PrivateIdentifier.
|
||||
5. Return MakePrivateReference(bv, fieldNameString).
|
||||
|
||||
MakePrivateReference(baseValue, privateIdentifier)
|
||||
1. Let env be the running execution context's PrivateEnvironment.
|
||||
2. Let privateNameBinding be ? ResolveBinding(privateIdentifier, env).
|
||||
3. Let privateName be GetValue(privateNameBinding).
|
||||
4. Assert: privateName is a Private Name.
|
||||
5. Return a value of type Reference whose base value is baseValue, whose referenced name is privateName, whose strict reference flag is true.
|
||||
|
||||
---*/
|
||||
|
||||
|
||||
class C {
|
||||
static #m = 'outer class';
|
||||
|
||||
static B = class {
|
||||
static fieldAccess(o) {
|
||||
return o.#m;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert.sameValue(C.B.fieldAccess(C), 'outer class');
|
||||
assert.throws(TypeError, function() {
|
||||
C.B.methodAccess(C.B);
|
||||
}, 'accessed static private field from an arbritary object');
|
|
@ -0,0 +1,89 @@
|
|||
// This file was procedurally generated from the following sources:
|
||||
// - src/class-elements/private-static-method-shadowed-by-field-on-nested-class.case
|
||||
// - src/class-elements/default/cls-decl.template
|
||||
/*---
|
||||
description: PrivateName of private static method can be shadowed on inner classes by a private field (field definitions in a class declaration)
|
||||
esid: prod-FieldDefinition
|
||||
features: [class-static-methods-private, class-static-fields-public, class-fields-private, class]
|
||||
flags: [generated]
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
CallExpression[Yield, Await]:
|
||||
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await]
|
||||
SuperCall[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await]Arguments[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await][Expression[+In, ?Yield, ?Await]]
|
||||
CallExpression[?Yield, ?Await].IdentifierName
|
||||
CallExpression[?Yield, ?Await]TemplateLiteral[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await].PrivateIdentifier
|
||||
|
||||
ClassTail : ClassHeritage { ClassBody }
|
||||
...
|
||||
6. Let classPrivateEnvironment be NewDeclarativeEnvironment(outerPrivateEnvironment).
|
||||
7. Let classPrivateEnvRec be classPrivateEnvironment's EnvironmentRecord.
|
||||
...
|
||||
15. Set the running execution context's LexicalEnvironment to classScope.
|
||||
16. Set the running execution context's PrivateEnvironment to classPrivateEnvironment.
|
||||
...
|
||||
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,
|
||||
a. PrivateBrandAdd(F, F).
|
||||
34. For each item fieldRecord in order from staticFields,
|
||||
a. Perform ? DefineField(F, field).
|
||||
|
||||
FieldDefinition : ClassElementName Initializer_opt
|
||||
1. Let name be the result of evaluating ClassElementName.
|
||||
2. ReturnIfAbrupt(name).
|
||||
3. If Initializer_opt is present,
|
||||
a. Let lex be the Lexical Environment of the running execution context.
|
||||
b. Let formalParameterList be an instance of the production FormalParameters : [empty].
|
||||
c. Let privateScope be the PrivateEnvironment of the running execution context.
|
||||
d. Let initializer be FunctionCreate(Method, formalParameterList, Initializer, lex, true, privateScope).
|
||||
e. Perform MakeMethod(initializer, homeObject).
|
||||
f. Let isAnonymousFunctionDefinition be IsAnonymousFunctionDefinition(Initializer).
|
||||
4. Else,
|
||||
a. Let initializer be empty.
|
||||
b. Let isAnonymousFunctionDeclaration be false.
|
||||
5. Return a Record { [[Name]]: name, [[Initializer]]: initializer, [[IsAnonymousFunctionDefinition]]: isAnonymousFunctionDefinition }.
|
||||
|
||||
MemberExpression : MemberExpression.PrivateIdentifier
|
||||
1. Let baseReference be the result of evaluating MemberExpression.
|
||||
2. Let baseValue be ? GetValue(baseReference).
|
||||
3. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
4. Let fieldNameString be the StringValue of PrivateIdentifier.
|
||||
5. Return MakePrivateReference(bv, fieldNameString).
|
||||
|
||||
MakePrivateReference(baseValue, privateIdentifier)
|
||||
1. Let env be the running execution context's PrivateEnvironment.
|
||||
2. Let privateNameBinding be ? ResolveBinding(privateIdentifier, env).
|
||||
3. Let privateName be GetValue(privateNameBinding).
|
||||
4. Assert: privateName is a Private Name.
|
||||
5. Return a value of type Reference whose base value is baseValue, whose referenced name is privateName, whose strict reference flag is true.
|
||||
|
||||
---*/
|
||||
|
||||
|
||||
class C {
|
||||
static #m() { return 'outer class'; }
|
||||
|
||||
static methodAccess() {
|
||||
return this.#m();
|
||||
}
|
||||
|
||||
static B = class {
|
||||
#m = 'inner class';
|
||||
static fieldAccess(o) {
|
||||
return o.#m;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert.sameValue(C.methodAccess(), 'outer class');
|
||||
|
||||
let b = new C.B();
|
||||
|
||||
assert.sameValue(C.B.fieldAccess(b), 'inner class');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
C.B.fieldAccess(C);
|
||||
}, 'accessed private field from an arbritary object');
|
|
@ -0,0 +1,90 @@
|
|||
// This file was procedurally generated from the following sources:
|
||||
// - src/class-elements/private-static-method-shadowed-by-getter-on-nested-class.case
|
||||
// - src/class-elements/default/cls-decl.template
|
||||
/*---
|
||||
description: PrivateName of private static method can be shadowed on inner classes by a private getter (field definitions in a class declaration)
|
||||
esid: prod-FieldDefinition
|
||||
features: [class-static-methods-private, class-static-fields-public, class-methods-private, class]
|
||||
flags: [generated]
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
CallExpression[Yield, Await]:
|
||||
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await]
|
||||
SuperCall[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await]Arguments[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await][Expression[+In, ?Yield, ?Await]]
|
||||
CallExpression[?Yield, ?Await].IdentifierName
|
||||
CallExpression[?Yield, ?Await]TemplateLiteral[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await].PrivateIdentifier
|
||||
|
||||
ClassTail : ClassHeritage { ClassBody }
|
||||
...
|
||||
6. Let classPrivateEnvironment be NewDeclarativeEnvironment(outerPrivateEnvironment).
|
||||
7. Let classPrivateEnvRec be classPrivateEnvironment's EnvironmentRecord.
|
||||
...
|
||||
15. Set the running execution context's LexicalEnvironment to classScope.
|
||||
16. Set the running execution context's PrivateEnvironment to classPrivateEnvironment.
|
||||
...
|
||||
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,
|
||||
a. PrivateBrandAdd(F, F).
|
||||
34. For each item fieldRecord in order from staticFields,
|
||||
a. Perform ? DefineField(F, field).
|
||||
|
||||
FieldDefinition : ClassElementName Initializer_opt
|
||||
1. Let name be the result of evaluating ClassElementName.
|
||||
2. ReturnIfAbrupt(name).
|
||||
3. If Initializer_opt is present,
|
||||
a. Let lex be the Lexical Environment of the running execution context.
|
||||
b. Let formalParameterList be an instance of the production FormalParameters : [empty].
|
||||
c. Let privateScope be the PrivateEnvironment of the running execution context.
|
||||
d. Let initializer be FunctionCreate(Method, formalParameterList, Initializer, lex, true, privateScope).
|
||||
e. Perform MakeMethod(initializer, homeObject).
|
||||
f. Let isAnonymousFunctionDefinition be IsAnonymousFunctionDefinition(Initializer).
|
||||
4. Else,
|
||||
a. Let initializer be empty.
|
||||
b. Let isAnonymousFunctionDeclaration be false.
|
||||
5. Return a Record { [[Name]]: name, [[Initializer]]: initializer, [[IsAnonymousFunctionDefinition]]: isAnonymousFunctionDefinition }.
|
||||
|
||||
MemberExpression : MemberExpression.PrivateIdentifier
|
||||
1. Let baseReference be the result of evaluating MemberExpression.
|
||||
2. Let baseValue be ? GetValue(baseReference).
|
||||
3. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
4. Let fieldNameString be the StringValue of PrivateIdentifier.
|
||||
5. Return MakePrivateReference(bv, fieldNameString).
|
||||
|
||||
MakePrivateReference(baseValue, privateIdentifier)
|
||||
1. Let env be the running execution context's PrivateEnvironment.
|
||||
2. Let privateNameBinding be ? ResolveBinding(privateIdentifier, env).
|
||||
3. Let privateName be GetValue(privateNameBinding).
|
||||
4. Assert: privateName is a Private Name.
|
||||
5. Return a value of type Reference whose base value is baseValue, whose referenced name is privateName, whose strict reference flag is true.
|
||||
|
||||
---*/
|
||||
|
||||
|
||||
class C {
|
||||
static #m() { return 'outer class'; }
|
||||
|
||||
static methodAccess() {
|
||||
return this.#m();
|
||||
}
|
||||
|
||||
static B = class {
|
||||
get #m() { return 'inner class'; }
|
||||
|
||||
static access(o) {
|
||||
return o.#m;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert.sameValue(C.methodAccess(), 'outer class');
|
||||
|
||||
let b = new C.B();
|
||||
|
||||
assert.sameValue(C.B.access(b), 'inner class');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
C.B.access(C);
|
||||
}, 'accessed private getter from an arbritary object');
|
|
@ -0,0 +1,90 @@
|
|||
// This file was procedurally generated from the following sources:
|
||||
// - src/class-elements/private-static-method-shadowed-by-method-on-nested-class.case
|
||||
// - src/class-elements/default/cls-decl.template
|
||||
/*---
|
||||
description: PrivateName of private static method can be shadowed on inner classes by a private method (field definitions in a class declaration)
|
||||
esid: prod-FieldDefinition
|
||||
features: [class-static-methods-private, class-static-fields-public, class-methods-private, class]
|
||||
flags: [generated]
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
CallExpression[Yield, Await]:
|
||||
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await]
|
||||
SuperCall[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await]Arguments[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await][Expression[+In, ?Yield, ?Await]]
|
||||
CallExpression[?Yield, ?Await].IdentifierName
|
||||
CallExpression[?Yield, ?Await]TemplateLiteral[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await].PrivateIdentifier
|
||||
|
||||
ClassTail : ClassHeritage { ClassBody }
|
||||
...
|
||||
6. Let classPrivateEnvironment be NewDeclarativeEnvironment(outerPrivateEnvironment).
|
||||
7. Let classPrivateEnvRec be classPrivateEnvironment's EnvironmentRecord.
|
||||
...
|
||||
15. Set the running execution context's LexicalEnvironment to classScope.
|
||||
16. Set the running execution context's PrivateEnvironment to classPrivateEnvironment.
|
||||
...
|
||||
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,
|
||||
a. PrivateBrandAdd(F, F).
|
||||
34. For each item fieldRecord in order from staticFields,
|
||||
a. Perform ? DefineField(F, field).
|
||||
|
||||
FieldDefinition : ClassElementName Initializer_opt
|
||||
1. Let name be the result of evaluating ClassElementName.
|
||||
2. ReturnIfAbrupt(name).
|
||||
3. If Initializer_opt is present,
|
||||
a. Let lex be the Lexical Environment of the running execution context.
|
||||
b. Let formalParameterList be an instance of the production FormalParameters : [empty].
|
||||
c. Let privateScope be the PrivateEnvironment of the running execution context.
|
||||
d. Let initializer be FunctionCreate(Method, formalParameterList, Initializer, lex, true, privateScope).
|
||||
e. Perform MakeMethod(initializer, homeObject).
|
||||
f. Let isAnonymousFunctionDefinition be IsAnonymousFunctionDefinition(Initializer).
|
||||
4. Else,
|
||||
a. Let initializer be empty.
|
||||
b. Let isAnonymousFunctionDeclaration be false.
|
||||
5. Return a Record { [[Name]]: name, [[Initializer]]: initializer, [[IsAnonymousFunctionDefinition]]: isAnonymousFunctionDefinition }.
|
||||
|
||||
MemberExpression : MemberExpression.PrivateIdentifier
|
||||
1. Let baseReference be the result of evaluating MemberExpression.
|
||||
2. Let baseValue be ? GetValue(baseReference).
|
||||
3. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
4. Let fieldNameString be the StringValue of PrivateIdentifier.
|
||||
5. Return MakePrivateReference(bv, fieldNameString).
|
||||
|
||||
MakePrivateReference(baseValue, privateIdentifier)
|
||||
1. Let env be the running execution context's PrivateEnvironment.
|
||||
2. Let privateNameBinding be ? ResolveBinding(privateIdentifier, env).
|
||||
3. Let privateName be GetValue(privateNameBinding).
|
||||
4. Assert: privateName is a Private Name.
|
||||
5. Return a value of type Reference whose base value is baseValue, whose referenced name is privateName, whose strict reference flag is true.
|
||||
|
||||
---*/
|
||||
|
||||
|
||||
class C {
|
||||
static #m() { return 'outer class'; }
|
||||
|
||||
static methodAccess() {
|
||||
return this.#m();
|
||||
}
|
||||
|
||||
static B = class {
|
||||
#m() { return 'inner class'; }
|
||||
|
||||
static access(o) {
|
||||
return o.#m();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert.sameValue(C.methodAccess(), 'outer class');
|
||||
|
||||
let b = new C.B();
|
||||
|
||||
assert.sameValue(C.B.access(b), 'inner class');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
C.B.access(C);
|
||||
}, 'accessed private method from an arbritary object');
|
|
@ -0,0 +1,91 @@
|
|||
// This file was procedurally generated from the following sources:
|
||||
// - src/class-elements/private-static-method-shadowed-by-setter-on-nested-class.case
|
||||
// - src/class-elements/default/cls-decl.template
|
||||
/*---
|
||||
description: PrivateName of private static method can be shadowed on inner classes by a private setter (field definitions in a class declaration)
|
||||
esid: prod-FieldDefinition
|
||||
features: [class-static-methods-private, class-static-fields-public, class-methods-private, class]
|
||||
flags: [generated]
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
CallExpression[Yield, Await]:
|
||||
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await]
|
||||
SuperCall[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await]Arguments[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await][Expression[+In, ?Yield, ?Await]]
|
||||
CallExpression[?Yield, ?Await].IdentifierName
|
||||
CallExpression[?Yield, ?Await]TemplateLiteral[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await].PrivateIdentifier
|
||||
|
||||
ClassTail : ClassHeritage { ClassBody }
|
||||
...
|
||||
6. Let classPrivateEnvironment be NewDeclarativeEnvironment(outerPrivateEnvironment).
|
||||
7. Let classPrivateEnvRec be classPrivateEnvironment's EnvironmentRecord.
|
||||
...
|
||||
15. Set the running execution context's LexicalEnvironment to classScope.
|
||||
16. Set the running execution context's PrivateEnvironment to classPrivateEnvironment.
|
||||
...
|
||||
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,
|
||||
a. PrivateBrandAdd(F, F).
|
||||
34. For each item fieldRecord in order from staticFields,
|
||||
a. Perform ? DefineField(F, field).
|
||||
|
||||
FieldDefinition : ClassElementName Initializer_opt
|
||||
1. Let name be the result of evaluating ClassElementName.
|
||||
2. ReturnIfAbrupt(name).
|
||||
3. If Initializer_opt is present,
|
||||
a. Let lex be the Lexical Environment of the running execution context.
|
||||
b. Let formalParameterList be an instance of the production FormalParameters : [empty].
|
||||
c. Let privateScope be the PrivateEnvironment of the running execution context.
|
||||
d. Let initializer be FunctionCreate(Method, formalParameterList, Initializer, lex, true, privateScope).
|
||||
e. Perform MakeMethod(initializer, homeObject).
|
||||
f. Let isAnonymousFunctionDefinition be IsAnonymousFunctionDefinition(Initializer).
|
||||
4. Else,
|
||||
a. Let initializer be empty.
|
||||
b. Let isAnonymousFunctionDeclaration be false.
|
||||
5. Return a Record { [[Name]]: name, [[Initializer]]: initializer, [[IsAnonymousFunctionDefinition]]: isAnonymousFunctionDefinition }.
|
||||
|
||||
MemberExpression : MemberExpression.PrivateIdentifier
|
||||
1. Let baseReference be the result of evaluating MemberExpression.
|
||||
2. Let baseValue be ? GetValue(baseReference).
|
||||
3. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
4. Let fieldNameString be the StringValue of PrivateIdentifier.
|
||||
5. Return MakePrivateReference(bv, fieldNameString).
|
||||
|
||||
MakePrivateReference(baseValue, privateIdentifier)
|
||||
1. Let env be the running execution context's PrivateEnvironment.
|
||||
2. Let privateNameBinding be ? ResolveBinding(privateIdentifier, env).
|
||||
3. Let privateName be GetValue(privateNameBinding).
|
||||
4. Assert: privateName is a Private Name.
|
||||
5. Return a value of type Reference whose base value is baseValue, whose referenced name is privateName, whose strict reference flag is true.
|
||||
|
||||
---*/
|
||||
|
||||
|
||||
class C {
|
||||
static #m() { return 'outer class'; }
|
||||
|
||||
static methodAccess() {
|
||||
return this.#m();
|
||||
}
|
||||
|
||||
static B = class {
|
||||
set #m(v) { this._v = v; }
|
||||
|
||||
static access(o) {
|
||||
o.#m = 'inner class';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert.sameValue(C.methodAccess(), 'outer class');
|
||||
|
||||
let b = new C.B();
|
||||
|
||||
C.B.access(b);
|
||||
assert.sameValue(b._v, 'inner class');
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
C.B.access(C);
|
||||
}, 'accessed private setter from an arbritary object');
|
|
@ -0,0 +1,81 @@
|
|||
// This file was procedurally generated from the following sources:
|
||||
// - src/class-elements/private-static-method-usage-inside-nested-class.case
|
||||
// - src/class-elements/default/cls-decl.template
|
||||
/*---
|
||||
description: PrivateName of private static method is available inside inner classes (field definitions in a class declaration)
|
||||
esid: prod-FieldDefinition
|
||||
features: [class-static-methods-private, class-static-fields-public, class]
|
||||
flags: [generated]
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
CallExpression[Yield, Await]:
|
||||
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await]
|
||||
SuperCall[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await]Arguments[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await][Expression[+In, ?Yield, ?Await]]
|
||||
CallExpression[?Yield, ?Await].IdentifierName
|
||||
CallExpression[?Yield, ?Await]TemplateLiteral[?Yield, ?Await]
|
||||
CallExpression[?Yield, ?Await].PrivateIdentifier
|
||||
|
||||
ClassTail : ClassHeritage { ClassBody }
|
||||
...
|
||||
6. Let classPrivateEnvironment be NewDeclarativeEnvironment(outerPrivateEnvironment).
|
||||
7. Let classPrivateEnvRec be classPrivateEnvironment's EnvironmentRecord.
|
||||
...
|
||||
15. Set the running execution context's LexicalEnvironment to classScope.
|
||||
16. Set the running execution context's PrivateEnvironment to classPrivateEnvironment.
|
||||
...
|
||||
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,
|
||||
a. PrivateBrandAdd(F, F).
|
||||
34. For each item fieldRecord in order from staticFields,
|
||||
a. Perform ? DefineField(F, field).
|
||||
|
||||
FieldDefinition : ClassElementName Initializer_opt
|
||||
1. Let name be the result of evaluating ClassElementName.
|
||||
2. ReturnIfAbrupt(name).
|
||||
3. If Initializer_opt is present,
|
||||
a. Let lex be the Lexical Environment of the running execution context.
|
||||
b. Let formalParameterList be an instance of the production FormalParameters : [empty].
|
||||
c. Let privateScope be the PrivateEnvironment of the running execution context.
|
||||
d. Let initializer be FunctionCreate(Method, formalParameterList, Initializer, lex, true, privateScope).
|
||||
e. Perform MakeMethod(initializer, homeObject).
|
||||
f. Let isAnonymousFunctionDefinition be IsAnonymousFunctionDefinition(Initializer).
|
||||
4. Else,
|
||||
a. Let initializer be empty.
|
||||
b. Let isAnonymousFunctionDeclaration be false.
|
||||
5. Return a Record { [[Name]]: name, [[Initializer]]: initializer, [[IsAnonymousFunctionDefinition]]: isAnonymousFunctionDefinition }.
|
||||
|
||||
MemberExpression : MemberExpression.PrivateIdentifier
|
||||
1. Let baseReference be the result of evaluating MemberExpression.
|
||||
2. Let baseValue be ? GetValue(baseReference).
|
||||
3. Let bv be ? RequireObjectCoercible(baseValue).
|
||||
4. Let fieldNameString be the StringValue of PrivateIdentifier.
|
||||
5. Return MakePrivateReference(bv, fieldNameString).
|
||||
|
||||
MakePrivateReference(baseValue, privateIdentifier)
|
||||
1. Let env be the running execution context's PrivateEnvironment.
|
||||
2. Let privateNameBinding be ? ResolveBinding(privateIdentifier, env).
|
||||
3. Let privateName be GetValue(privateNameBinding).
|
||||
4. Assert: privateName is a Private Name.
|
||||
5. Return a value of type Reference whose base value is baseValue, whose referenced name is privateName, whose strict reference flag is true.
|
||||
|
||||
---*/
|
||||
|
||||
|
||||
class C {
|
||||
static #m() {
|
||||
return 'outer class';
|
||||
}
|
||||
|
||||
static B = class {
|
||||
static methodAccess(o) {
|
||||
return o.#m();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert.sameValue(C.B.methodAccess(C), 'outer class');
|
||||
assert.throws(TypeError, function() {
|
||||
C.B.methodAccess(C.B);
|
||||
}, 'accessed static private method from an arbritary object');
|
Loading…
Reference in New Issue