tor-browser

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

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


      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-decl-after-same-line-static-method.template
      4 /*---
      5 description: static private methods with fields (field definitions after a static 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 class C {
     28  static 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(
     53  !Object.prototype.hasOwnProperty.call(C.prototype, "m"),
     54  "m doesn't appear as an own property on the C prototype"
     55 );
     56 
     57 verifyProperty(C, "m", {
     58  enumerable: false,
     59  configurable: true,
     60  writable: true,
     61 });
     62 
     63 // Test the private methods do not appear as properties before set to value
     64 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#x"), "test 1");
     65 assert(!Object.prototype.hasOwnProperty.call(C, "#x"), "test 2");
     66 assert(!Object.prototype.hasOwnProperty.call(c, "#x"), "test 3");
     67 
     68 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#y"), "test 4");
     69 assert(!Object.prototype.hasOwnProperty.call(C, "#y"), "test 5");
     70 assert(!Object.prototype.hasOwnProperty.call(c, "#y"), "test 6");
     71 
     72 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#xVal"), "test 7");
     73 assert(!Object.prototype.hasOwnProperty.call(C, "#xVal"), "test 8");
     74 assert(!Object.prototype.hasOwnProperty.call(c, "#xVal"), "test 9");
     75 
     76 assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#yVal"), "test 10");
     77 assert(!Object.prototype.hasOwnProperty.call(C, "#yVal"), "test 11");
     78 assert(!Object.prototype.hasOwnProperty.call(c, "#yVal"), "test 12");
     79 
     80 // Test if private fields can be sucessfully accessed and set to value
     81 assert.sameValue(C.x(), 42, "test 13");
     82 assert.sameValue(C.y(), 43, "test 14");
     83 
     84 // Test the private fields do not appear as properties before after set to value
     85 assert(!Object.prototype.hasOwnProperty.call(C, "#x"), "test 15");
     86 assert(!Object.prototype.hasOwnProperty.call(C, "#y"), "test 16");
     87 
     88 assert(!Object.prototype.hasOwnProperty.call(C, "#xVal"), "test 17");
     89 assert(!Object.prototype.hasOwnProperty.call(C, "#yVal"), "test 18");
     90 
     91 reportCompare(0, 0);