summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/language/statements/class/elements/field-declaration.js
blob: b8c0fcc6c886da84373af8f6c7cce37b15d37cde (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// This file was procedurally generated from the following sources:
// - src/class-elements/field-declaration.case
// - src/class-elements/default/cls-decl.template
/*---
description: Fields are defined (field definitions in a class declaration)
esid: prod-FieldDefinition
features: [class-fields-public, class]
flags: [generated]
includes: [propertyHelper.js]
info: |
    Updated Productions

    ClassElement :
      ...
      FieldDefinition ;

    FieldDefinition :
      ClassElementName Initializer_opt

    ClassElementName :
      PropertyName

    PropertyName :
      LiteralPropertyName
      ComputedPropertyName

    LiteralPropertyName :
      IdentifierName
      StringLiteral
      NumericLiteral

    ClassDefinitionEvaluation:
      ...

      26. Let instanceFields be a new empty List.
      28. For each ClassElement e in order from elements,
        a. If IsStatic of e is false, then
          i. Let field be the result of performing ClassElementEvaluation for e with arguments proto and false.
        b. ...
        c. ...
        d. If field is not empty, append field to instanceFields.

      ...

      30. Set F.[[Fields]] to instanceFields.
      ...

---*/
var computed = 'h';


class C {
  f = 'test262';
  'g';
  0 = 'bar';
  [computed];
}

let c = new C();

assert.sameValue(C.f, undefined);
assert.sameValue(C.g, undefined);
assert.sameValue(C.h, undefined);
assert.sameValue(C[0], undefined);

assert(
  !Object.prototype.hasOwnProperty.call(C, 'f'),
  "f does not appear as an own property on C constructor"
);
assert(
  !Object.prototype.hasOwnProperty.call(C, 'g'),
  "g does not appear as an own property on C constructor"
);
assert(
  !Object.prototype.hasOwnProperty.call(C, 'h'),
  "h does not appear as an own property on C constructor"
);
assert(
  !Object.prototype.hasOwnProperty.call(C, 0),
  "0 does not appear as an own property on C constructor"
);

verifyProperty(c, 'f', {
  value: 'test262',
  enumerable: true,
  writable: true,
  configurable: true
});

verifyProperty(c, 'g', {
  value: undefined,
  enumerable: true,
  writable: true,
  configurable: true
});

verifyProperty(c, 0, {
  value: 'bar',
  enumerable: true,
  writable: true,
  configurable: true
});

verifyProperty(c, 'h', {
  value: undefined,
  enumerable: true,
  writable: true,
  configurable: true
});

reportCompare(0, 0);