tor-browser

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

same-line-async-gen-static-private-methods.js (2499B)


      1 // |reftest| async
      2 // This file was procedurally generated from the following sources:
      3 // - src/class-elements/static-private-methods.case
      4 // - src/class-elements/productions/cls-decl-after-same-line-async-gen.template
      5 /*---
      6 description: static private methods (field definitions after an async generator in the same line)
      7 esid: prod-FieldDefinition
      8 features: [class-static-methods-private, class, class-fields-public, async-iteration]
      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 class C {
     29  async *m() { return 42; } ;
     30  static #x(value) {
     31    return value / 2;
     32  }
     33  static #y(value) {
     34    return value * 2;
     35  }
     36  static x() {
     37    return this.#x(84);
     38  }
     39  static y() {
     40    return this.#y(43);
     41  }
     42 }
     43 
     44 var c = new C();
     45 
     46 assert(
     47  !Object.prototype.hasOwnProperty.call(c, "m"),
     48  "m doesn't appear as an own property on the C instance"
     49 );
     50 assert.sameValue(c.m, C.prototype.m);
     51 
     52 verifyProperty(C.prototype, "m", {
     53  enumerable: false,
     54  configurable: true,
     55  writable: true,
     56 }, {restore: true});
     57 
     58 c.m().next().then(function(v) {
     59  assert.sameValue(v.value, 42);
     60  assert.sameValue(v.done, true);
     61 
     62  function assertions() {
     63    // Cover $DONE handler for async cases.
     64    function $DONE(error) {
     65      if (error) {
     66        throw new Test262Error('Test262:AsyncTestFailure')
     67      }
     68    }
     69    // Test the private methods do not appear as properties before set to value
     70    assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#x"), "test 1");
     71    assert(!Object.prototype.hasOwnProperty.call(C, "#x"), "test 2");
     72    assert(!Object.prototype.hasOwnProperty.call(c, "#x"), "test 3");
     73 
     74    assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#y"), "test 4");
     75    assert(!Object.prototype.hasOwnProperty.call(C, "#y"), "test 5");
     76    assert(!Object.prototype.hasOwnProperty.call(c, "#y"), "test 6");
     77 
     78    // Test if private fields can be sucessfully accessed and set to value
     79    assert.sameValue(C.x(), 42, "test 7");
     80    assert.sameValue(C.y(), 86, "test 8");
     81 
     82    // Test the private fields do not appear as properties before after set to value
     83    assert(!Object.prototype.hasOwnProperty.call(C, "#x"), "test 9");
     84    assert(!Object.prototype.hasOwnProperty.call(C, "#y"), "test 10");
     85  }
     86 
     87  return Promise.resolve(assertions());
     88 }).then($DONE, $DONE);