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 |
11 // with the distribution. | 11 // with the distribution. |
12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
15 // | 15 // |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
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: --turbo-deoptimization --noharmony-scoping | 28 // Flags: --turbo-deoptimization |
29 // Flags: --noharmony-classes --noharmony-object-literals | |
30 | 29 |
31 function CheckStrictMode(code, exception) { | 30 function CheckStrictMode(code, exception) { |
32 assertDoesNotThrow(code); | 31 assertDoesNotThrow(code); |
33 assertThrows("'use strict';\n" + code, exception); | 32 assertThrows("'use strict';\n" + code, exception); |
34 assertThrows('"use strict";\n' + code, exception); | 33 assertThrows('"use strict";\n' + code, exception); |
35 assertDoesNotThrow("\ | 34 assertDoesNotThrow("\ |
36 function outer() {\ | 35 function outer() {\ |
37 function inner() {\n" | 36 function inner() {\n" |
38 + code + | 37 + code + |
39 "\n}\ | 38 "\n}\ |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 CheckStrictMode("function strict() { var x = ++arguments; }", SyntaxError); | 279 CheckStrictMode("function strict() { var x = ++arguments; }", SyntaxError); |
281 | 280 |
282 // Prefix decrement with eval or arguments | 281 // Prefix decrement with eval or arguments |
283 CheckStrictMode("function strict() { --eval; }", SyntaxError); | 282 CheckStrictMode("function strict() { --eval; }", SyntaxError); |
284 CheckStrictMode("function strict() { --arguments; }", SyntaxError); | 283 CheckStrictMode("function strict() { --arguments; }", SyntaxError); |
285 CheckStrictMode("function strict() { print(--eval); }", SyntaxError); | 284 CheckStrictMode("function strict() { print(--eval); }", SyntaxError); |
286 CheckStrictMode("function strict() { print(--arguments); }", SyntaxError); | 285 CheckStrictMode("function strict() { print(--arguments); }", SyntaxError); |
287 CheckStrictMode("function strict() { var x = --eval; }", SyntaxError); | 286 CheckStrictMode("function strict() { var x = --eval; }", SyntaxError); |
288 CheckStrictMode("function strict() { var x = --arguments; }", SyntaxError); | 287 CheckStrictMode("function strict() { var x = --arguments; }", SyntaxError); |
289 | 288 |
290 // Use of const in strict mode is disallowed in anticipation of ES Harmony. | |
291 CheckStrictMode("const x = 0;", SyntaxError); | |
292 CheckStrictMode("for (const x = 0; false;) {}", SyntaxError); | |
293 CheckStrictMode("function strict() { const x = 0; }", SyntaxError); | |
294 | |
295 // Strict mode only allows functions in StatementList | |
296 CheckStrictMode("if (true) { function invalid() {} }", SyntaxError); | |
297 CheckStrictMode("for (;false;) { function invalid() {} }", SyntaxError); | |
298 CheckStrictMode("{ function invalid() {} }", SyntaxError); | |
299 CheckStrictMode("try { function invalid() {} } catch(e) {}", SyntaxError); | |
300 CheckStrictMode("try { } catch(e) { function invalid() {} }", SyntaxError); | |
301 CheckStrictMode("function outer() {{ function invalid() {} }}", SyntaxError); | |
302 | |
303 // Delete of an unqualified identifier | 289 // Delete of an unqualified identifier |
304 CheckStrictMode("delete unqualified;", SyntaxError); | 290 CheckStrictMode("delete unqualified;", SyntaxError); |
305 CheckStrictMode("function strict() { delete unqualified; }", SyntaxError); | 291 CheckStrictMode("function strict() { delete unqualified; }", SyntaxError); |
306 CheckStrictMode("function function_name() { delete function_name; }", | 292 CheckStrictMode("function function_name() { delete function_name; }", |
307 SyntaxError); | 293 SyntaxError); |
308 CheckStrictMode("function strict(parameter) { delete parameter; }", | 294 CheckStrictMode("function strict(parameter) { delete parameter; }", |
309 SyntaxError); | 295 SyntaxError); |
310 CheckStrictMode("function strict() { var variable; delete variable; }", | 296 CheckStrictMode("function strict() { var variable; delete variable; }", |
311 SyntaxError); | 297 SyntaxError); |
312 CheckStrictMode("var variable; delete variable;", SyntaxError); | 298 CheckStrictMode("var variable; delete variable;", SyntaxError); |
(...skipping 899 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1212 assertSame(null, test(i)); | 1198 assertSame(null, test(i)); |
1213 } | 1199 } |
1214 })(); | 1200 })(); |
1215 | 1201 |
1216 | 1202 |
1217 (function TestStrictModeEval() { | 1203 (function TestStrictModeEval() { |
1218 "use strict"; | 1204 "use strict"; |
1219 eval("var eval_local = 10;"); | 1205 eval("var eval_local = 10;"); |
1220 assertThrows(function() { return eval_local; }, ReferenceError); | 1206 assertThrows(function() { return eval_local; }, ReferenceError); |
1221 })(); | 1207 })(); |
OLD | NEW |