Add more tests for class fields

- Add tests for multiple public fields of the same name
- Reorganize fields default templates
- Add more tests for redeclaration of fields
- Remove non used template
- Add tests for computed property names in class fields definitions
- Minor test fixes

Thanks @andresaraujo for helping with the early review
This commit is contained in:
Leo Balter 2017-11-13 17:32:23 -05:00
parent 076ecc38c6
commit 28a2495c3c
No known key found for this signature in database
GPG Key ID: 2C75F319D398E36B
66 changed files with 1200 additions and 30 deletions

View File

@ -0,0 +1,17 @@
// Copyright (C) 2017 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/statements/class/fields-evaluation-error-
name: field definitions in a class declaration
features: [class-fields]
esid: sec-runtime-semantics-classdefinitionevaluation
---*/
function evaluate() {
class C {
/*{ fields }*/
}
}
assert.throws(/*{ error }*/, evaluate);

View File

@ -0,0 +1,17 @@
// Copyright (C) 2017 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/expressions/class/fields-evaluation-error-
name: field definitions in a class expression
features: [class-fields]
esid: sec-runtime-semantics-classdefinitionevaluation
---*/
function evaluate() {
var C = class {
/*{ fields }*/
};
}
assert.throws(/*{ error }*/, evaluate);

View File

@ -0,0 +1,54 @@
// Copyright (C) 2017 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: ReferenceError evaluating a computed property name
info: |
Runtime Semantics: ClassDefinitionEvaluation
...
27. For each ClassElement e in order from elements
a. If IsStatic of me is false, then
i. Let fields be the result of performing ClassElementEvaluation for e with arguments proto and false.
b. Else,
i. Let fields be the result of performing ClassElementEvaluation for e with arguments F and false.
c. If fields is an abrupt completion, then
i. Set the running execution context's LexicalEnvironment to lex.
ii. Set the running execution context's PrivateNameEnvironment to outerPrivateEnvironment.
iii. Return Completion(status).
...
Runtime Semantics: ClassElementEvaluation
ClassElement: static FieldDefinition;
Return ClassFieldDefinitionEvaluation of FieldDefinition with parameter true and object.
ClassElement: FieldDefinition;
Return ClassFieldDefinitionEvaluation of FieldDefinition with parameter false and object.
Runtime Semantics: ClassFieldDefinitionEvaluation
With parameters isStatic and homeObject.
1. Let fieldName be the result of evaluating ClassElementName.
2. ReturnIfAbrupt(fieldName).
...
Runtime Semantics: Evaluation
ComputedPropertyName: [ AssignmentExpression ]
1. Let exprValue be the result of evaluating AssignmentExpression.
2. Let propName be ? GetValue(exprValue).
3. Return ? ToPropertyKey(propName).
template: class-evaluation-error
features: [computed-property-names]
---*/
//- setup
function fn() {
throw new Test262Error();
}
//- fields
[noRef] = fn();
//- error
ReferenceError

View File

@ -0,0 +1,56 @@
// Copyright (C) 2017 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Custom error evaluating a computed property name
info: |
Runtime Semantics: ClassDefinitionEvaluation
...
27. For each ClassElement e in order from elements
a. If IsStatic of me is false, then
i. Let fields be the result of performing ClassElementEvaluation for e with arguments proto and false.
b. Else,
i. Let fields be the result of performing ClassElementEvaluation for e with arguments F and false.
c. If fields is an abrupt completion, then
i. Set the running execution context's LexicalEnvironment to lex.
ii. Set the running execution context's PrivateNameEnvironment to outerPrivateEnvironment.
iii. Return Completion(status).
...
Runtime Semantics: ClassElementEvaluation
ClassElement: static FieldDefinition;
Return ClassFieldDefinitionEvaluation of FieldDefinition with parameter true and object.
ClassElement: FieldDefinition;
Return ClassFieldDefinitionEvaluation of FieldDefinition with parameter false and object.
Runtime Semantics: ClassFieldDefinitionEvaluation
With parameters isStatic and homeObject.
1. Let fieldName be the result of evaluating ClassElementName.
2. ReturnIfAbrupt(fieldName).
...
Runtime Semantics: Evaluation
ComputedPropertyName: [ AssignmentExpression ]
1. Let exprValue be the result of evaluating AssignmentExpression.
2. Let propName be ? GetValue(exprValue).
3. Return ? ToPropertyKey(propName).
template: class-evaluation-error
features: [computed-property-names, Symbol.toPrimitive]
---*/
//- setup
var obj = {
[Symbol.toPrimitive]: function() {
throw new Test262Error();
}
};
//- fields
[obj]
//- error
Test262Error

