tor-browser

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

after-same-line-method-static-private-methods-with-fields.js (2778B)


      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-after-same-line-method.template
      4 /*---
      5 description: static private methods with fields (field definitions after a method in the same line)
      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  m() { return 42; } static #xVal; static #yVal;
     29  static #x(value) {
     30    this.#xVal = value;
     31    return this.#xVal;
     32  }
     33  static #y(value) {
     34    this.#yVal = value;
     35    return this.#yVal;
     36  }
     37  static x() {
     38    return this.#x(42);
     39  }
     40  static y() {
     41    return this.#y(43);
     42  }
     43 }
     44 
     45 var c = new C();
     46 
     47 assert.sameValue(c.m(), 42);
     48 assert(
     49  !Object.prototype.hasOwnProperty.call(c, "m"),
     50  "m doesn't appear as an own property on the C instance"
     51 );
     52 assert.sameValue(c.m, C.prototype.m);
     53 
     54 verifyProperty(C.prototype, "m", {
     55  enumerable: false,
     56  configurable: true,
     57  writable: true,
     58 });
     59 
     60 // Test the private methods do not appear as properties before set to value
     61 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#x"), "test 1");
     62 assert(!Object.prototype.hasOwnProperty.call(C, "#x"), "test 2");
     63 assert(!Object.prototype.hasOwnProperty.call(c, "#x"), "test 3");
     64 
     65 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#y"), "test 4");
     66 assert(!Object.prototype.hasOwnProperty.call(C, "#y"), "test 5");
     67 assert(!Object.prototype.hasOwnProperty.call(c, "#y"), "test 6");
     68 
     69 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#xVal"), "test 7");
     70 assert(!Object.prototype.hasOwnProperty.call(C, "#xVal"), "test 8");
     71 assert(!Object.prototype.hasOwnProperty.call(c, "#xVal"), "test 9");
     72 
     73 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#yVal"), "test 10");
     74 assert(!Object.prototype.hasOwnProperty.call(C, "#yVal"), "test 11");
     75 assert(!Object.prototype.hasOwnProperty.call(c, "#yVal"), "test 12");
     76 
     77 // Test if private fields can be sucessfully accessed and set to value
     78 assert.sameValue(C.x(), 42, "test 13");
     79 assert.sameValue(C.y(), 43, "test 14");
     80 
     81 // Test the private fields do not appear as properties before after set to value
     82 assert(!Object.prototype.hasOwnProperty.call(C, "#x"), "test 15");
     83 assert(!Object.prototype.hasOwnProperty.call(C, "#y"), "test 16");
     84 
     85 assert(!Object.prototype.hasOwnProperty.call(C, "#xVal"), "test 17");
     86 assert(!Object.prototype.hasOwnProperty.call(C, "#yVal"), "test 18");
     87 
     88 reportCompare(0, 0);