tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

fields-computed-name-static-computed-var-propname-constructor.js (2298B)


      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 var x = 'constructor';
     60 class C1 {
     61  static [x];
     62 }
     63 
     64 verifyProperty(C1, 'constructor', {
     65  value: undefined,
     66  configurable: true,
     67  writable: true,
     68  enumerable: true,
     69 });
     70 
     71 class C2 {
     72  static [x] = 42;
     73 }
     74 
     75 verifyProperty(C2, 'constructor', {
     76  value: 42,
     77  configurable: true,
     78  writable: true,
     79  enumerable: true,
     80 });
     81 
     82 reportCompare(0, 0);