1var noError = false;
2
3function assert(cond) {
4 if (!cond)
5 throw new Error("broke assertion");
6}
7
8try {
9 (function () { let a; eval('var a'); })();
10} catch (e) {
11 noError = e instanceof SyntaxError;
12}
13
14assert(noError, 'Expected syntax error in case var tried shadow let/const');
15
16
17var noError = false;
18
19try {
20 (function () { let a; eval('{ var a = 10; }'); })();
21} catch (e) {
22 noError = e instanceof SyntaxError;
23}
24
25assert(noError, 'Expected syntax error in case var tried shadow let/const');
26
27var noError = false;
28
29try {
30 function foo() { let a; eval('{ var a = 10; }'); }
31 foo();
32} catch (e) {
33 noError = e instanceof SyntaxError;
34}
35
36assert(noError, 'Expected syntax error in case var tried shadow let/const');
37
38try {
39 (function () { const a = ''; eval('var a'); })();
40} catch (e) {
41 noError = e instanceof SyntaxError;
42}
43
44assert(noError, 'Expected syntax error in case var tried shadow let/const');
45
46
47var noError = false;
48
49try {
50 (function () { const a = ''; eval('{ var a = 10; }'); })();
51} catch (e) {
52 noError = e instanceof SyntaxError;
53}
54
55assert(noError, 'Expected syntax error in case var tried shadow let/const');
56
57
58var noError = false;
59
60try {
61 function foo() { const a = ''; eval('{ var a = 10; }'); }
62 foo();
63} catch (e) {
64 noError = e instanceof SyntaxError;
65}
66
67assert(noError, 'Expected syntax error in case var tried shadow let/const');
68
69noError = false;
70
71function boo() {
72 try {
73 throw new Error('error');
74 } catch(e) {
75 noError = e instanceof Error;
76 eval('var e = 10;');
77 noError = noError && e === 10;
78 }
79 noError = noError && typeof e === 'undefined';
80};
81boo();
82
83assert(noError, 'Expected that var in eval can override variable in catch block');
84
85noError = false;
86
87function foo() {
88 try {
89 throw new Error('error');
90 } catch(e) {
91 noError = e instanceof Error;
92 eval('function e() { return "abcd"; }');
93 noError = noError && typeof e === 'function' && e() === 'abcd';
94 }
95 noError = noError && typeof e === 'undefined';
96};
97foo();
98
99assert(noError, 'Expected that function in eval can override variable in catch block');
100
101
102noError = false;
103
104try {
105 (function () {
106 var o = {a:'1'};
107 let a;
108 with (o) {
109 eval('var a');
110 }
111 })();
112} catch (error) {
113 noError = error instanceof SyntaxError;
114}
115
116assert(noError, 'Expected `with` is not affect early SyntaxError in eval');
117
118noError = false;
119
120(function () {
121 var o = { a:'1' };
122 with (o) {
123 eval('var a = 10;');
124 }
125 noError = a === undefined && o.a === 10;
126})();
127
128assert(noError, 'Expected `with` is not affect early SyntaxError in eval');
129
130noError = false;
131
132{
133 let a = 10;
134 noError = a === 10;
135 (function () {
136 noError = noError && a === 10;
137 eval('var a = 20');
138 noError = noError && a === 20;
139 })();
140 noError = noError && a === 10;
141}
142
143assert(noError, 'Expected `with` is not affect early SyntaxError in eval');
144
145{
146 const a = 10;
147 noError = a === 10;
148 (function () {
149 noError = noError && a === 10;
150 eval('var a = 20');
151 noError = noError && a === 20;
152 })();
153 noError = noError && a === 10;
154}
155
156assert(noError, 'Expected `with` is not affect early SyntaxError in eval');