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-with-fields.js (3320B)


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