mirror of https://github.com/tc39/test262.git
Adding tests to verify if '.name' of static members are configured properly (#2293)
This commit is contained in:
parent
f947f93887
commit
65fd8d30a3
|
@ -0,0 +1,67 @@
|
|||
// Copyright (C) 2019 Caio Lima (Igalia SL). All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
desc: Private static methods have name property properly configured
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
ClassElement : MethodDefinition
|
||||
1. Return ClassElementEvaluation of MethodDefinition with arguments ! Get(homeObject, "prototype"),enumerable, and "prototype".
|
||||
|
||||
ClassElement : static MethodDefinition
|
||||
1. Return ClassElementEvaluation of MethodDefinition with arguments homeObject, enumerable and "static".
|
||||
|
||||
MethodDefinition : ClassElementName( UniqueFormalParameters ) { FunctionBody }
|
||||
1. Let methodDef be DefineMethod of MethodDefinition with argument homeObject.
|
||||
2. ReturnIfAbrupt(methodDef).
|
||||
3. Perform ? DefineOrdinaryMethod(methodDef.[[Key]], homeObject, methodDef.[[Closure]], _enumerable).
|
||||
|
||||
ClassElement : MethodDefinition
|
||||
ClassElement : static MethodDefinition
|
||||
1. Perform ? PropertyDefinitionEvaluation with parameters object and enumerable.
|
||||
2. Return empty.
|
||||
|
||||
MethodDefinition : ClassElementName (UniqueFormalParameters) { FunctionBody }
|
||||
1. Let propKey be the result of evaluating ClassElementName.
|
||||
...
|
||||
8. Let closure be FunctionCreate(kind, UniqueFormalParameters, FunctionBody, scope, privateScope, strict, prototype).
|
||||
9. Perform MakeMethod(closure, object).
|
||||
10. Return the Record{[[Key]]: propKey, [[Closure]]: closure}.
|
||||
|
||||
ClassElementName : PrivateIdentifier
|
||||
1. Let bindingName be StringValue of PrivateIdentifier.
|
||||
...
|
||||
5. If scopeEnvRec's binding for bindingName is uninitialized,
|
||||
a. Let field be NewPrivateName(bindingName).
|
||||
b. Perform ! scopeEnvRec.InitializeBinding(bindingName, field).
|
||||
6. Otherwise,
|
||||
a. Let field be scopeEnvRec.GetBindingValue(bindingName).
|
||||
7. Assert: field.[[Description]] is bindingName.
|
||||
8. Return field.
|
||||
|
||||
DefineOrdinaryMethod(key, homeObject, closure, enumerable)
|
||||
1. Perform SetFunctionName(closure, key).
|
||||
2. If key is a Private Name,
|
||||
a. Assert: key does not have a [[Kind]] field.
|
||||
b. Set key.[[Kind]] to "method".
|
||||
c. Set key.[[Value]] to closure.
|
||||
d. Set key.[[Brand]] to homeObject.
|
||||
3. Else,
|
||||
a. Let desc be the PropertyDescriptor{[[Value]]: closure, [[Writable]]: true, [[Enumerable]]: enumerable, [[Configurable]]: true}.
|
||||
b. Perform ? DefinePropertyOrThrow(homeObject, key, desc).
|
||||
template: default
|
||||
features: [class-static-methods-private]
|
||||
---*/
|
||||
|
||||
//- elements
|
||||
static #method() {
|
||||
return 'Test262';
|
||||
};
|
||||
|
||||
static getPrivateMethod() {
|
||||
return this.#method;
|
||||
}
|
||||
|
||||
//- assertions
|
||||
assert.sameValue(C.getPrivateMethod().name, "#method");
|
|
@ -0,0 +1,66 @@
|
|||
// Copyright (C) 2019 Caio Lima (Igalia SL). All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
desc: Anonymous function receives the name of static fields
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
ClassElement :
|
||||
...
|
||||
static FieldDefinition ;
|
||||
|
||||
FieldDefinition :
|
||||
ClassElementName Initializer_opt
|
||||
|
||||
ClassDefinitionEvaluation:
|
||||
...
|
||||
|
||||
27. Let staticFields be a new empty List.
|
||||
28. For each ClassElement e in order from elements,
|
||||
a. If IsStatic of e is false, then
|
||||
...
|
||||
b. Else,
|
||||
i. Let field be the result of performing PropertyDefinitionEvaluation for m ClassElementEvaluation for e with arguments F and false.
|
||||
c. If field is an abrupt completion, then
|
||||
...
|
||||
d. If field is not empty,
|
||||
i. If IsStatic of e is false, append field to instanceFields.
|
||||
ii. Otherwise, append field to staticFields.
|
||||
|
||||
34. For each item fieldRecord in order from staticFields,
|
||||
a. Perform ? DefineField(F, field).
|
||||
...
|
||||
|
||||
DefineField(receiver, fieldRecord)
|
||||
1. Assert: Type(receiver) is Object.
|
||||
2. Assert: fieldRecord is a Record as created by ClassFieldDefinitionEvaluation.
|
||||
3. Let name be fieldRecord.[[Name]].
|
||||
4. Let initializer be fieldRecord.[[Initializer]].
|
||||
5. If initializer is not empty, then
|
||||
a. Let initValue be ? Call(initializer, receiver).
|
||||
6. Else, let initValue be undefined.
|
||||
7. If fieldRecord.[[IsAnonymousFunctionDefinition]] is true, then
|
||||
a. Let hasNameProperty be ? HasOwnProperty(initValue, "name").
|
||||
b. If hasNameProperty is false, perform SetFunctionName(initValue, fieldName).
|
||||
8. If fieldName is a Private Name,
|
||||
a. Perform ? PrivateFieldAdd(fieldName, receiver, initValue).
|
||||
9. Else,
|
||||
a. Assert: IsPropertyKey(fieldName) is true.
|
||||
b. Perform ? CreateDataPropertyOrThrow(receiver, fieldName, initValue).
|
||||
10. Return.
|
||||
template: default
|
||||
features: [class-static-fields-private, class-static-fields-public]
|
||||
---*/
|
||||
|
||||
//- elements
|
||||
static #field = () => 'Test262';
|
||||
static field = function() { return 42; };
|
||||
|
||||
static accessPrivateField() {
|
||||
return this.#field;
|
||||
}
|
||||
|
||||
//- assertions
|
||||
assert.sameValue(C.accessPrivateField().name, "#field");
|
||||
assert.sameValue(C.field.name, "field");
|
|
@ -0,0 +1,71 @@
|
|||
// This file was procedurally generated from the following sources:
|
||||
// - src/class-elements/private-static-method-name.case
|
||||
// - src/class-elements/default/cls-expr.template
|
||||
/*---
|
||||
description: Private static methods have name property properly configured (field definitions in a class expression)
|
||||
esid: prod-FieldDefinition
|
||||
features: [class-static-methods-private, class]
|
||||
flags: [generated]
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
ClassElement : MethodDefinition
|
||||
1. Return ClassElementEvaluation of MethodDefinition with arguments ! Get(homeObject, "prototype"),enumerable, and "prototype".
|
||||
|
||||
ClassElement : static MethodDefinition
|
||||
1. Return ClassElementEvaluation of MethodDefinition with arguments homeObject, enumerable and "static".
|
||||
|
||||
MethodDefinition : ClassElementName( UniqueFormalParameters ) { FunctionBody }
|
||||
1. Let methodDef be DefineMethod of MethodDefinition with argument homeObject.
|
||||
2. ReturnIfAbrupt(methodDef).
|
||||
3. Perform ? DefineOrdinaryMethod(methodDef.[[Key]], homeObject, methodDef.[[Closure]], _enumerable).
|
||||
|
||||
ClassElement : MethodDefinition
|
||||
ClassElement : static MethodDefinition
|
||||
1. Perform ? PropertyDefinitionEvaluation with parameters object and enumerable.
|
||||
2. Return empty.
|
||||
|
||||
MethodDefinition : ClassElementName (UniqueFormalParameters) { FunctionBody }
|
||||
1. Let propKey be the result of evaluating ClassElementName.
|
||||
...
|
||||
8. Let closure be FunctionCreate(kind, UniqueFormalParameters, FunctionBody, scope, privateScope, strict, prototype).
|
||||
9. Perform MakeMethod(closure, object).
|
||||
10. Return the Record{[[Key]]: propKey, [[Closure]]: closure}.
|
||||
|
||||
ClassElementName : PrivateIdentifier
|
||||
1. Let bindingName be StringValue of PrivateIdentifier.
|
||||
...
|
||||
5. If scopeEnvRec's binding for bindingName is uninitialized,
|
||||
a. Let field be NewPrivateName(bindingName).
|
||||
b. Perform ! scopeEnvRec.InitializeBinding(bindingName, field).
|
||||
6. Otherwise,
|
||||
a. Let field be scopeEnvRec.GetBindingValue(bindingName).
|
||||
7. Assert: field.[[Description]] is bindingName.
|
||||
8. Return field.
|
||||
|
||||
DefineOrdinaryMethod(key, homeObject, closure, enumerable)
|
||||
1. Perform SetFunctionName(closure, key).
|
||||
2. If key is a Private Name,
|
||||
a. Assert: key does not have a [[Kind]] field.
|
||||
b. Set key.[[Kind]] to "method".
|
||||
c. Set key.[[Value]] to closure.
|
||||
d. Set key.[[Brand]] to homeObject.
|
||||
3. Else,
|
||||
a. Let desc be the PropertyDescriptor{[[Value]]: closure, [[Writable]]: true, [[Enumerable]]: enumerable, [[Configurable]]: true}.
|
||||
b. Perform ? DefinePropertyOrThrow(homeObject, key, desc).
|
||||
|
||||
---*/
|
||||
|
||||
|
||||
var C = class {
|
||||
static #method() {
|
||||
return 'Test262';
|
||||
};
|
||||
|
||||
static getPrivateMethod() {
|
||||
return this.#method;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
assert.sameValue(C.getPrivateMethod().name, "#method");
|
|
@ -0,0 +1,70 @@
|
|||
// This file was procedurally generated from the following sources:
|
||||
// - src/class-elements/static-field-anonymous-function-name.case
|
||||
// - src/class-elements/default/cls-expr.template
|
||||
/*---
|
||||
description: Anonymous function receives the name of static fields (field definitions in a class expression)
|
||||
esid: prod-FieldDefinition
|
||||
features: [class-static-fields-private, class-static-fields-public, class]
|
||||
flags: [generated]
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
ClassElement :
|
||||
...
|
||||
static FieldDefinition ;
|
||||
|
||||
FieldDefinition :
|
||||
ClassElementName Initializer_opt
|
||||
|
||||
ClassDefinitionEvaluation:
|
||||
...
|
||||
|
||||
27. Let staticFields be a new empty List.
|
||||
28. For each ClassElement e in order from elements,
|
||||
a. If IsStatic of e is false, then
|
||||
...
|
||||
b. Else,
|
||||
i. Let field be the result of performing PropertyDefinitionEvaluation for m ClassElementEvaluation for e with arguments F and false.
|
||||
c. If field is an abrupt completion, then
|
||||
...
|
||||
d. If field is not empty,
|
||||
i. If IsStatic of e is false, append field to instanceFields.
|
||||
ii. Otherwise, append field to staticFields.
|
||||
|
||||
34. For each item fieldRecord in order from staticFields,
|
||||
a. Perform ? DefineField(F, field).
|
||||
...
|
||||
|
||||
DefineField(receiver, fieldRecord)
|
||||
1. Assert: Type(receiver) is Object.
|
||||
2. Assert: fieldRecord is a Record as created by ClassFieldDefinitionEvaluation.
|
||||
3. Let name be fieldRecord.[[Name]].
|
||||
4. Let initializer be fieldRecord.[[Initializer]].
|
||||
5. If initializer is not empty, then
|
||||
a. Let initValue be ? Call(initializer, receiver).
|
||||
6. Else, let initValue be undefined.
|
||||
7. If fieldRecord.[[IsAnonymousFunctionDefinition]] is true, then
|
||||
a. Let hasNameProperty be ? HasOwnProperty(initValue, "name").
|
||||
b. If hasNameProperty is false, perform SetFunctionName(initValue, fieldName).
|
||||
8. If fieldName is a Private Name,
|
||||
a. Perform ? PrivateFieldAdd(fieldName, receiver, initValue).
|
||||
9. Else,
|
||||
a. Assert: IsPropertyKey(fieldName) is true.
|
||||
b. Perform ? CreateDataPropertyOrThrow(receiver, fieldName, initValue).
|
||||
10. Return.
|
||||
|
||||
---*/
|
||||
|
||||
|
||||
var C = class {
|
||||
static #field = () => 'Test262';
|
||||
static field = function() { return 42; };
|
||||
|
||||
static accessPrivateField() {
|
||||
return this.#field;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
assert.sameValue(C.accessPrivateField().name, "#field");
|
||||
assert.sameValue(C.field.name, "field");
|
|
@ -0,0 +1,71 @@
|
|||
// This file was procedurally generated from the following sources:
|
||||
// - src/class-elements/private-static-method-name.case
|
||||
// - src/class-elements/default/cls-decl.template
|
||||
/*---
|
||||
description: Private static methods have name property properly configured (field definitions in a class declaration)
|
||||
esid: prod-FieldDefinition
|
||||
features: [class-static-methods-private, class]
|
||||
flags: [generated]
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
ClassElement : MethodDefinition
|
||||
1. Return ClassElementEvaluation of MethodDefinition with arguments ! Get(homeObject, "prototype"),enumerable, and "prototype".
|
||||
|
||||
ClassElement : static MethodDefinition
|
||||
1. Return ClassElementEvaluation of MethodDefinition with arguments homeObject, enumerable and "static".
|
||||
|
||||
MethodDefinition : ClassElementName( UniqueFormalParameters ) { FunctionBody }
|
||||
1. Let methodDef be DefineMethod of MethodDefinition with argument homeObject.
|
||||
2. ReturnIfAbrupt(methodDef).
|
||||
3. Perform ? DefineOrdinaryMethod(methodDef.[[Key]], homeObject, methodDef.[[Closure]], _enumerable).
|
||||
|
||||
ClassElement : MethodDefinition
|
||||
ClassElement : static MethodDefinition
|
||||
1. Perform ? PropertyDefinitionEvaluation with parameters object and enumerable.
|
||||
2. Return empty.
|
||||
|
||||
MethodDefinition : ClassElementName (UniqueFormalParameters) { FunctionBody }
|
||||
1. Let propKey be the result of evaluating ClassElementName.
|
||||
...
|
||||
8. Let closure be FunctionCreate(kind, UniqueFormalParameters, FunctionBody, scope, privateScope, strict, prototype).
|
||||
9. Perform MakeMethod(closure, object).
|
||||
10. Return the Record{[[Key]]: propKey, [[Closure]]: closure}.
|
||||
|
||||
ClassElementName : PrivateIdentifier
|
||||
1. Let bindingName be StringValue of PrivateIdentifier.
|
||||
...
|
||||
5. If scopeEnvRec's binding for bindingName is uninitialized,
|
||||
a. Let field be NewPrivateName(bindingName).
|
||||
b. Perform ! scopeEnvRec.InitializeBinding(bindingName, field).
|
||||
6. Otherwise,
|
||||
a. Let field be scopeEnvRec.GetBindingValue(bindingName).
|
||||
7. Assert: field.[[Description]] is bindingName.
|
||||
8. Return field.
|
||||
|
||||
DefineOrdinaryMethod(key, homeObject, closure, enumerable)
|
||||
1. Perform SetFunctionName(closure, key).
|
||||
2. If key is a Private Name,
|
||||
a. Assert: key does not have a [[Kind]] field.
|
||||
b. Set key.[[Kind]] to "method".
|
||||
c. Set key.[[Value]] to closure.
|
||||
d. Set key.[[Brand]] to homeObject.
|
||||
3. Else,
|
||||
a. Let desc be the PropertyDescriptor{[[Value]]: closure, [[Writable]]: true, [[Enumerable]]: enumerable, [[Configurable]]: true}.
|
||||
b. Perform ? DefinePropertyOrThrow(homeObject, key, desc).
|
||||
|
||||
---*/
|
||||
|
||||
|
||||
class C {
|
||||
static #method() {
|
||||
return 'Test262';
|
||||
};
|
||||
|
||||
static getPrivateMethod() {
|
||||
return this.#method;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
assert.sameValue(C.getPrivateMethod().name, "#method");
|
|
@ -0,0 +1,70 @@
|
|||
// This file was procedurally generated from the following sources:
|
||||
// - src/class-elements/static-field-anonymous-function-name.case
|
||||
// - src/class-elements/default/cls-decl.template
|
||||
/*---
|
||||
description: Anonymous function receives the name of static fields (field definitions in a class declaration)
|
||||
esid: prod-FieldDefinition
|
||||
features: [class-static-fields-private, class-static-fields-public, class]
|
||||
flags: [generated]
|
||||
info: |
|
||||
Updated Productions
|
||||
|
||||
ClassElement :
|
||||
...
|
||||
static FieldDefinition ;
|
||||
|
||||
FieldDefinition :
|
||||
ClassElementName Initializer_opt
|
||||
|
||||
ClassDefinitionEvaluation:
|
||||
...
|
||||
|
||||
27. Let staticFields be a new empty List.
|
||||
28. For each ClassElement e in order from elements,
|
||||
a. If IsStatic of e is false, then
|
||||
...
|
||||
b. Else,
|
||||
i. Let field be the result of performing PropertyDefinitionEvaluation for m ClassElementEvaluation for e with arguments F and false.
|
||||
c. If field is an abrupt completion, then
|
||||
...
|
||||
d. If field is not empty,
|
||||
i. If IsStatic of e is false, append field to instanceFields.
|
||||
ii. Otherwise, append field to staticFields.
|
||||
|
||||
34. For each item fieldRecord in order from staticFields,
|
||||
a. Perform ? DefineField(F, field).
|
||||
...
|
||||
|
||||
DefineField(receiver, fieldRecord)
|
||||
1. Assert: Type(receiver) is Object.
|
||||
2. Assert: fieldRecord is a Record as created by ClassFieldDefinitionEvaluation.
|
||||
3. Let name be fieldRecord.[[Name]].
|
||||
4. Let initializer be fieldRecord.[[Initializer]].
|
||||
5. If initializer is not empty, then
|
||||
a. Let initValue be ? Call(initializer, receiver).
|
||||
6. Else, let initValue be undefined.
|
||||
7. If fieldRecord.[[IsAnonymousFunctionDefinition]] is true, then
|
||||
a. Let hasNameProperty be ? HasOwnProperty(initValue, "name").
|
||||
b. If hasNameProperty is false, perform SetFunctionName(initValue, fieldName).
|
||||
8. If fieldName is a Private Name,
|
||||
a. Perform ? PrivateFieldAdd(fieldName, receiver, initValue).
|
||||
9. Else,
|
||||
a. Assert: IsPropertyKey(fieldName) is true.
|
||||
b. Perform ? CreateDataPropertyOrThrow(receiver, fieldName, initValue).
|
||||
10. Return.
|
||||
|
||||
---*/
|
||||
|
||||
|
||||
class C {
|
||||
static #field = () => 'Test262';
|
||||
static field = function() { return 42; };
|
||||
|
||||
static accessPrivateField() {
|
||||
return this.#field;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
assert.sameValue(C.accessPrivateField().name, "#field");
|
||||
assert.sameValue(C.field.name, "field");
|
Loading…
Reference in New Issue