| 1 |
// Copyright (C) 2017 Leo Balter. All rights reserved. |
| 2 |
// This code is governed by the BSD license found in the LICENSE file. |
| 3 |
/*--- |
| 4 |
description: static class fields forbid PropName 'constructor' (no early error -- PropName of ComputedPropertyName not forbidden value) |
| 5 |
esid: sec-class-definitions-static-semantics-early-errors |
| 6 |
features: [class, class-static-fields-public] |
| 7 |
info: | |
| 8 |
Static Semantics: PropName |
| 9 |
... |
| 10 |
ComputedPropertyName : [ AssignmentExpression ] |
| 11 |
Return empty. |
| 12 |
|
| 13 |
This test file tests the following early error is only valid for a matching PropName: |
| 14 |
|
| 15 |
Static Semantics: Early Errors |
| 16 |
|
| 17 |
ClassElement : static FieldDefinition; |
| 18 |
It is a Syntax Error if PropName of FieldDefinition is "prototype" or "constructor". |
| 19 |
|
| 20 |
-- IDK what is calling InitializeClassElements but I guess it's supposed to be called to |
| 21 |
-- set the fields |
| 22 |
|
| 23 |
InitializeClassElements(F, proto) |
| 24 |
|
| 25 |
... |
| 26 |
6. For each item element in order from elements, |
| 27 |
a. If element.[[Kind]] is "field" and element.[[Placement]] is "static" or "prototype", |
| 28 |
... |
| 29 |
ii. Let receiver be F if element.[[Placement]] is "static", else let receiver be proto. |
| 30 |
iii. Perform ? DefineClassElement(receiver, element). |
| 31 |
|
| 32 |
-- DefineClassElement is probably DefineField in the class fields proposal |
| 33 |
|
| 34 |
DefineField(receiver, fieldRecord) |
| 35 |
|
| 36 |
... |
| 37 |
8. If fieldName is a Private Name, |
| 38 |
... |
| 39 |
9. Else, |
| 40 |
a. ... |
| 41 |
b. Perform ? CreateDataPropertyOrThrow(receiver, fieldName, initValue). |
| 42 |
|
| 43 |
CreateDataPropertyOrThrow ( O, P, V ) |
| 44 |
|
| 45 |
... |
| 46 |
3. Let success be ? CreateDataProperty(O, P, V). |
| 47 |
4. If success is false, throw a TypeError exception. |
| 48 |
... |
| 49 |
|
| 50 |
CreateDataProperty ( O, P, V ) |
| 51 |
|
| 52 |
... |
| 53 |
3. Let newDesc be the PropertyDescriptor { [[Value]]: V, [[Writable]]: true, [[Enumerable]]: true, |
| 54 |
[[Configurable]]: true }. |
| 55 |
4. Return ? O.[[DefineOwnProperty]](P, newDesc). |
| 56 |
includes: [propertyHelper.js] |
| 57 |
---*/ |
| 58 |
|
| 59 |
class C1 { |
| 60 |
static ['constructor']; |
| 61 |
} |
| 62 |
|
| 63 |
verifyProperty(C1, 'constructor', { |
| 64 |
value: undefined, |
| 65 |
configurable: true, |
| 66 |
writable: true, |
| 67 |
enumerable: true, |
| 68 |
}); |
| 69 |
|
| 70 |
class C2 { |
| 71 |
static ['constructor'] = 42; |
| 72 |
} |
| 73 |
|
| 74 |
verifyProperty(C2, 'constructor', { |
| 75 |
value: 42, |
| 76 |
configurable: true, |
| 77 |
writable: true, |
| 78 |
enumerable: true, |
| 79 |
}); |
| 80 |
|
| 81 |
reportCompare(0, 0); |