View File

@ -0,0 +1,55 @@
// Copyright (C) 2017 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Custom error evaluating a computed property name
info: |
Runtime Semantics: ClassDefinitionEvaluation
...
27. For each ClassElement e in order from elements
a. If IsStatic of me is false, then
i. Let fields be the result of performing ClassElementEvaluation for e with arguments proto and false.
b. Else,
i. Let fields be the result of performing ClassElementEvaluation for e with arguments F and false.
c. If fields is an abrupt completion, then
i. Set the running execution context's LexicalEnvironment to lex.
ii. Set the running execution context's PrivateNameEnvironment to outerPrivateEnvironment.
iii. Return Completion(status).
...
Runtime Semantics: ClassElementEvaluation
ClassElement: static FieldDefinition;
Return ClassFieldDefinitionEvaluation of FieldDefinition with parameter true and object.
ClassElement: FieldDefinition;
Return ClassFieldDefinitionEvaluation of FieldDefinition with parameter false and object.
Runtime Semantics: ClassFieldDefinitionEvaluation
With parameters isStatic and homeObject.
1. Let fieldName be the result of evaluating ClassElementName.
2. ReturnIfAbrupt(fieldName).
...
Runtime Semantics: Evaluation
ComputedPropertyName: [ AssignmentExpression ]
1. Let exprValue be the result of evaluating AssignmentExpression.
2. Let propName be ? GetValue(exprValue).
3. Return ? ToPropertyKey(propName).
template: class-evaluation-error
features: [computed-property-names, Symbol.toPrimitive]
---*/
//- setup
var obj = {
[Symbol.toPrimitive]: {}
};
//- fields
[obj] = refErrorIfEvaluated;
//- error
TypeError

View File

@ -0,0 +1,54 @@
// Copyright (C) 2017 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Custom error evaluating a computed property name
info: |
Runtime Semantics: ClassDefinitionEvaluation
...
27. For each ClassElement e in order from elements
a. If IsStatic of me is false, then
i. Let fields be the result of performing ClassElementEvaluation for e with arguments proto and false.
b. Else,
i. Let fields be the result of performing ClassElementEvaluation for e with arguments F and false.
c. If fields is an abrupt completion, then
i. Set the running execution context's LexicalEnvironment to lex.
ii. Set the running execution context's PrivateNameEnvironment to outerPrivateEnvironment.
iii. Return Completion(status).
...
Runtime Semantics: ClassElementEvaluation
ClassElement: static FieldDefinition;
Return ClassFieldDefinitionEvaluation of FieldDefinition with parameter true and object.
ClassElement: FieldDefinition;
Return ClassFieldDefinitionEvaluation of FieldDefinition with parameter false and object.
Runtime Semantics: ClassFieldDefinitionEvaluation
With parameters isStatic and homeObject.
1. Let fieldName be the result of evaluating ClassElementName.
2. ReturnIfAbrupt(fieldName).
...
Runtime Semantics: Evaluation
ComputedPropertyName: [ AssignmentExpression ]
1. Let exprValue be the result of evaluating AssignmentExpression.
2. Let propName be ? GetValue(exprValue).
3. Return ? ToPropertyKey(propName).
template: class-evaluation-error
features: [computed-property-names, Symbol.toPrimitive]
---*/
//- setup
var obj = {
[Symbol.toPrimitive]: 42
};
//- fields
[obj] = refErrorIfEvaluated;
//- error
TypeError

View File

