OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 13 matching lines...) Expand all Loading... |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 // Flags: --harmony-scoping --allow-natives-syntax | 28 // Flags: --harmony-scoping --allow-natives-syntax |
29 | 29 |
30 // TODO(ES6): properly activate extended mode | 30 // TODO(ES6): properly activate extended mode |
31 "use strict"; | 31 "use strict"; |
32 | 32 |
33 // Check that the following functions are optimizable. | 33 // Check that the following functions are optimizable. |
34 var functions = [ f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12 ]; | 34 var functions = [ f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, |
| 35 f15, f16, f17, f18, f19, f20, f21, f22, f23 ]; |
35 | 36 |
36 for (var i = 0; i < functions.length; ++i) { | 37 for (var i = 0; i < functions.length; ++i) { |
37 var func = functions[i]; | 38 var func = functions[i]; |
38 print("Testing:"); | 39 print("Testing:"); |
39 print(func); | 40 print(func); |
40 for (var j = 0; j < 10; ++j) { | 41 for (var j = 0; j < 10; ++j) { |
41 func(12); | 42 func(12); |
42 } | 43 } |
43 %OptimizeFunctionOnNextCall(func); | 44 %OptimizeFunctionOnNextCall(func); |
44 func(12); | 45 func(12); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 function f11() { | 89 function f11() { |
89 let x; | 90 let x; |
90 x = 1; | 91 x = 1; |
91 } | 92 } |
92 | 93 |
93 function f12() { | 94 function f12() { |
94 function x() {}; | 95 function x() {}; |
95 x = 1; | 96 x = 1; |
96 } | 97 } |
97 | 98 |
| 99 function f13(x) { |
| 100 (function() { x; }); |
| 101 } |
| 102 |
| 103 function f14() { |
| 104 let x; |
| 105 (function() { x; }); |
| 106 } |
| 107 |
| 108 function f15() { |
| 109 function x() { |
| 110 } |
| 111 (function() { x; }); |
| 112 } |
| 113 |
| 114 function f16() { |
| 115 let x = 1; |
| 116 (function() { x; }); |
| 117 } |
| 118 |
| 119 function f17() { |
| 120 const x = 1; |
| 121 (function() { x; }); |
| 122 } |
| 123 |
| 124 function f18(x) { |
| 125 return x; |
| 126 (function() { x; }); |
| 127 } |
| 128 |
| 129 function f19() { |
| 130 let x; |
| 131 return x; |
| 132 (function() { x; }); |
| 133 } |
| 134 |
| 135 function f20() { |
| 136 function x() { |
| 137 } |
| 138 return x; |
| 139 (function() { x; }); |
| 140 } |
| 141 |
| 142 function f21(x) { |
| 143 x = 1; |
| 144 (function() { x; }); |
| 145 } |
| 146 |
| 147 function f22() { |
| 148 let x; |
| 149 x = 1; |
| 150 (function() { x; }); |
| 151 } |
| 152 |
| 153 function f23() { |
| 154 function x() { } |
| 155 x = 1; |
| 156 (function() { x; }); |
| 157 } |
| 158 |
98 | 159 |
99 // Test that temporal dead zone semantics for function and block scoped | 160 // Test that temporal dead zone semantics for function and block scoped |
100 // let bindings are handled by the optimizing compiler. | 161 // let bindings are handled by the optimizing compiler. |
101 | 162 |
102 function TestFunctionLocal(s) { | 163 function TestFunctionLocal(s) { |
103 'use strict'; | 164 'use strict'; |
104 var func = eval("(function baz(){" + s + "; })"); | 165 var func = eval("(function baz(){" + s + "; })"); |
105 print("Testing:"); | 166 print("Testing:"); |
106 print(func); | 167 print(func); |
107 for (var i = 0; i < 5; ++i) { | 168 for (var i = 0; i < 5; ++i) { |
108 try { | 169 try { |
109 func(); | 170 func(); |
110 assertUnreachable(); | 171 assertUnreachable(); |
111 } catch (e) { | 172 } catch (e) { |
112 assertInstanceof(e, ReferenceError); | 173 assertInstanceof(e, ReferenceError); |
113 } | 174 } |
114 } | 175 } |
115 %OptimizeFunctionOnNextCall(func); | 176 %OptimizeFunctionOnNextCall(func); |
116 try { | 177 try { |
117 func(); | 178 func(); |
118 assertUnreachable(); | 179 assertUnreachable(); |
119 } catch (e) { | 180 } catch (e) { |
120 assertInstanceof(e, ReferenceError); | 181 assertInstanceof(e, ReferenceError); |
121 } | 182 } |
122 } | 183 } |
123 | 184 |
| 185 function TestFunctionContext(s) { |
| 186 'use strict'; |
| 187 var func = eval("(function baz(){ " + s + "; (function() { x; }); })"); |
| 188 print("Testing:"); |
| 189 print(func); |
| 190 for (var i = 0; i < 5; ++i) { |
| 191 print(i); |
| 192 try { |
| 193 func(); |
| 194 assertUnreachable(); |
| 195 } catch (e) { |
| 196 assertInstanceof(e, ReferenceError); |
| 197 } |
| 198 } |
| 199 print("optimize"); |
| 200 %OptimizeFunctionOnNextCall(func); |
| 201 try { |
| 202 print("call"); |
| 203 func(); |
| 204 assertUnreachable(); |
| 205 } catch (e) { |
| 206 print("catch"); |
| 207 assertInstanceof(e, ReferenceError); |
| 208 } |
| 209 } |
| 210 |
124 function TestAll(s) { | 211 function TestAll(s) { |
125 TestFunctionLocal(s); | 212 TestFunctionLocal(s); |
| 213 TestFunctionContext(s); |
126 } | 214 } |
127 | 215 |
128 // Use before initialization in declaration statement. | 216 // Use before initialization in declaration statement. |
129 TestAll('let x = x + 1'); | 217 TestAll('let x = x + 1'); |
130 TestAll('let x = x += 1'); | 218 TestAll('let x = x += 1'); |
131 TestAll('let x = x++'); | 219 TestAll('let x = x++'); |
132 TestAll('let x = ++x'); | 220 TestAll('let x = ++x'); |
133 TestAll('const x = x + 1'); | 221 TestAll('const x = x + 1'); |
134 | 222 |
135 // Use before initialization in prior statement. | 223 // Use before initialization in prior statement. |
(...skipping 29 matching lines...) Expand all Loading... |
165 f(42, true); | 253 f(42, true); |
166 } catch (e) { | 254 } catch (e) { |
167 assertInstanceof(e, ReferenceError); | 255 assertInstanceof(e, ReferenceError); |
168 } | 256 } |
169 | 257 |
170 try { | 258 try { |
171 g(42, true); | 259 g(42, true); |
172 } catch (e) { | 260 } catch (e) { |
173 assertInstanceof(e, ReferenceError); | 261 assertInstanceof(e, ReferenceError); |
174 } | 262 } |
OLD | NEW |