mirror of
https://github.com/tc39/test262.git
synced 2025-07-14 09:34:37 +02:00
Fix tests for computed names in class fields - ctor and prototype
This commit is contained in:
parent
3690d98e27
commit
45a31876e7
@ -1,30 +1,32 @@
|
|||||||
// Copyright (C) 2017 Valerie Young. All rights reserved.
|
// Copyright (C) 2017 Valerie Young. All rights reserved.
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
// 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
|
esid: sec-class-definitions-static-semantics-early-errors
|
||||||
features: [class, class-fields-public]
|
features: [class, class-static-fields-public]
|
||||||
info: |
|
info: |
|
||||||
Static Semantics: PropName
|
14.6.13 Runtime Semantics: ClassDefinitionEvaluation
|
||||||
|
|
||||||
|
...
|
||||||
|
16. Perform MakeConstructor(F, false, proto).
|
||||||
...
|
...
|
||||||
ComputedPropertyName : [ AssignmentExpression ]
|
|
||||||
Return empty.
|
|
||||||
|
|
||||||
|
9.2.10 MakeConstructor ( F [ , writablePrototype [ , prototype ] ] )
|
||||||
|
|
||||||
// This test file tests the following early error:
|
6. Perform ! DefinePropertyOrThrow(F, "prototype", PropertyDescriptor { [[Value]]: prototype,
|
||||||
Static Semantics: Early Errors
|
[[Writable]]: writablePrototype, [[Enumerable]]: false, [[Configurable]]: false }).
|
||||||
|
|
||||||
ClassElement : static FieldDefinition;
|
|
||||||
It is a Syntax Error if PropName of FieldDefinition is "prototype" or "constructor".
|
|
||||||
|
|
||||||
negative:
|
|
||||||
phase: parse
|
|
||||||
type: SyntaxError
|
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
throw "Test262: This statement should not be evaluated.";
|
|
||||||
|
|
||||||
var x = "prototype";
|
var x = "prototype";
|
||||||
var C = class {
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
(0, class {
|
||||||
|
static [x] = 42;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
(0, class {
|
||||||
static [x];
|
static [x];
|
||||||
};
|
});
|
||||||
|
});
|
||||||
|
@ -17,20 +17,37 @@ info: |
|
|||||||
ClassElement : FieldDefinition;
|
ClassElement : FieldDefinition;
|
||||||
It is a Syntax Error if PropName of FieldDefinition is "constructor".
|
It is a Syntax Error if PropName of FieldDefinition is "constructor".
|
||||||
|
|
||||||
negative:
|
DefineField(receiver, fieldRecord)
|
||||||
phase: parse
|
|
||||||
type: SyntaxError
|
|
||||||
|
|
||||||
|
...
|
||||||
|
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";
|
var x = "constructor";
|
||||||
class C {
|
class C1 {
|
||||||
[x];
|
[x];
|
||||||
}
|
}
|
||||||
|
|
||||||
var c = new C();
|
var c1 = new C1();
|
||||||
|
|
||||||
assert.sameValue(c.hasOwnProperty("constructor"), true);
|
assert.sameValue(c1.hasOwnProperty("constructor"), true);
|
||||||
assert.sameValue(C.hasOwnProperty("constructor"), false);
|
assert.sameValue(C1.hasOwnProperty("constructor"), false);
|
||||||
|
@ -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.
|
// 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
|
esid: sec-class-definitions-static-semantics-early-errors
|
||||||
features: [class, class-static-fields-public]
|
features: [class, class-static-fields-public]
|
||||||
info: |
|
info: |
|
||||||
@ -10,22 +10,71 @@ info: |
|
|||||||
ComputedPropertyName : [ AssignmentExpression ]
|
ComputedPropertyName : [ AssignmentExpression ]
|
||||||
Return empty.
|
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
|
Static Semantics: Early Errors
|
||||||
|
|
||||||
ClassElement : static FieldDefinition;
|
ClassElement : static FieldDefinition;
|
||||||
It is a Syntax Error if PropName of FieldDefinition is "prototype" or "constructor".
|
It is a Syntax Error if PropName of FieldDefinition is "prototype" or "constructor".
|
||||||
|
|
||||||
negative:
|
-- IDK what is calling InitializeClassElements but I guess it's supposed to be called to
|
||||||
phase: parse
|
-- set the fields
|
||||||
type: SyntaxError
|
|
||||||
|
|
||||||
|
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 C1 {
|
||||||
var x = "constructor";
|
|
||||||
class C {
|
|
||||||
static [x];
|
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,
|
||||||
|
});
|
||||||
|
@ -1,31 +1,32 @@
|
|||||||
// Copyright (C) 2017 Valerie Young. All rights reserved.
|
// Copyright (C) 2017 Valerie Young. All rights reserved.
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
// 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
|
esid: sec-class-definitions-static-semantics-early-errors
|
||||||
features: [class, class-static-fields-public]
|
features: [class, class-static-fields-public]
|
||||||
info: |
|
info: |
|
||||||
Static Semantics: PropName
|
14.6.13 Runtime Semantics: ClassDefinitionEvaluation
|
||||||
|
|
||||||
|
...
|
||||||
|
16. Perform MakeConstructor(F, false, proto).
|
||||||
...
|
...
|
||||||
ComputedPropertyName : [ AssignmentExpression ]
|
|
||||||
Return empty.
|
|
||||||
|
|
||||||
|
9.2.10 MakeConstructor ( F [ , writablePrototype [ , prototype ] ] )
|
||||||
|
|
||||||
// This test file tests the following early error:
|
6. Perform ! DefinePropertyOrThrow(F, "prototype", PropertyDescriptor { [[Value]]: prototype,
|
||||||
Static Semantics: Early Errors
|
[[Writable]]: writablePrototype, [[Enumerable]]: false, [[Configurable]]: false }).
|
||||||
|
|
||||||
ClassElement : static FieldDefinition;
|
|
||||||
It is a Syntax Error if PropName of FieldDefinition is "prototype" or "constructor".
|
|
||||||
|
|
||||||
negative:
|
|
||||||
phase: parse
|
|
||||||
type: SyntaxError
|
|
||||||
|
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
throw "Test262: This statement should not be evaluated.";
|
|
||||||
|
|
||||||
var x = "prototype";
|
var x = "prototype";
|
||||||
class C {
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
class C {
|
||||||
|
static [x] = 42;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
class C {
|
||||||
static [x];
|
static [x];
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
@ -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.
|
// 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
|
esid: sec-class-definitions-static-semantics-early-errors
|
||||||
features: [class-static-fields-public]
|
features: [class, class-static-fields-public]
|
||||||
info: |
|
info: |
|
||||||
Static Semantics: PropName
|
Static Semantics: PropName
|
||||||
...
|
...
|
||||||
ComputedPropertyName : [ AssignmentExpression ]
|
ComputedPropertyName : [ AssignmentExpression ]
|
||||||
Return empty.
|
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
|
Static Semantics: Early Errors
|
||||||
|
|
||||||
ClassElement : static FieldDefinition;
|
ClassElement : static FieldDefinition;
|
||||||
It is a Syntax Error if PropName of FieldDefinition is "prototype" or "constructor".
|
It is a Syntax Error if PropName of FieldDefinition is "prototype" or "constructor".
|
||||||
|
|
||||||
negative:
|
-- IDK what is calling InitializeClassElements but I guess it's supposed to be called to
|
||||||
phase: parse
|
-- set the fields
|
||||||
type: SyntaxError
|
|
||||||
|
|
||||||
|
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 C1 {
|
||||||
|
static ['constructor'];
|
||||||
class C {
|
|
||||||
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,
|
||||||
|
});
|
||||||
|
@ -1,30 +1,30 @@
|
|||||||
// Copyright (C) 2017 Valerie Young. All rights reserved.
|
// Copyright (C) 2017 Valerie Young. All rights reserved.
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
// 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
|
esid: sec-class-definitions-static-semantics-early-errors
|
||||||
features: [class-static-fields-public]
|
features: [class, class-static-fields-public]
|
||||||
info: |
|
info: |
|
||||||
Static Semantics: PropName
|
14.6.13 Runtime Semantics: ClassDefinitionEvaluation
|
||||||
|
|
||||||
|
...
|
||||||
|
16. Perform MakeConstructor(F, false, proto).
|
||||||
...
|
...
|
||||||
ComputedPropertyName : [ AssignmentExpression ]
|
|
||||||
Return empty.
|
|
||||||
|
|
||||||
|
9.2.10 MakeConstructor ( F [ , writablePrototype [ , prototype ] ] )
|
||||||
|
|
||||||
// This test file tests the following early error:
|
6. Perform ! DefinePropertyOrThrow(F, "prototype", PropertyDescriptor { [[Value]]: prototype,
|
||||||
Static Semantics: Early Errors
|
[[Writable]]: writablePrototype, [[Enumerable]]: false, [[Configurable]]: false }).
|
||||||
|
|
||||||
ClassElement : static FieldDefinition;
|
|
||||||
It is a Syntax Error if PropName of FieldDefinition is "prototype" or "constructor".
|
|
||||||
|
|
||||||
negative:
|
|
||||||
phase: parse
|
|
||||||
type: SyntaxError
|
|
||||||
|
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
throw "Test262: This statement should not be evaluated.";
|
assert.throws(TypeError, function() {
|
||||||
|
class C {
|
||||||
|
static ['prototype'] = 42;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
class C {
|
assert.throws(TypeError, function() {
|
||||||
static ["prototype"];
|
class C {
|
||||||
}
|
static ['prototype'];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
@ -62,8 +62,6 @@ var obj3 = {
|
|||||||
valueOf: function() { return s3; }
|
valueOf: function() { return s3; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class C {
|
class C {
|
||||||
[obj1] = 42;
|
[obj1] = 42;
|
||||||
[obj2] = 43;
|
[obj2] = 43;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user