tor-browser

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

multiple-definitions-static-private-methods.js (3196B)


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