fields-computed-name-propname-constructor.js (1504B)
1 // Copyright (C) 2017 Valerie Young. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 /*--- 4 description: 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-fields-public] 7 info: | 8 Static Semantics: PropName 9 ... 10 ComputedPropertyName : [ AssignmentExpression ] 11 Return empty. 12 13 14 // This test file tests the following early error: 15 Static Semantics: Early Errors 16 17 ClassElement : FieldDefinition; 18 It is a Syntax Error if PropName of FieldDefinition is "constructor". 19 20 DefineField(receiver, fieldRecord) 21 22 ... 23 8. If fieldName is a Private Name, 24 ... 25 9. Else, 26 a. ... 27 b. Perform ? CreateDataPropertyOrThrow(receiver, fieldName, initValue). 28 29 CreateDataPropertyOrThrow ( O, P, V ) 30 31 ... 32 3. Let success be ? CreateDataProperty(O, P, V). 33 4. If success is false, throw a TypeError exception. 34 ... 35 36 CreateDataProperty ( O, P, V ) 37 38 ... 39 3. Let newDesc be the PropertyDescriptor { [[Value]]: V, [[Writable]]: true, [[Enumerable]]: true, 40 [[Configurable]]: true }. 41 4. Return ? O.[[DefineOwnProperty]](P, newDesc). 42 ---*/ 43 44 var x = "constructor"; 45 class C1 { 46 [x]; 47 } 48 49 var c1 = new C1(); 50 51 assert.sameValue(c1.hasOwnProperty("constructor"), true); 52 assert.sameValue(C1.hasOwnProperty("constructor"), false); 53 54 reportCompare(0, 0);