tor-browser

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

multiple-stacked-definitions-static-private-fields.js (2558B)


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