Fix tests for computed names in class fields - ctor and prototype

This commit is contained in:
Leo Balter 2018-08-21 15:50:39 -04:00
parent 3690d98e27
commit 45a31876e7
7 changed files with 207 additions and 91 deletions

View File

@ -1,30 +1,32 @@
// Copyright (C) 2017 Valerie Young. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: static class fields forbid PropName 'prototype' (no early error -- PropName of ComputedPropertyName not forbidden value)
description: static class fields forbid PropName 'prototype' (no early error -- PropName of ComputedPropertyName)
esid: sec-class-definitions-static-semantics-early-errors
features: [class, class-fields-public]
features: [class, class-static-fields-public]
info: |
Static Semantics: PropName
...
ComputedPropertyName : [ AssignmentExpression ]
Return empty.
14.6.13 Runtime Semantics: ClassDefinitionEvaluation
...
16. Perform MakeConstructor(F, false, proto).
...
// This test file tests the following early error:
Static Semantics: Early Errors
9.2.10 MakeConstructor ( F [ , writablePrototype [ , prototype ] ] )
ClassElement : static FieldDefinition;
It is a Syntax Error if PropName of FieldDefinition is "prototype" or "constructor".
negative:
phase: parse
type: SyntaxError
6. Perform ! DefinePropertyOrThrow(F, "prototype", PropertyDescriptor { [[Value]]: prototype,
[[Writable]]: writablePrototype, [[Enumerable]]: false, [[Configurable]]: false }).
---*/
throw "Test262: This statement should not be evaluated.";
var x = "prototype";
var C = class {
static [x];
};
assert.throws(TypeError, function() {
(0, class {
static [x] = 42;
});
});
assert.throws(TypeError, function() {
(0, class {
static [x];
});
});

View File

