tor-browser

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

multiple-stacked-definitions-static-private-methods.js (2608B)


      1 // This file was procedurally generated from the following sources:
      2 // - src/class-elements/static-private-methods.case
      3 // - src/class-elements/productions/cls-expr-multiple-stacked-definitions.template
      4 /*---
      5 description: static private methods (multiple stacked fields definitions through ASI)
      6 esid: prod-FieldDefinition
      7 features: [class-static-methods-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  
     29  foo = "foobar"
     30  bar = "barbaz";
     31  static #x(value) {
     32    return value / 2;
     33  }
     34  static #y(value) {
     35    return value * 2;
     36  }
     37  static x() {
     38    return this.#x(84);
     39  }
     40  static y() {
     41    return this.#y(43);
     42  }
     43 }
     44 
     45 var c = new C();
     46 
     47 assert.sameValue(c.foo, "foobar");
     48 assert(
     49  !Object.prototype.hasOwnProperty.call(C, "foo"),
     50  "foo doesn't appear as an own property on the C constructor"
     51 );
     52 assert(
     53  !Object.prototype.hasOwnProperty.call(C.prototype, "foo"),
     54  "foo doesn't appear as an own property on the C prototype"
     55 );
     56 
     57 verifyProperty(c, "foo", {
     58  value: "foobar",
     59  enumerable: true,
     60  configurable: true,
     61  writable: true,
     62 });
     63 
     64 assert.sameValue(c.bar, "barbaz");
     65 assert(
     66  !Object.prototype.hasOwnProperty.call(C, "bar"),
     67  "bar doesn't appear as an own property on the C constructor"
     68 );
     69 assert(
     70  !Object.prototype.hasOwnProperty.call(C.prototype, "bar"),
     71  "bar doesn't appear as an own property on the C prototype"
     72 );
     73 
     74 verifyProperty(c, "bar", {
     75  value: "barbaz",
     76  enumerable: true,
     77  configurable: true,
     78  writable: true,
     79 });
     80 
     81 // Test the private methods do not appear as properties before set to value
     82 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#x"), "test 1");
     83 assert(!Object.prototype.hasOwnProperty.call(C, "#x"), "test 2");
     84 assert(!Object.prototype.hasOwnProperty.call(c, "#x"), "test 3");
     85 
     86 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#y"), "test 4");
     87 assert(!Object.prototype.hasOwnProperty.call(C, "#y"), "test 5");
     88 assert(!Object.prototype.hasOwnProperty.call(c, "#y"), "test 6");
     89 
     90 // Test if private fields can be sucessfully accessed and set to value
     91 assert.sameValue(C.x(), 42, "test 7");
     92 assert.sameValue(C.y(), 86, "test 8");
     93 
     94 // Test the private fields do not appear as properties before after set to value
     95 assert(!Object.prototype.hasOwnProperty.call(C, "#x"), "test 9");
     96 assert(!Object.prototype.hasOwnProperty.call(C, "#y"), "test 10");
     97 
     98 reportCompare(0, 0);