1/* Copyright JS Foundation and other contributors, http://js.foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16function must_throw (str) {
17  try {
18    eval ("switch (1) { default: " + str + "}");
19    assert (false);
20  } catch (e) { }
21
22  try {
23    eval (str);
24    assert (false);
25  }
26  catch (e) { }
27
28  try {
29    eval ("'use strict'; switch (1) { default: " + str + "}");
30    assert (false);
31  } catch (e) { }
32
33  try {
34    eval ("'use strict'; " + str);
35    assert (false);
36  } catch (e) { }
37}
38
39class A {
40  constructor (a) {
41    this.a = a;
42  }
43
44  f () {
45    return 5;
46  }
47}
48
49must_throw ("class B extends 5 + 6 + 5 { constructor (a, b) { super (a) } }");
50
51must_throw ("class B extends null { constructor () { super () } }; new B");
52
53must_throw ("var o = { a : 5 }; \
54             class B extends Object.keys (o)[0] { constructor (a, b) { super (a) } } \
55             var b = new B (1, 2);");
56
57must_throw ("class B extends A { constructor (a, b) { this.b = b} } \
58             var b = new B (1, 2);");
59
60must_throw ("class B extends A { constructor (a, b) { super.f () } } \
61             var b = new B (1, 2);");
62
63must_throw ("class B extends A { constructor (a, b) { eval ('this.b = b') } } \
64             var b = new B (1, 2);");
65
66must_throw ("class B extends A { constructor (a, b) { eval ('super.f ()') } } \
67             var b = new B (1, 2);");
68
69must_throw ("class B extends A { constructor (a, b) { super (a); super (a); } } \
70             var b = new B (1, 2);");
71
72must_throw ("class B extends A { constructor (a, b) { eval ('super (a)'); eval ('super (a)'); } } \
73             var b = new B (1, 2);");
74
75must_throw ("class B extends A { constructor (a, b) { super (a) } g () { super (a) } } \
76             var b = new B (1, 2);");
77
78must_throw ("class B extends A { constructor (a, b) { super (a) } g () { eval ('super (a)') } } \
79             var b = new B (1, 2); \
80             b.g ();");
81
82must_throw ("class B extends A { constructor (a, b) { super (a) } g () { return function () { return super.f () } } } \
83             var b = new B (1, 2); \
84             b.g ()();");
85
86must_throw ("class B extends A { constructor (a, b) { super (a) } \
87                                 g () { return function () { return eval ('super.f ()') } } } \
88             var b = new B (1, 2); \
89             b.g ()();");
90
91must_throw ("class B extends A { constructor (a, b) { super (a) } \
92                                 g () { return function () { return eval (\"eval ('super.f ();')\") } } } \
93             var b = new B (1, 2); \
94             b.g ()();");
95
96must_throw ("class A extends Array { constructor () { return 5; } }; new A");
97
98must_throw ("class A extends Array { constructor () { return undefined; } }; new A");
99
100must_throw ("class B extends undefined { }; new B;");
101
102must_throw ("var A = class extends Array { . }");
103
104must_throw ("class Array extends Array { }");
105
106must_throw ("class A extends A { }");
107
108must_throw ("class A extends { constructor () { super () } }");
109
110must_throw ("class A extends a * b {}");
111
112must_throw ("class A extends a = b {}");
113
114must_throw ("class A extends a++ {}");
115
116must_throw ("class A extends -a {}");
117
118class B extends A {
119  constructor (a, b) {
120    super (a);
121    assert (super.f () === 5);
122  }
123
124  g () {
125    return () => {
126      return super.f ();
127    }
128  }
129
130  h () {
131    return () => {
132      return () => {
133        return eval ('super.f ()');
134      }
135    }
136  }
137}
138
139var b = new B (1, 2);
140assert (b.g ()() === 5);
141assert (b.h ()()() === 5);
142