@ -0,0 +1,103 @@
// Copyright (C) 2017 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: ToPrimitive evaluation in the ComputedPropertyName
info: |
Runtime Semantics: ClassDefinitionEvaluation
...
27. For each ClassElement e in order from elements
a. If IsStatic of me is false, then
i. Let fields be the result of performing ClassElementEvaluation for e with arguments proto and false.
b. Else,
i. Let fields be the result of performing ClassElementEvaluation for e with arguments F and false.
c. If fields is an abrupt completion, then
i. Set the running execution context's LexicalEnvironment to lex.
ii. Set the running execution context's PrivateNameEnvironment to outerPrivateEnvironment.
iii. Return Completion(status).
...
Runtime Semantics: ClassElementEvaluation
ClassElement: static FieldDefinition;
Return ClassFieldDefinitionEvaluation of FieldDefinition with parameter true and object.
ClassElement: FieldDefinition;
Return ClassFieldDefinitionEvaluation of FieldDefinition with parameter false and object.
Runtime Semantics: ClassFieldDefinitionEvaluation
With parameters isStatic and homeObject.
1. Let fieldName be the result of evaluating ClassElementName.
2. ReturnIfAbrupt(fieldName).
...
Runtime Semantics: Evaluation
ComputedPropertyName: [ AssignmentExpression ]
1. Let exprValue be the result of evaluating AssignmentExpression.
2. Let propName be ? GetValue(exprValue).
3. Return ? ToPropertyKey(propName).
template: default
features: [computed-property-names, Symbol.toPrimitive, Symbol]
includes: [propertyHelper.js]
---*/
//- setup
var s1 = Symbol();
var s2 = Symbol();
var s3 = Symbol();
var err = function() { throw new Test262Error(); };
var obj1 = {
[Symbol.toPrimitive]: function() { return s1; },
toString: err,
valueOf: err
};
var obj2 = {
toString: function() { return s2; },
valueOf: err
};
var obj3 = {
toString: undefined,
valueOf: function() { return s3; }
};
//- fields
[obj1] = 42;
[obj2] = 43;
[obj3] = 44;
//- assertions
var c = new C();
assert.sameValue(Object.hasOwnProperty.call(C.prototype, s1), false);
assert.sameValue(Object.hasOwnProperty.call(C, s1), false);
verifyProperty(c, s1, {
value: 42,
enumerable: true,
writable: true,
configurable: true
});
assert.sameValue(Object.hasOwnProperty.call(C.prototype, s2), false);
assert.sameValue(Object.hasOwnProperty.call(C, s2), false);
verifyProperty(c, s2, {
value: 43,
enumerable: true,
writable: true,
configurable: true
});
assert.sameValue(Object.hasOwnProperty.call(C.prototype, s3), false);
assert.sameValue(Object.hasOwnProperty.call(C, s3), false);
verifyProperty(c, s3, {
value: 44,
enumerable: true,
writable: true,
configurable: true
});

View File

@ -0,0 +1,100 @@
// Copyright (C) 2017 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: ToPrimitive evaluation in the ComputedPropertyName
info: |
Runtime Semantics: ClassDefinitionEvaluation
...
27. For each ClassElement e in order from elements
a. If IsStatic of me is false, then
i. Let fields be the result of performing ClassElementEvaluation for e with arguments proto and false.
b. Else,
i. Let fields be the result of performing ClassElementEvaluation for e with arguments F and false.
c. If fields is an abrupt completion, then
i. Set the running execution context's LexicalEnvironment to lex.
ii. Set the running execution context's PrivateNameEnvironment to outerPrivateEnvironment.
iii. Return Completion(status).
...
Runtime Semantics: ClassElementEvaluation
ClassElement: static FieldDefinition;
Return ClassFieldDefinitionEvaluation of FieldDefinition with parameter true and object.
ClassElement: FieldDefinition;
Return ClassFieldDefinitionEvaluation of FieldDefinition with parameter false and object.
Runtime Semantics: ClassFieldDefinitionEvaluation
With parameters isStatic and homeObject.
1. Let fieldName be the result of evaluating ClassElementName.
2. ReturnIfAbrupt(fieldName).
...
Runtime Semantics: Evaluation
ComputedPropertyName: [ AssignmentExpression ]
1. Let exprValue be the result of evaluating AssignmentExpression.
2. Let propName be ? GetValue(exprValue).
3. Return ? ToPropertyKey(propName).
template: default
features: [computed-property-names, Symbol.toPrimitive]
includes: [propertyHelper.js]
---*/
//- setup
var err = function() { throw new Test262Error(); };
var obj1 = {
[Symbol.toPrimitive]: function() { return "d"; },
toString: err,
valueOf: err
};
var obj2 = {
toString: function() { return "e"; },
valueOf: err
};
var obj3 = {
toString: undefined,
valueOf: function() { return "f"; }
};
//- fields
[obj1] = 42;
[obj2] = 43;
[obj3] = 44;
//- assertions
var c = new C();
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "d"), false);
assert.sameValue(Object.hasOwnProperty.call(C, "d"), false);
verifyProperty(c, "d", {
value: 42,
enumerable: true,
writable: true,
configurable: true
});
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "e"), false);
assert.sameValue(Object.hasOwnProperty.call(C, "e"), false);
verifyProperty(c, "e", {
value: 43,
enumerable: true,
writable: true,
configurable: true
});
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "f"), false);
assert.sameValue(Object.hasOwnProperty.call(C, "f"), false);
verifyProperty(c, "f", {
value: 44,
enumerable: true,
writable: true,
configurable: true
});

