tor-browser

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

wrapped-in-sc-private-names.js (1623B)


      1 // This file was procedurally generated from the following sources:
      2 // - src/class-elements/private-names.case
      3 // - src/class-elements/productions/cls-decl-wrapped-in-sc.template
      4 /*---
      5 description: private names (fields definition wrapped in semicolons)
      6 esid: prod-FieldDefinition
      7 features: [class-fields-private, class, class-fields-public]
      8 flags: [generated]
      9 info: |
     10    ClassElement :
     11      ...
     12      FieldDefinition ;
     13 
     14    FieldDefinition :
     15      ClassElementName Initializer_opt
     16 
     17    ClassElementName :
     18      PrivateName
     19 
     20    PrivateName :
     21      # IdentifierName
     22 
     23 ---*/
     24 
     25 
     26 class C {
     27  ;;;;
     28  ;;;;;;#x; #y;;;;;;;
     29  ;;;;
     30  x() {
     31    this.#x = 42;
     32    return this.#x;
     33  }
     34  y() {
     35    this.#y = 43;
     36    return this.#y;
     37  }
     38 }
     39 
     40 var c = new C();
     41 
     42 // Test the private fields do not appear as properties before set to value
     43 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#x"), "test 1");
     44 assert(!Object.prototype.hasOwnProperty.call(C, "#x"), "test 2");
     45 assert(!Object.prototype.hasOwnProperty.call(c, "#x"), "test 3");
     46 
     47 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#y"), "test 4");
     48 assert(!Object.prototype.hasOwnProperty.call(C, "#y"), "test 5");
     49 assert(!Object.prototype.hasOwnProperty.call(c, "#y"), "test 6");
     50 
     51 // Test if private fields can be sucessfully accessed and set to value
     52 assert.sameValue(c.x(), 42, "test 7");
     53 assert.sameValue(c.y(), 43, "test 8");
     54 
     55 // Test the private fields do not appear as properties before after set to value
     56 assert(!Object.prototype.hasOwnProperty.call(c, "#x"), "test 9");
     57 assert(!Object.prototype.hasOwnProperty.call(c, "#y"), "test 10");
     58 
     59 reportCompare(0, 0);