summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/fields/private-field-error-messages.js
blob: 4f7bfe0ae26f118a4a7439df7dc428092f61f485 (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
load(libdir + "asserts.js");

class C {
  #f = 1;
  static test() {
    assertTypeErrorMessage(
      () => [].#f,
      "can't access private field or method: object is not the right class"
    );
    assertTypeErrorMessage(
      () => "ok".#f,
      "can't access private field or method: object is not the right class"
    );
    assertTypeErrorMessage(
      () => { [].#f = 3; },
      "can't set private field: object is not the right class"
    );
    assertTypeErrorMessage(
      () => { [].#f += 3; },
      "can't set private field: object is not the right class"
    );
    assertTypeErrorMessage(
      () => { [].#f++; },
      "can't set private field: object is not the right class"
    );

    assertTypeErrorMessage(
      () => "".#f,
      "can't access private field or method: object is not the right class"
    );
    assertTypeErrorMessage(
      () => { "".#f = 3; },
      "can't set private field: object is not the right class"
    );
  }
}

C.test();