View File

@ -0,0 +1,57 @@
// Copyright (C) 2017 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Custom error evaluating a computed property name
info: |
Runtime Semantics: ClassDefinitionEvaluation
...
27. For each ClassElement e in order from elements
a. If IsStatic of me is false, then
i. Let fields be the result of performing ClassElementEvaluation for e with arguments proto and false.
b. Else,
i. Let fields be the result of performing ClassElementEvaluation for e with arguments F and false.
c. If fields is an abrupt completion, then
i. Set the running execution context's LexicalEnvironment to lex.
ii. Set the running execution context's PrivateNameEnvironment to outerPrivateEnvironment.
iii. Return Completion(status).
...
Runtime Semantics: ClassElementEvaluation
ClassElement: static FieldDefinition;
Return ClassFieldDefinitionEvaluation of FieldDefinition with parameter true and object.
ClassElement: FieldDefinition;
Return ClassFieldDefinitionEvaluation of FieldDefinition with parameter false and object.
Runtime Semantics: ClassFieldDefinitionEvaluation
With parameters isStatic and homeObject.
1. Let fieldName be the result of evaluating ClassElementName.
2. ReturnIfAbrupt(fieldName).
...
Runtime Semantics: Evaluation
ComputedPropertyName: [ AssignmentExpression ]
1. Let exprValue be the result of evaluating AssignmentExpression.
2. Let propName be ? GetValue(exprValue).
3. Return ? ToPropertyKey(propName).
template: class-evaluation-error
features: [computed-property-names]
---*/
//- setup
var obj = {
toString: function() {
throw new Test262Error();
}
};
//- fields
[obj]
//- error
Test262Error

View File

@ -0,0 +1,57 @@
// Copyright (C) 2017 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Custom error evaluating a computed property name
info: |
Runtime Semantics: ClassDefinitionEvaluation
...
27. For each ClassElement e in order from elements
a. If IsStatic of me is false, then
i. Let fields be the result of performing ClassElementEvaluation for e with arguments proto and false.
b. Else,
i. Let fields be the result of performing ClassElementEvaluation for e with arguments F and false.
c. If fields is an abrupt completion, then
i. Set the running execution context's LexicalEnvironment to lex.
ii. Set the running execution context's PrivateNameEnvironment to outerPrivateEnvironment.
iii. Return Completion(status).
...
Runtime Semantics: ClassElementEvaluation
ClassElement: static FieldDefinition;
Return ClassFieldDefinitionEvaluation of FieldDefinition with parameter true and object.
ClassElement: FieldDefinition;
Return ClassFieldDefinitionEvaluation of FieldDefinition with parameter false and object.
Runtime Semantics: ClassFieldDefinitionEvaluation
With parameters isStatic and homeObject.
1. Let fieldName be the result of evaluating ClassElementName.
2. ReturnIfAbrupt(fieldName).
...
Runtime Semantics: Evaluation
ComputedPropertyName: [ AssignmentExpression ]
1. Let exprValue be the result of evaluating AssignmentExpression.
2. Let propName be ? GetValue(exprValue).
3. Return ? ToPropertyKey(propName).
template: class-evaluation-error
features: [computed-property-names]
---*/
//- setup
var obj = {
toString: undefined,
valueOf: function() {
throw new Test262Error();
}
};
//- fields
[obj]
//- error
Test262Error

View File

@ -13,7 +13,7 @@ info: |
ClassElementName:
PropertyName
template: default
template: productions
includes: [propertyHelper.js]
features: [computed-property-names]
---*/

View File

@ -13,7 +13,7 @@ info: |
ClassElementName:
PropertyName
template: default
template: productions
includes: [propertyHelper.js]
features: [Symbol, computed-property-names]
---*/

View File

@ -0,0 +1,29 @@
// Copyright (C) 2017 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: The constructor method is called after the fields are initalized
info: |
[[Construct]] ( argumentsList, newTarget)
8. If kind is "base", then
a. Perform OrdinaryCallBindThis(F, calleeContext, thisArgument).
b. Let result be InitializeInstanceFields(thisArgument, F).
...
...
11. Let result be OrdinaryCallEvaluateBody(F, argumentsList).
...
template: default
---*/
//- setup
var ctor;
//- fields
constructor() {
ctor = this.foo;
}
foo = 42;
//- assertions
var c = new C();
assert.sameValue(ctor, 42);

