1425bb815Sopenharmony_ci/* Copyright JS Foundation and other contributors, http://js.foundation
2425bb815Sopenharmony_ci *
3425bb815Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4425bb815Sopenharmony_ci * you may not use this file except in compliance with the License.
5425bb815Sopenharmony_ci * You may obtain a copy of the License at
6425bb815Sopenharmony_ci *
7425bb815Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8425bb815Sopenharmony_ci *
9425bb815Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10425bb815Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS
11425bb815Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12425bb815Sopenharmony_ci * See the License for the specific language governing permissions and
13425bb815Sopenharmony_ci * limitations under the License.
14425bb815Sopenharmony_ci */
15425bb815Sopenharmony_ci
16425bb815Sopenharmony_cifunction must_throw (str) {
17425bb815Sopenharmony_ci  try {
18425bb815Sopenharmony_ci    eval ("switch (1) { default: " + str + "}");
19425bb815Sopenharmony_ci    assert (false);
20425bb815Sopenharmony_ci  } catch (e) { }
21425bb815Sopenharmony_ci
22425bb815Sopenharmony_ci  try {
23425bb815Sopenharmony_ci    eval (str);
24425bb815Sopenharmony_ci    assert (false);
25425bb815Sopenharmony_ci  }
26425bb815Sopenharmony_ci  catch (e) { }
27425bb815Sopenharmony_ci
28425bb815Sopenharmony_ci  try {
29425bb815Sopenharmony_ci    eval ("'use strict'; switch (1) { default: " + str + "}");
30425bb815Sopenharmony_ci    assert (false);
31425bb815Sopenharmony_ci  } catch (e) { }
32425bb815Sopenharmony_ci
33425bb815Sopenharmony_ci  try {
34425bb815Sopenharmony_ci    eval ("'use strict'; " + str);
35425bb815Sopenharmony_ci    assert (false);
36425bb815Sopenharmony_ci  } catch (e) { }
37425bb815Sopenharmony_ci}
38425bb815Sopenharmony_ci
39425bb815Sopenharmony_ciclass A {
40425bb815Sopenharmony_ci  constructor (a) {
41425bb815Sopenharmony_ci    this.a = a;
42425bb815Sopenharmony_ci  }
43425bb815Sopenharmony_ci
44425bb815Sopenharmony_ci  f () {
45425bb815Sopenharmony_ci    return 5;
46425bb815Sopenharmony_ci  }
47425bb815Sopenharmony_ci}
48425bb815Sopenharmony_ci
49425bb815Sopenharmony_cimust_throw ("class B extends 5 + 6 + 5 { constructor (a, b) { super (a) } }");
50425bb815Sopenharmony_ci
51425bb815Sopenharmony_cimust_throw ("class B extends null { constructor () { super () } }; new B");
52425bb815Sopenharmony_ci
53425bb815Sopenharmony_cimust_throw ("var o = { a : 5 }; \
54425bb815Sopenharmony_ci             class B extends Object.keys (o)[0] { constructor (a, b) { super (a) } } \
55425bb815Sopenharmony_ci             var b = new B (1, 2);");
56425bb815Sopenharmony_ci
57425bb815Sopenharmony_cimust_throw ("class B extends A { constructor (a, b) { this.b = b} } \
58425bb815Sopenharmony_ci             var b = new B (1, 2);");
59425bb815Sopenharmony_ci
60425bb815Sopenharmony_cimust_throw ("class B extends A { constructor (a, b) { super.f () } } \
61425bb815Sopenharmony_ci             var b = new B (1, 2);");
62425bb815Sopenharmony_ci
63425bb815Sopenharmony_cimust_throw ("class B extends A { constructor (a, b) { eval ('this.b = b') } } \
64425bb815Sopenharmony_ci             var b = new B (1, 2);");
65425bb815Sopenharmony_ci
66425bb815Sopenharmony_cimust_throw ("class B extends A { constructor (a, b) { eval ('super.f ()') } } \
67425bb815Sopenharmony_ci             var b = new B (1, 2);");
68425bb815Sopenharmony_ci
69425bb815Sopenharmony_cimust_throw ("class B extends A { constructor (a, b) { super (a); super (a); } } \
70425bb815Sopenharmony_ci             var b = new B (1, 2);");
71425bb815Sopenharmony_ci
72425bb815Sopenharmony_cimust_throw ("class B extends A { constructor (a, b) { eval ('super (a)'); eval ('super (a)'); } } \
73425bb815Sopenharmony_ci             var b = new B (1, 2);");
74425bb815Sopenharmony_ci
75425bb815Sopenharmony_cimust_throw ("class B extends A { constructor (a, b) { super (a) } g () { super (a) } } \
76425bb815Sopenharmony_ci             var b = new B (1, 2);");
77425bb815Sopenharmony_ci
78425bb815Sopenharmony_cimust_throw ("class B extends A { constructor (a, b) { super (a) } g () { eval ('super (a)') } } \
79425bb815Sopenharmony_ci             var b = new B (1, 2); \
80425bb815Sopenharmony_ci             b.g ();");
81425bb815Sopenharmony_ci
82425bb815Sopenharmony_cimust_throw ("class B extends A { constructor (a, b) { super (a) } g () { return function () { return super.f () } } } \
83425bb815Sopenharmony_ci             var b = new B (1, 2); \
84425bb815Sopenharmony_ci             b.g ()();");
85425bb815Sopenharmony_ci
86425bb815Sopenharmony_cimust_throw ("class B extends A { constructor (a, b) { super (a) } \
87425bb815Sopenharmony_ci                                 g () { return function () { return eval ('super.f ()') } } } \
88425bb815Sopenharmony_ci             var b = new B (1, 2); \
89425bb815Sopenharmony_ci             b.g ()();");
90425bb815Sopenharmony_ci
91425bb815Sopenharmony_cimust_throw ("class B extends A { constructor (a, b) { super (a) } \
92425bb815Sopenharmony_ci                                 g () { return function () { return eval (\"eval ('super.f ();')\") } } } \
93425bb815Sopenharmony_ci             var b = new B (1, 2); \
94425bb815Sopenharmony_ci             b.g ()();");
95425bb815Sopenharmony_ci
96425bb815Sopenharmony_cimust_throw ("class A extends Array { constructor () { return 5; } }; new A");
97425bb815Sopenharmony_ci
98425bb815Sopenharmony_cimust_throw ("class A extends Array { constructor () { return undefined; } }; new A");
99425bb815Sopenharmony_ci
100425bb815Sopenharmony_cimust_throw ("class B extends undefined { }; new B;");
101425bb815Sopenharmony_ci
102425bb815Sopenharmony_cimust_throw ("var A = class extends Array { . }");
103425bb815Sopenharmony_ci
104425bb815Sopenharmony_cimust_throw ("class Array extends Array { }");
105425bb815Sopenharmony_ci
106425bb815Sopenharmony_cimust_throw ("class A extends A { }");
107425bb815Sopenharmony_ci
108425bb815Sopenharmony_cimust_throw ("class A extends { constructor () { super () } }");
109425bb815Sopenharmony_ci
110425bb815Sopenharmony_cimust_throw ("class A extends a * b {}");
111425bb815Sopenharmony_ci
112425bb815Sopenharmony_cimust_throw ("class A extends a = b {}");
113425bb815Sopenharmony_ci
114425bb815Sopenharmony_cimust_throw ("class A extends a++ {}");
115425bb815Sopenharmony_ci
116425bb815Sopenharmony_cimust_throw ("class A extends -a {}");
117425bb815Sopenharmony_ci
118425bb815Sopenharmony_ciclass B extends A {
119425bb815Sopenharmony_ci  constructor (a, b) {
120425bb815Sopenharmony_ci    super (a);
121425bb815Sopenharmony_ci    assert (super.f () === 5);
122425bb815Sopenharmony_ci  }
123425bb815Sopenharmony_ci
124425bb815Sopenharmony_ci  g () {
125425bb815Sopenharmony_ci    return () => {
126425bb815Sopenharmony_ci      return super.f ();
127425bb815Sopenharmony_ci    }
128425bb815Sopenharmony_ci  }
129425bb815Sopenharmony_ci
130425bb815Sopenharmony_ci  h () {
131425bb815Sopenharmony_ci    return () => {
132425bb815Sopenharmony_ci      return () => {
133425bb815Sopenharmony_ci        return eval ('super.f ()');
134425bb815Sopenharmony_ci      }
135425bb815Sopenharmony_ci    }
136425bb815Sopenharmony_ci  }
137425bb815Sopenharmony_ci}
138425bb815Sopenharmony_ci
139425bb815Sopenharmony_civar b = new B (1, 2);
140425bb815Sopenharmony_ciassert (b.g ()() === 5);
141425bb815Sopenharmony_ciassert (b.h ()()() === 5);
142