summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/class/fields-static-class-name-binding-eval.js
blob: 34185e7ecd5d8904656da8090595adea3117b6e1 (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Static field initialisers can access the inner name binding for class definitions.
{
  class C {
    static field = eval("C");
  }
  assertEq(C.field, C);
}
{
  let C = class Inner {
    static field = eval("Inner");
  };
  assertEq(C.field, C);
}

// Static field initialisers can't access the outer name binding for class expressions
// before it has been initialised.
{
  assertThrowsInstanceOf(() => {
    let C = class {
      static field = eval("C");
    };
  }, ReferenceError);
}

// Static field initialisers can access the outer name binding for class expressions after
// the binding has been initialised
{
  let C = class {
    static field = () => eval("C");
  };
  assertEq(C.field(), C);
}

// Static field initialiser expressions always resolve the inner name binding.
{
  class C {
    static field = () => eval("C");
  }
  assertEq(C.field(), C);

  const D = C;
  C = null;

  assertEq(D.field(), D);
}
{
  let C = class Inner {
    static field = () => eval("Inner");
  }
  assertEq(C.field(), C);

  const D = C;
  C = null;

  assertEq(D.field(), D);
}

if (typeof reportCompare === "function")
  reportCompare(true, true);