View File

@ -0,0 +1,15 @@
// Copyright (C) 2017 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/statements/class/fields-
name: field definitions in a class declaration
features: [class-fields]
esid: prod-FieldDefinition
---*/
class C {
/*{ fields }*/
}
/*{ assertions }*/

View File

@ -0,0 +1,15 @@
// Copyright (C) 2017 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/expressions/class/fields-
name: field definitions in a class expression
features: [class-fields]
esid: prod-FieldDefinition
---*/
var C = class {
/*{ fields }*/
}
/*{ assertions }*/

View File

@ -1,16 +0,0 @@
// Copyright (C) 2017 the V8 project authors, 2017 Igalia S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
path: language/statements/class/fields-new-no-sc-line-gen-
name: ASI prevents a following generator method
features: [class-fields, generators]
negative:
type: SyntaxError
phase: early
---*/
class C {
/*{ fields }*/
*m() { return 42; }
}

View File

@ -0,0 +1,32 @@
// Copyright (C) 2017 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Return abrupt completion evaluating the field initializer
info: |
[[Construct]] ( argumentsList, newTarget)
8. If kind is "base", then
a. Perform OrdinaryCallBindThis(F, calleeContext, thisArgument).
b. Let result be InitializeInstanceFields(thisArgument, F).
...
...
11. Let result be OrdinaryCallEvaluateBody(F, argumentsList).
...
template: default
---*/
//- setup
var x = 0;
function fn1() { x += 1; }
function fn2() { throw new Test262Error(); }
//- fields
x = fn1();
y = fn2();
z = fn1();
//- assertions
assert.throws(Test262Error, function() {
new C();
});
assert.sameValue(x, 1);

View File

@ -0,0 +1,45 @@
// Copyright (C) 2017 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: The initializer value is defined after the class evaluation
info: |
[[Construct]] ( argumentsList, newTarget)
8. If kind is "base", then
a. Perform OrdinaryCallBindThis(F, calleeContext, thisArgument).
b. Let result be InitializeInstanceFields(thisArgument, F).
...
...
11. Let result be OrdinaryCallEvaluateBody(F, argumentsList).
...
template: default
features: [computed-property-names]
includes: [propertyHelper.js]
---*/
//- setup
var x = false;
//- fields
[x] = x;
//- assertions
var c1 = new C();
x = true;
var c2 = new C();
verifyProperty(c1, "false", {
value: false,
enumerable: true,
configurable: true,
writable: true,
});
verifyProperty(c2, "false", {
value: true,
enumerable: true,
configurable: true,
writable: true,
});
assert.sameValue(c1.hasOwnProperty("true"), false);
assert.sameValue(c2.hasOwnProperty("true"), false);

View File

@ -0,0 +1,81 @@
// Copyright (C) 2017 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: The initializer value is defined during the class instatiation
info: |
Runtime Semantics: ClassDefinitionEvaluation
27. For each ClassElement e in order from elements
...
d. Append to fieldRecords the elements of fields.
...
33. Let result be InitializeStaticFields(F).
...
[[Construct]] ( argumentsList, newTarget)
8. If kind is "base", then
a. Perform OrdinaryCallBindThis(F, calleeContext, thisArgument).
b. Let result be InitializeInstanceFields(thisArgument, F).
...
...
11. Let result be OrdinaryCallEvaluateBody(F, argumentsList).
...
template: default
features: [computed-property-names]
includes: [propertyHelper.js]
---*/
//- setup
var x = 0;
//- fields
static [x++] = x++;
[x++] = x++;
static [x++] = x++;
[x++] = x++;
//- assertions
var c1 = new C();
var c2 = new C();
verifyProperty(C, "0", {
value: 4,
enumerable: true,
configurable: true,
writable: true,
});
verifyProperty(C, "2", {
value: 5,
enumerable: true,
configurable: true,
writable: true,
});
verifyProperty(c1, "1", {
value: 6,
enumerable: true,
configurable: true,
writable: true,
});
verifyProperty(c1, "3", {
value: 7,
enumerable: true,
configurable: true,
writable: true,
});
verifyProperty(c2, "1", {
value: 8,
enumerable: true,
configurable: true,
writable: true,
});
verifyProperty(c2, "3", {
value: 9,
enumerable: true,
configurable: true,
writable: true,
});

