tor-browser

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

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


      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-decl-after-same-line-static-async-method.template
      5 /*---
      6 description: static private methods with fields (field definitions after a static 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 class C {
     29  static 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(
     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 }, {restore: true});
     62 
     63 C.m().then(function(v) {
     64  assert.sameValue(v, 42);
     65 
     66  function assertions() {
     67    // Cover $DONE handler for async cases.
     68    function $DONE(error) {
     69      if (error) {
     70        throw new Test262Error('Test262:AsyncTestFailure')
     71      }
     72    }
     73    // Test the private methods do not appear as properties before set to value
     74    assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#x"), "test 1");
     75    assert(!Object.prototype.hasOwnProperty.call(C, "#x"), "test 2");
     76    assert(!Object.prototype.hasOwnProperty.call(c, "#x"), "test 3");
     77 
     78    assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#y"), "test 4");
     79    assert(!Object.prototype.hasOwnProperty.call(C, "#y"), "test 5");
     80    assert(!Object.prototype.hasOwnProperty.call(c, "#y"), "test 6");
     81 
     82    assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#xVal"), "test 7");
     83    assert(!Object.prototype.hasOwnProperty.call(C, "#xVal"), "test 8");
     84    assert(!Object.prototype.hasOwnProperty.call(c, "#xVal"), "test 9");
     85 
     86    assert(!Object.prototype.hasOwnProperty.call(C.prototype, "#yVal"), "test 10");
     87    assert(!Object.prototype.hasOwnProperty.call(C, "#yVal"), "test 11");
     88    assert(!Object.prototype.hasOwnProperty.call(c, "#yVal"), "test 12");
     89 
     90    // Test if private fields can be sucessfully accessed and set to value
     91    assert.sameValue(C.x(), 42, "test 13");
     92    assert.sameValue(C.y(), 43, "test 14");
     93 
     94    // Test the private fields do not appear as properties before after set to value
     95    assert(!Object.prototype.hasOwnProperty.call(C, "#x"), "test 15");
     96    assert(!Object.prototype.hasOwnProperty.call(C, "#y"), "test 16");
     97 
     98    assert(!Object.prototype.hasOwnProperty.call(C, "#xVal"), "test 17");
     99    assert(!Object.prototype.hasOwnProperty.call(C, "#yVal"), "test 18");
    100  }
    101 
    102  return Promise.resolve(assertions());
    103 }).then($DONE, $DONE);