summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/language/statements/class/elements/fields-computed-name-static-computed-var-propname-constructor.js
blob: 585dbac7de4a1920e9605e0fc17f38b7650a831f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// 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 '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: |
    Static Semantics: PropName
    ...
    ComputedPropertyName : [ AssignmentExpression ]
      Return empty.

    This test file tests the following early error is only valid for a matching PropName:

    Static Semantics: Early Errors

    ClassElement : static FieldDefinition;
        It is a Syntax Error if PropName of FieldDefinition is "prototype" or "constructor".

    -- 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]
---*/

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,
});

reportCompare(0, 0);