View File

@ -13,7 +13,7 @@ info: |
ClassElementName:
PropertyName
template: default
template: productions
includes: [propertyHelper.js]
---*/

View File

@ -16,7 +16,7 @@ info: |
PrivateName:
#IdentifierName
template: default
template: productions
---*/
//- fields

View File

@ -0,0 +1,52 @@
// Copyright (C) 2017 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Redeclaration of public fields with the same name
info: |
2.13.2 Runtime Semantics: ClassDefinitionEvaluation
...
30. Set the value of F's [[Fields]] internal slot to fieldRecords.
...
2.14 [[Construct]] ( argumentsList, newTarget)
...
8. If kind is "base", then
...
b. Let result be InitializeInstanceFields(thisArgument, F).
...
2.9 InitializeInstanceFields ( O, constructor )
3. Let fieldRecords be the value of constructor's [[Fields]] internal slot.
4. For each item fieldRecord in order from fieldRecords,
a. If fieldRecord.[[static]] is false, then
i. Perform ? DefineField(O, fieldRecord).
template: default
includes: [propertyHelper.js, compareArray.js]
---*/
//- setup
var x = [];
var y = Symbol();
//- fields
[y] = (x.push("a"), "old_value");
[y] = (x.push("b"), "same_value");
[y] = (x.push("c"), "same_value");
//- assertions
var c = new C();
assert.sameValue(Object.hasOwnProperty.call(C.prototype, y), false);
assert.sameValue(Object.hasOwnProperty.call(C, y), false);
verifyProperty(c, y, {
value: "same_value",
enumerable: true,
writable: true,
configurable: true
});
assert(compareArray(x, ["a", "b", "c"]));

View File

@ -0,0 +1,52 @@
// Copyright (C) 2017 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Redeclaration of public fields with the same name
info: |
2.13.2 Runtime Semantics: ClassDefinitionEvaluation
...
30. Set the value of F's [[Fields]] internal slot to fieldRecords.
...
2.14 [[Construct]] ( argumentsList, newTarget)
...
8. If kind is "base", then
...
b. Let result be InitializeInstanceFields(thisArgument, F).
...
2.9 InitializeInstanceFields ( O, constructor )
3. Let fieldRecords be the value of constructor's [[Fields]] internal slot.
4. For each item fieldRecord in order from fieldRecords,
a. If fieldRecord.[[static]] is false, then
i. Perform ? DefineField(O, fieldRecord).
template: default
includes: [propertyHelper.js, compareArray.js]
---*/
//- setup
var x = [];
//- fields
y = (x.push("a"), "old_value");
["y"] = (x.push("b"), "another_value");
"y" = (x.push("c"), "same_value");
y = (x.push("d"), "same_value");
//- assertions
var c = new C();
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "y"), false);
assert.sameValue(Object.hasOwnProperty.call(C, "y"), false);
verifyProperty(c, "y", {
value: "same_value",
enumerable: true,
writable: true,
configurable: true
});
assert(compareArray(x, ["a", "b", "c", "d"]));

View File

