tor-browser

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

new-sc-line-method-static-private-fields.js (2034B)


      1 // This file was procedurally generated from the following sources:
      2 // - src/class-elements/static-private-fields.case
      3 // - src/class-elements/productions/cls-expr-new-sc-line-method.template
      4 /*---
      5 description: static private fields (field definitions followed by a method in a new line with a semicolon)
      6 esid: prod-FieldDefinition
      7 features: [class-static-fields-private, class, class-fields-public]
      8 flags: [generated]
      9 includes: [propertyHelper.js]
     10 info: |
     11    ClassElement :
     12      ...
     13      static FieldDefinition ;
     14 
     15    FieldDefinition :
     16      ClassElementName Initializer_opt
     17 
     18    ClassElementName :
     19      PrivateName
     20 
     21    PrivateName :
     22      # IdentifierName
     23 
     24 ---*/
     25 
     26 
     27 var C = class {
     28  static #x; static #y;
     29  m() { return 42; }
     30  static x() {
     31    this.#x = 42;
     32    return this.#x;
     33  }
     34  static y() {
     35    this.#y = 43;
     36    return this.#y;
     37  }
     38 }
     39 
     40 var c = new C();
     41 
     42 assert.sameValue(c.m(), 42);
     43 assert.sameValue(c.m, C.prototype.m);
     44 assert(
     45  !Object.prototype.hasOwnProperty.call(c, "m"),
     46  "m doesn't appear as an own property on the C instance"
     47 );
     48 
     49 verifyProperty(C.prototype, "m", {
     50  enumerable: false,
     51  configurable: true,
     52  writable: true,
     53 });
     54 
     55 // Test the private fields do not appear as properties before set to value
     56 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#x"), "test 1");
     57 assert(!Object.prototype.hasOwnProperty.call(C, "#x"), "test 2");
     58 assert(!Object.prototype.hasOwnProperty.call(c, "#x"), "test 3");
     59 
     60 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#y"), "test 4");
     61 assert(!Object.prototype.hasOwnProperty.call(C, "#y"), "test 5");
     62 assert(!Object.prototype.hasOwnProperty.call(c, "#y"), "test 6");
     63 
     64 // Test if private fields can be sucessfully accessed and set to value
     65 assert.sameValue(C.x(), 42, "test 7");
     66 assert.sameValue(C.y(), 43, "test 8");
     67 
     68 // Test the private fields do not appear as properties before after set to value
     69 assert(!Object.prototype.hasOwnProperty.call(C, "#x"), "test 9");
     70 assert(!Object.prototype.hasOwnProperty.call(C, "#y"), "test 10");
     71 
     72 reportCompare(0, 0);