blob: f5766def747678df7b55376790ef0284d69b83a3 [file] [log] [blame]
utatane.tea@gmail.comfdd9bf42015-12-02 03:16:28 +00001function shouldBe(actual, expected) {
2 if (actual !== expected)
3 throw new Error('bad value: ' + actual);
4}
5
6function shouldThrow(func, errorMessage) {
7 var errorThrown = false;
8 var error = null;
9 try {
10 func();
11 } catch (e) {
12 errorThrown = true;
13 error = e;
14 }
15 if (!errorThrown)
16 throw new Error('not thrown');
17 if (String(error) !== errorMessage)
18 throw new Error(`bad error: ${String(error)}`);
19}
20
21function *gen() {
22 yield eval("this");
23}
24
utatane.tea@gmail.comfdd9bf42015-12-02 03:16:28 +000025shouldThrow(() => {
utatane.tea@gmail.com552595b2015-12-29 11:49:35 +000026 var g = new gen();
utatane.tea@gmail.comfdd9bf42015-12-02 03:16:28 +000027 g.next().value;
utatane.tea@gmail.com552595b2015-12-29 11:49:35 +000028}, `TypeError: function is not a constructor (evaluating 'new gen()')`);
utatane.tea@gmail.comfdd9bf42015-12-02 03:16:28 +000029
30class B { }
31
32(function() {
33 eval('this');
34 eval('this');
35}());
36
37class A extends B {
38 constructor()
39 {
40 return eval('this');
41 }
42}
43
44shouldThrow(() => {
45 new A();
46}, `ReferenceError: Cannot access uninitialized variable.`);
47
48class C {
49 *generator()
50 {
51 yield eval('this');
52 }
53}
54
55shouldThrow(() => {
56 let c = new C();
57 let g = new c.generator();
58 g.next();
59}, `TypeError: function is not a constructor (evaluating 'new c.generator()')`);
60
61(function () {
62 let c = new C();
63 let g = c.generator();
64 shouldBe(g.next().value, c);
65}());