@ -0,0 +1,102 @@
// Copyright (C) 2017 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: ToPrimitive evaluation in the ComputedPropertyName
info: |
Runtime Semantics: ClassDefinitionEvaluation
...
27. For each ClassElement e in order from elements
a. If IsStatic of me is false, then
i. Let fields be the result of performing ClassElementEvaluation for e with arguments proto and false.
b. Else,
i. Let fields be the result of performing ClassElementEvaluation for e with arguments F and false.
c. If fields is an abrupt completion, then
i. Set the running execution context's LexicalEnvironment to lex.
ii. Set the running execution context's PrivateNameEnvironment to outerPrivateEnvironment.
iii. Return Completion(status).
...
Runtime Semantics: ClassElementEvaluation
ClassElement: static FieldDefinition;
Return ClassFieldDefinitionEvaluation of FieldDefinition with parameter true and object.
ClassElement: FieldDefinition;
Return ClassFieldDefinitionEvaluation of FieldDefinition with parameter false and object.
Runtime Semantics: ClassFieldDefinitionEvaluation
With parameters isStatic and homeObject.
1. Let fieldName be the result of evaluating ClassElementName.
2. ReturnIfAbrupt(fieldName).
...
Runtime Semantics: Evaluation
ComputedPropertyName: [ AssignmentExpression ]
1. Let exprValue be the result of evaluating AssignmentExpression.
2. Let propName be ? GetValue(exprValue).
3. Return ? ToPropertyKey(propName).
template: default
features: [computed-property-names, Symbol.toPrimitive, Symbol]
includes: [propertyHelper.js]
---*/
//- setup
var s1 = Symbol();
var s2 = Symbol();
var s3 = Symbol();
var err = function() { throw new Test262Error(); };
var obj1 = {
[Symbol.toPrimitive]: function() { return s1; },
toString: err,
valueOf: err
};
var obj2 = {
toString: function() { return s2; },
valueOf: err
};
var obj3 = {
toString: undefined,
valueOf: function() { return s3; }
};
//- fields
static [obj1] = 42;
static [obj2] = 43;
static [obj3] = 44;
//- assertions
assert.sameValue(Object.hasOwnProperty.call(C.prototype, s1), false);
assert.sameValue(Object.hasOwnProperty.call(C.prototype, s2), false);
assert.sameValue(Object.hasOwnProperty.call(C.prototype, s3), false);
verifyProperty(C, s1, {
value: 42,
enumerable: true,
writable: true,
configurable: true
});
verifyProperty(C, s2, {
value: 43,
enumerable: true,
writable: true,
configurable: true
});
verifyProperty(C, s3, {
value: 44,
enumerable: true,
writable: true,
configurable: true
});
var c = new C();
assert.sameValue(Object.hasOwnProperty.call(c, s1), false);
assert.sameValue(Object.hasOwnProperty.call(c, s2), false);
assert.sameValue(Object.hasOwnProperty.call(c, s3), false);

View File

@ -0,0 +1,99 @@
// Copyright (C) 2017 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: ToPrimitive evaluation in the ComputedPropertyName
info: |
Runtime Semantics: ClassDefinitionEvaluation
...
27. For each ClassElement e in order from elements
a. If IsStatic of me is false, then
i. Let fields be the result of performing ClassElementEvaluation for e with arguments proto and false.
b. Else,
i. Let fields be the result of performing ClassElementEvaluation for e with arguments F and false.
c. If fields is an abrupt completion, then
i. Set the running execution context's LexicalEnvironment to lex.
ii. Set the running execution context's PrivateNameEnvironment to outerPrivateEnvironment.
iii. Return Completion(status).
...
Runtime Semantics: ClassElementEvaluation
ClassElement: static FieldDefinition;
Return ClassFieldDefinitionEvaluation of FieldDefinition with parameter true and object.
ClassElement: FieldDefinition;
Return ClassFieldDefinitionEvaluation of FieldDefinition with parameter false and object.
Runtime Semantics: ClassFieldDefinitionEvaluation
With parameters isStatic and homeObject.
1. Let fieldName be the result of evaluating ClassElementName.
2. ReturnIfAbrupt(fieldName).
...
Runtime Semantics: Evaluation
ComputedPropertyName: [ AssignmentExpression ]
1. Let exprValue be the result of evaluating AssignmentExpression.
2. Let propName be ? GetValue(exprValue).
3. Return ? ToPropertyKey(propName).
template: default
features: [computed-property-names, Symbol.toPrimitive]
includes: [propertyHelper.js]
---*/
//- setup
var err = function() { throw new Test262Error(); };
var obj1 = {
[Symbol.toPrimitive]: function() { return "d"; },
toString: err,
valueOf: err
};
var obj2 = {
toString: function() { return "e"; },
valueOf: err
};
var obj3 = {
toString: undefined,
valueOf: function() { return "f"; }
};
//- fields
static [obj1] = 42;
static [obj2] = 43;
static [obj3] = 44;
//- assertions
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "d"), false);
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "e"), false);
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "f"), false);
verifyProperty(C, "d", {
value: 42,
enumerable: true,
writable: true,
configurable: true
});
verifyProperty(C, "e", {
value: 43,
enumerable: true,
writable: true,
configurable: true
});
verifyProperty(C, "f", {
value: 44,
enumerable: true,
writable: true,
configurable: true
});
var c = new C();
assert.sameValue(Object.hasOwnProperty.call(c, "d"), false);
assert.sameValue(Object.hasOwnProperty.call(c, "e"), false);
assert.sameValue(Object.hasOwnProperty.call(c, "f"), false);

View File

