summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/fields/private-field-details.js
blob: 1d746c33c8a16f8069d9bbbf9430c47495c608e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
var shouldBeThis;

class A {
  #nullReturn = false;
  constructor(nullReturn) {
    this.#nullReturn = nullReturn;
  }

  #calls = 0;

  #z =
      () => {
        assertEq(this, shouldBeThis);
        this.#calls++;

        // To test the second optional below.
        if (this.#nullReturn && this.#calls == 2) {
          return null;
        }

        return this;
      }

  static chainTest(o) {
    o?.#z().#z()?.#z();
  }
};

for (var i = 0; i < 1000; i++) {
  var a = new A();
  shouldBeThis = a;

  A.chainTest(a);
  A.chainTest(null);

  var b = new A(true);
  shouldBeThis = b;
  A.chainTest(b);
}