Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(207)

Side by Side Diff: test/mjsunit/strict-mode.js

Issue 6144005: Early draft of strict mode (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: CR Feedback + Tests. Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« src/scopes.cc ('K') | « src/scopes.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
27
28 function CheckStrictMode(code, exception) {
29 assertDoesNotThrow(code);
30 assertThrows("'use strict';\n" + code, exception);
31 assertThrows('"use strict";\n' + code, exception);
32 assertDoesNotThrow("\
33 function outer() {\
34 function inner() {\n"
35 + code +
36 "\n}\
37 }");
38 assertThrows("\
39 function outer() {\
40 'use strict';\
41 function inner() {\n"
42 + code +
43 "\n}\
44 }", exception);
45 }
46
47 // Incorrect 'use strict' directive.
48 function UseStrictEscape() {
49 "use\\x20strict";
50 with ({}) {};
51 }
52
53 // 'use strict' in non-directive position.
54 function UseStrictNonDirective() {
55 void(0);
56 "use strict";
57 with ({}) {};
58 }
Lasse Reichstein 2011/01/18 13:40:59 How about adding a case where there are more direc
Martin Maly 2011/01/18 16:46:38 Done.
59
60 // 'with' disallowed in strict mode.
61 CheckStrictMode("with({}) {}", SyntaxError);
62
63 // Function named 'eval'.
64 CheckStrictMode("function eval() {}", SyntaxError)
65
66 // Function named 'arguments'.
67 CheckStrictMode("function arguments() {}", SyntaxError)
68
69 // Function parameter named 'eval'.
70 CheckStrictMode("function foo(a, b, eval, c, d) {}", SyntaxError)
71
72 // Function parameter named 'arguments'.
73 CheckStrictMode("function foo(a, b, arguments, c, d) {}", SyntaxError)
74
75 // Duplicate function parameter name.
76 CheckStrictMode("function foo(a, b, c, d, b) {}", SyntaxError)
77
78 // catch(eval)
79 CheckStrictMode("try{}catch(eval){};", SyntaxError)
80
81 // catch(arguments)
82 CheckStrictMode("try{}catch(arguments){};", SyntaxError)
83
84 // var eval
85 CheckStrictMode("var eval;", SyntaxError)
86
87 // var arguments
88 CheckStrictMode("var arguments;", SyntaxError)
Lasse Reichstein 2011/01/18 13:40:59 Test that we catches: var o = {set foo(eval) {}};
Martin Maly 2011/01/18 16:46:38 Done.
OLDNEW
« src/scopes.cc ('K') | « src/scopes.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698