Adding case to verify private methods length proeprty

This commit is contained in:
Caio Lima 2019-08-30 13:31:45 -03:00
parent b63cdfd4f4
commit 5848f4f39d
4 changed files with 184 additions and 0 deletions

View File

@ -0,0 +1,42 @@
// 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 in field initilizer have length properly set
info: |
Updated Productions
FieldDefinition :
ClassElementName Initializer_opt
InitializeInstanceFields ( O, constructor )
1. Assert: Type ( O ) is Object.
2. Assert: constructor is an ECMAScript function object.
3. Let fields be the value of constructor.[[Fields]].
4. For each item fieldRecord in order from fields,
a. Perform ? DefineField(O, fieldRecord).
5. Return.
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).
...
template: default
features: [class-static-fields-private, class-static-fields-public]
---*/
//- elements
field = function() {};
#field = (a, b, c, d) => undefined;
accessPrivateField() {
return this.#field;
}
//- assertions
let c = new C();
assert.sameValue(c.accessPrivateField().length, 4);
assert.sameValue(c.field.length, 0);

View File

@ -0,0 +1,43 @@
// 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 methods have length 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 }
...
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}.
template: default
features: [class-methods-private]
---*/
//- elements
#method(a) {};
getPrivateMethod() {
return this.#method;
}
//- assertions
let c = new C();
assert.sameValue(c.getPrivateMethod().length, 1);

View File

@ -0,0 +1,42 @@
// 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 length 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 }
...
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}.
template: default
features: [class-static-methods-private]
---*/
//- elements
static #method(a, b, c) {};
static getPrivateMethod() {
return this.#method;
}
//- assertions
assert.sameValue(C.getPrivateMethod().length, 3);

View File

@ -0,0 +1,57 @@
// 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 in field initilizer have length properly set
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).
...
template: default
features: [class-static-fields-private, class-static-fields-public]
---*/
//- elements
static #field = (a, b) => undefined;
static field = function() {};
static accessPrivateField() {
return this.#field;
}
//- assertions
assert.sameValue(C.accessPrivateField().length, 2);
assert.sameValue(C.field.length, 0);