tor-browser

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

multiple-definitions-static-private-fields.js (3146B)


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