tor-browser

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

grammar-private-field-optional-chaining.js (1030B)


      1 // This file was procedurally generated from the following sources:
      2 // - src/class-elements/grammar-private-field-optional-chaining.case
      3 // - src/class-elements/default/cls-decl.template
      4 /*---
      5 description: PrivateName after '?.' is valid syntax (field definitions in a class declaration)
      6 esid: prod-FieldDefinition
      7 features: [class-fields-private, optional-chaining, class]
      8 flags: [generated]
      9 info: |
     10    Updated Productions
     11 
     12    OptionalChain[Yield, Await]:
     13      `?.` `[` Expression[+In, ?Yield, ?Await] `]`
     14      `?.` IdentifierName
     15      `?.` Arguments[?Yield, ?Await]
     16      `?.` TemplateLiteral[?Yield, ?Await, +Tagged]
     17      `?.` PrivateIdentifier
     18 
     19 ---*/
     20 
     21 
     22 class C {
     23  #m = 'test262';
     24 
     25  static access(obj) {
     26    return obj?.#m;
     27  }
     28 }
     29 
     30 let c = new C();
     31 
     32 assert.sameValue(C.access(c), 'test262');
     33 
     34 assert.sameValue(C.access(null), undefined);
     35 assert.sameValue(C.access(undefined), undefined);
     36 
     37 assert.throws(TypeError, function() {
     38  C.access({});
     39 }, 'accessed private field from an ordinary object');
     40 
     41 
     42 reportCompare(0, 0);