tor-browser

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

same-line-async-method-static-private-methods-with-fields.js (3201B)


      1 // |reftest| async
      2 // This file was procedurally generated from the following sources:
      3 // - src/class-elements/static-private-methods-with-fields.case
      4 // - src/class-elements/productions/cls-expr-after-same-line-async-method.template
      5 /*---
      6 description: static private methods with fields (field definitions after an async method in the same line)
      7 esid: prod-FieldDefinition
      8 features: [class-static-methods-private, class-static-fields-private, class, class-fields-public, async-functions]
      9 flags: [generated, async]
     10 includes: [propertyHelper.js]
     11 info: |
     12    ClassElement :
     13      ...
     14      static FieldDefinition ;
     15 
     16    FieldDefinition :
     17      ClassElementName Initializer_opt
     18 
     19    ClassElementName :
     20      PrivateName
     21 
     22    PrivateName :
     23      # IdentifierName
     24 
     25 ---*/
     26 
     27 
     28 var C = class {
     29  async m() { return 42; } static #xVal; static #yVal;
     30  static #x(value) {
     31    this.#xVal = value;
     32    return this.#xVal;
     33  }
     34  static #y(value) {
     35    this.#yVal = value;
     36    return this.#yVal;
     37  }
     38  static x() {
     39    return this.#x(42);
     40  }
     41  static y() {
     42    return this.#y(43);
     43  }
     44 }
     45 
     46 var c = new C();
     47 
     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 }, {restore: true});
     59 
     60 c.m().then(function(v) {
     61  assert.sameValue(v, 42);
     62 
     63  function assertions() {
     64    // Cover $DONE handler for async cases.
     65    function $DONE(error) {
     66      if (error) {
     67        throw new Test262Error('Test262:AsyncTestFailure')
     68      }
     69    }
     70    // Test the private methods do not appear as properties before set to value
     71    assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#x"), "test 1");
     72    assert(!Object.prototype.hasOwnProperty.call(C, "#x"), "test 2");
     73    assert(!Object.prototype.hasOwnProperty.call(c, "#x"), "test 3");
     74 
     75    assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#y"), "test 4");
     76    assert(!Object.prototype.hasOwnProperty.call(C, "#y"), "test 5");
     77    assert(!Object.prototype.hasOwnProperty.call(c, "#y"), "test 6");
     78 
     79    assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#xVal"), "test 7");
     80    assert(!Object.prototype.hasOwnProperty.call(C, "#xVal"), "test 8");
     81    assert(!Object.prototype.hasOwnProperty.call(c, "#xVal"), "test 9");
     82 
     83    assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#yVal"), "test 10");
     84    assert(!Object.prototype.hasOwnProperty.call(C, "#yVal"), "test 11");
     85    assert(!Object.prototype.hasOwnProperty.call(c, "#yVal"), "test 12");
     86 
     87    // Test if private fields can be sucessfully accessed and set to value
     88    assert.sameValue(C.x(), 42, "test 13");
     89    assert.sameValue(C.y(), 43, "test 14");
     90 
     91    // Test the private fields do not appear as properties before after set to value
     92    assert(!Object.prototype.hasOwnProperty.call(C, "#x"), "test 15");
     93    assert(!Object.prototype.hasOwnProperty.call(C, "#y"), "test 16");
     94 
     95    assert(!Object.prototype.hasOwnProperty.call(C, "#xVal"), "test 17");
     96    assert(!Object.prototype.hasOwnProperty.call(C, "#yVal"), "test 18");
     97  }
     98 
     99  return Promise.resolve(assertions());
    100 }).then($DONE, $DONE);