@ -17,20 +17,37 @@ info: |
ClassElement : FieldDefinition;
It is a Syntax Error if PropName of FieldDefinition is "constructor".
negative:
phase: parse
type: SyntaxError
DefineField(receiver, fieldRecord)
...
8. If fieldName is a Private Name,
...
9. Else,
a. ...
b. Perform ? CreateDataPropertyOrThrow(receiver, fieldName, initValue).
CreateDataPropertyOrThrow ( O, P, V )
...
3. Let success be ? CreateDataProperty(O, P, V).
4. If success is false, throw a TypeError exception.
...
CreateDataProperty ( O, P, V )
...
3. Let newDesc be the PropertyDescriptor { [[Value]]: V, [[Writable]]: true, [[Enumerable]]: true,
[[Configurable]]: true }.
4. Return ? O.[[DefineOwnProperty]](P, newDesc).
includes: [propertyHelper.js]
---*/
throw "Test262: This statement should not be evaluated.";
var x = "constructor";
class C {
class C1 {
[x];
}
var c = new C();
var c1 = new C1();
assert.sameValue(c.hasOwnProperty("constructor"), true);
assert.sameValue(C.hasOwnProperty("constructor"), false);
assert.sameValue(c1.hasOwnProperty("constructor"), true);
assert.sameValue(C1.hasOwnProperty("constructor"), false);

View File

@ -1,7 +1,7 @@
// Copyright (C) 2017 Valerie Young. All rights reserved.
// Copyright (C) 2017 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: static class fields forbid PropName 'prototype' (no early error -- PropName of ComputedPropertyName not forbidden value)
description: static class fields forbid PropName 'constructor' (no early error -- PropName of ComputedPropertyName not forbidden value)
esid: sec-class-definitions-static-semantics-early-errors
features: [class, class-static-fields-public]
info: |
@ -10,22 +10,71 @@ info: |
ComputedPropertyName : [ AssignmentExpression ]
Return empty.
This test file tests the following early error is only valid for a matching PropName:
// This test file tests the following early error:
Static Semantics: Early Errors
ClassElement : static FieldDefinition;
ClassElement : static FieldDefinition;
It is a Syntax Error if PropName of FieldDefinition is "prototype" or "constructor".
negative:
phase: parse
type: SyntaxError
-- IDK what is calling InitializeClassElements but I guess it's supposed to be called to
-- set the fields
InitializeClassElements(F, proto)
...
6. For each item element in order from elements,
a. If element.[[Kind]] is "field" and element.[[Placement]] is "static" or "prototype",
...
ii. Let receiver be F if element.[[Placement]] is "static", else let receiver be proto.
iii. Perform ? DefineClassElement(receiver, element).
-- DefineClassElement is probably DefineField in the class fields proposal
DefineField(receiver, fieldRecord)
...
8. If fieldName is a Private Name,
...
9. Else,
a. ...
b. Perform ? CreateDataPropertyOrThrow(receiver, fieldName, initValue).
CreateDataPropertyOrThrow ( O, P, V )
...
3. Let success be ? CreateDataProperty(O, P, V).
4. If success is false, throw a TypeError exception.
...
CreateDataProperty ( O, P, V )
...
3. Let newDesc be the PropertyDescriptor { [[Value]]: V, [[Writable]]: true, [[Enumerable]]: true,
[[Configurable]]: true }.
4. Return ? O.[[DefineOwnProperty]](P, newDesc).
includes: [propertyHelper.js]
---*/
throw "Test262: This statement should not be evaluated.";
var x = "constructor";
class C {
var x = 'constructor';
class C1 {
static [x];
}
verifyProperty(C1, 'constructor', {
value: undefined,
configurable: true,
writable: true,
enumerable: true,
});
class C2 {
static [x] = 42;
}
verifyProperty(C2, 'constructor', {
value: 42,
configurable: true,
writable: true,
enumerable: true,
});

View File

@ -1,31 +1,32 @@
// Copyright (C) 2017 Valerie Young. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: static class fields forbid PropName 'prototype' (no early error -- PropName of ComputedPropertyName not forbidden value)
description: static class fields forbid PropName 'prototype' (no early error -- PropName of ComputedPropertyName)
esid: sec-class-definitions-static-semantics-early-errors
features: [class, class-static-fields-public]
info: |
Static Semantics: PropName
...
ComputedPropertyName : [ AssignmentExpression ]
Return empty.
14.6.13 Runtime Semantics: ClassDefinitionEvaluation
...
16. Perform MakeConstructor(F, false, proto).
...
// This test file tests the following early error:
Static Semantics: Early Errors
ClassElement : static FieldDefinition;
It is a Syntax Error if PropName of FieldDefinition is "prototype" or "constructor".
negative:
phase: parse
type: SyntaxError
9.2.10 MakeConstructor ( F [ , writablePrototype [ , prototype ] ] )
6. Perform ! DefinePropertyOrThrow(F, "prototype", PropertyDescriptor { [[Value]]: prototype,
[[Writable]]: writablePrototype, [[Enumerable]]: false, [[Configurable]]: false }).
---*/
throw "Test262: This statement should not be evaluated.";
var x = "prototype";
class C {
static [x];
}
assert.throws(TypeError, function() {
class C {
static [x] = 42;
}
});
assert.throws(TypeError, function() {
class C {
static [x];
}
});

View File

@ -1,30 +1,79 @@
// Copyright (C) 2017 Valerie Young. All rights reserved.
// Copyright (C) 2017 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: static class fields forbid PropName 'prototype' (no early error -- PropName of ComputedPropertyName not forbidden value)
description: static class fields forbid PropName 'constructor' (no early error -- PropName of ComputedPropertyName not forbidden value)
esid: sec-class-definitions-static-semantics-early-errors
features: [class-static-fields-public]
features: [class, class-static-fields-public]
info: |
Static Semantics: PropName
...
ComputedPropertyName : [ AssignmentExpression ]
Return empty.
This test file tests the following early error is only valid for a matching PropName:
// This test file tests the following early error:
Static Semantics: Early Errors
ClassElement : static FieldDefinition;
ClassElement : static FieldDefinition;
It is a Syntax Error if PropName of FieldDefinition is "prototype" or "constructor".
negative:
phase: parse
type: SyntaxError
-- IDK what is calling InitializeClassElements but I guess it's supposed to be called to
-- set the fields
InitializeClassElements(F, proto)
...
6. For each item element in order from elements,
a. If element.[[Kind]] is "field" and element.[[Placement]] is "static" or "prototype",
...
ii. Let receiver be F if element.[[Placement]] is "static", else let receiver be proto.
iii. Perform ? DefineClassElement(receiver, element).
-- DefineClassElement is probably DefineField in the class fields proposal
DefineField(receiver, fieldRecord)
...
8. If fieldName is a Private Name,
...
9. Else,
a. ...
b. Perform ? CreateDataPropertyOrThrow(receiver, fieldName, initValue).
CreateDataPropertyOrThrow ( O, P, V )
...
3. Let success be ? CreateDataProperty(O, P, V).
4. If success is false, throw a TypeError exception.
...
CreateDataProperty ( O, P, V )
...
3. Let newDesc be the PropertyDescriptor { [[Value]]: V, [[Writable]]: true, [[Enumerable]]: true,
[[Configurable]]: true }.
4. Return ? O.[[DefineOwnProperty]](P, newDesc).
includes: [propertyHelper.js]
---*/
throw "Test262: This statement should not be evaluated.";
class C {
static ["constructor"];
class C1 {
static ['constructor'];
}
verifyProperty(C1, 'constructor', {
value: undefined,
configurable: true,
writable: true,
enumerable: true,
});
class C2 {
static ['constructor'] = 42;
}
verifyProperty(C2, 'constructor', {
value: 42,
configurable: true,
writable: true,
enumerable: true,
});

View File

@ -1,30 +1,30 @@
// Copyright (C) 2017 Valerie Young. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: static class fields forbid PropName 'prototype' (no early error -- PropName of ComputedPropertyName not forbidden value)
description: static class fields forbid PropName 'prototype' (no early error -- PropName of ComputedPropertyName)
esid: sec-class-definitions-static-semantics-early-errors
features: [class-static-fields-public]
features: [class, class-static-fields-public]
info: |
Static Semantics: PropName
...
ComputedPropertyName : [ AssignmentExpression ]
Return empty.
14.6.13 Runtime Semantics: ClassDefinitionEvaluation
...
16. Perform MakeConstructor(F, false, proto).
...
// This test file tests the following early error:
Static Semantics: Early Errors
ClassElement : static FieldDefinition;
It is a Syntax Error if PropName of FieldDefinition is "prototype" or "constructor".
negative:
phase: parse
type: SyntaxError
9.2.10 MakeConstructor ( F [ , writablePrototype [ , prototype ] ] )
6. Perform ! DefinePropertyOrThrow(F, "prototype", PropertyDescriptor { [[Value]]: prototype,
[[Writable]]: writablePrototype, [[Enumerable]]: false, [[Configurable]]: false }).
---*/
throw "Test262: This statement should not be evaluated.";
assert.throws(TypeError, function() {
class C {
static ['prototype'] = 42;
}
});
class C {
static ["prototype"];
}
assert.throws(TypeError, function() {
class C {
static ['prototype'];
}
});

View File

@ -62,8 +62,6 @@ var obj3 = {
valueOf: function() { return s3; }
};
class C {
[obj1] = 42;
[obj2] = 43;