summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/language/statements/class/elements/grammar-private-field-optional-chaining.js
blob: d0c3fc7cbe71ce11314023ae8b5626c139529775 (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
// This file was procedurally generated from the following sources:
// - src/class-elements/grammar-private-field-optional-chaining.case
// - src/class-elements/default/cls-decl.template
/*---
description: PrivateName after '?.' is valid syntax (field definitions in a class declaration)
esid: prod-FieldDefinition
features: [class-fields-private, optional-chaining, class]
flags: [generated]
info: |
    Updated Productions

    OptionalChain[Yield, Await]:
      `?.` `[` Expression[+In, ?Yield, ?Await] `]`
      `?.` IdentifierName
      `?.` Arguments[?Yield, ?Await]
      `?.` TemplateLiteral[?Yield, ?Await, +Tagged]
      `?.` PrivateIdentifier

---*/


class C {
  #m = 'test262';

  static access(obj) {
    return obj?.#m;
  }
}

let c = new C();

assert.sameValue(C.access(c), 'test262');

assert.sameValue(C.access(null), undefined);
assert.sameValue(C.access(undefined), undefined);

assert.throws(TypeError, function() {
  C.access({});
}, 'accessed private field from an ordinary object');


reportCompare(0, 0);