@ -14,7 +14,7 @@ info: |
ClassElementName:
PropertyName
template: default
template: productions
includes: [propertyHelper.js]
features: [computed-property-names]
---*/

View File

@ -13,7 +13,7 @@ info: |
ClassElementName:
PropertyName
template: default
template: productions
includes: [propertyHelper.js]
features: [Symbol, computed-property-names]
---*/
@ -23,12 +23,12 @@ var x = Symbol();
var y = Symbol();
//- fields
[x]; [y] = 42
static [x]; static [y] = 42
//- assertions
assert.sameValue(Object.hasOwnProperty.call(C.prototype, x), false);
assert.sameValue(Object.hasOwnProperty.call(C, x), false);
assert.sameValue(Object.hasOwnProperty.call(c, x), false);
verifyProperty(c, x, {
verifyProperty(C, x, {
value: undefined,
enumerable: true,
writable: true,
@ -36,9 +36,9 @@ verifyProperty(c, x, {
});
assert.sameValue(Object.hasOwnProperty.call(C.prototype, y), false);
assert.sameValue(Object.hasOwnProperty.call(C, y), false);
assert.sameValue(Object.hasOwnProperty.call(c, y), false);
verifyProperty(c, y, {
verifyProperty(C, y, {
value: 42,
enumerable: true,
writable: true,

View File

@ -13,7 +13,7 @@ info: |
ClassElementName:
PropertyName
template: default
template: productions
includes: [propertyHelper.js]
---*/

View File

@ -16,7 +16,7 @@ info: |
PrivateName:
#IdentifierName
template: default
template: productions
---*/
//- fields

View File

@ -0,0 +1,47 @@
// Copyright (C) 2017 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Redeclaration of public static fields with the same name
info: |
2.13.2 Runtime Semantics: ClassDefinitionEvaluation
...
30. Set the value of F's [[Fields]] internal slot to fieldRecords.
...
33. Let result be InitializeStaticFields(F).
InitializeStaticFields(F)
3. Let fieldRecords be the value of F's [[Fields]] internal slot.
4. For each item fieldRecord in order from fieldRecords,
a. If fieldRecord.[[static]] is true, then
i. Perform ? DefineField(F, fieldRecord).
template: default
includes: [propertyHelper.js, compareArray.js]
---*/
//- setup
var x = [];
var y = Symbol();
//- fields
static [y] = (x.push("a"), "old_value");
static [y] = (x.push("b"), "same_value");
static [y] = (x.push("c"), "same_value");
//- assertions
assert.sameValue(Object.hasOwnProperty.call(C.prototype, y), false);
verifyProperty(C, y, {
value: "same_value",
enumerable: true,
writable: true,
configurable: true
});
assert(compareArray(x, ["a", "b", "c"]));
var c = new C();
assert.sameValue(Object.hasOwnProperty.call(c, y), false);
assert(compareArray(x, ["a", "b", "c"]), "static fields are not redefined on class instatiation");

View File

@ -0,0 +1,47 @@
// Copyright (C) 2017 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
desc: Redeclaration of public static fields with the same name
info: |
2.13.2 Runtime Semantics: ClassDefinitionEvaluation
...
30. Set the value of F's [[Fields]] internal slot to fieldRecords.
...
33. Let result be InitializeStaticFields(F).
InitializeStaticFields(F)
3. Let fieldRecords be the value of F's [[Fields]] internal slot.
4. For each item fieldRecord in order from fieldRecords,
a. If fieldRecord.[[static]] is true, then
i. Perform ? DefineField(F, fieldRecord).
template: default
includes: [propertyHelper.js, compareArray.js]
---*/
//- setup
var x = [];
//- fields
static y = (x.push("a"), "old_value");
static ["y"] = (x.push("b"), "another_value");
static "y" = (x.push("c"), "same_value");
static y = (x.push("d"), "same_value");
//- assertions
assert.sameValue(Object.hasOwnProperty.call(C.prototype, "y"), false);
verifyProperty(C, "y", {
value: "same_value",
enumerable: true,
writable: true,
configurable: true
});
assert(compareArray(x, ["a", "b", "c", "d"]));
var c = new C();
assert.sameValue(Object.hasOwnProperty.call(c, "y"), false);
assert(compareArray(x, ["a", "b", "c", "d"]), "static fields are not redefined on class instatiation");

View File

@ -13,7 +13,7 @@ info: |
ClassElementName:
PropertyName
template: default
template: productions
includes: [propertyHelper.js]
---*/