Serenity Operating System
1describe("non-syntax errors", () => {
2 test("super reference inside nested-but-same |this| scope with no base class", () => {
3 expect(`
4 class A {
5 foo() {
6 () => { super.bar; }
7 }
8 }`).toEval();
9 });
10
11 test("super reference property lookup with no base class", () => {
12 expect(`
13 class A {
14 constructor() {
15 super.foo;
16 }
17 }`).toEval();
18 });
19});
20
21describe("reference errors", () => {
22 test("derived class doesn't call super in constructor before using this", () => {
23 class Parent {}
24 class Child extends Parent {
25 constructor() {
26 this;
27 }
28 }
29
30 expect(() => {
31 new Child();
32 }).toThrowWithMessage(ReferenceError, "|this| has not been initialized");
33 });
34
35 test("derived class calls super twice in constructor", () => {
36 class Parent {}
37 class Child extends Parent {
38 constructor() {
39 super();
40 super();
41 }
42 }
43
44 expect(() => {
45 new Child();
46 }).toThrowWithMessage(ReferenceError, "|this| is already initialized");
47 });
48});
49
50describe("syntax errors", () => {
51 test("getter with argument", () => {
52 expect(`
53 class A {
54 get foo(v) {
55 return 0;
56 }
57 }`).not.toEval();
58 });
59
60 test("setter with no arguments", () => {
61 expect(`
62 class A {
63 set foo() {
64 }
65 }`).not.toEval();
66 });
67
68 test("setter with more than one argument", () => {
69 expect(`
70 class A {
71 set foo(bar, baz) {
72 }
73 }`).not.toEval();
74 expect(`
75 class A {
76 set foo(...bar) {
77 }
78 }`).not.toEval();
79 });
80
81 test("super reference inside different |this| scope", () => {
82 expect(`
83 class Parent {}
84
85 class Child extends Parent {
86 foo() {
87 function f() { super.foo; }
88 }
89 }`).not.toEval();
90 });
91
92 test("super reference call with no base class", () => {
93 expect(`
94 class A {
95 constructor() {
96 super();
97 }
98 }`).not.toEval();
99 });
100});