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

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: Removing parameter validation; 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
« no previous file with comments | « src/parser.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 }
59
60 // Multiple directives, including "use strict".
61 assertThrows('\
62 "directive 1";\
63 "another directive";\
64 "use strict";\
65 "directive after strict";\
66 "and one more";\
67 with({}) {}', SyntaxError);
68
69 // 'with' disallowed in strict mode.
70 CheckStrictMode("with({}) {}", SyntaxError);
71
72 // Function named 'eval'.
73 CheckStrictMode("function eval() {}", SyntaxError)
74
75 // Function named 'arguments'.
76 CheckStrictMode("function arguments() {}", SyntaxError)
77
78 // Function parameter named 'eval'.
79 //CheckStrictMode("function foo(a, b, eval, c, d) {}", SyntaxError)
80
81 // Function parameter named 'arguments'.
82 //CheckStrictMode("function foo(a, b, arguments, c, d) {}", SyntaxError)
83
84 // Property accessor parameter named 'eval'.
85 //CheckStrictMode("var o = { set foo(eval) {} }", SyntaxError)
86
87 // Property accessor parameter named 'arguments'.
88 //CheckStrictMode("var o = { set foo(arguments) {} }", SyntaxError)
89
90 // Duplicate function parameter name.
91 //CheckStrictMode("function foo(a, b, c, d, b) {}", SyntaxError)
92
93 // catch(eval)
94 CheckStrictMode("try{}catch(eval){};", SyntaxError)
95
96 // catch(arguments)
97 CheckStrictMode("try{}catch(arguments){};", SyntaxError)
98
99 // var eval
100 CheckStrictMode("var eval;", SyntaxError)
101
102 // var arguments
103 CheckStrictMode("var arguments;", SyntaxError)
104
105 // Strict mode applies to the function in which the directive is used..
106 //assertThrows('\
107 //function foo(eval) {\
108 // "use strict";\
109 //}', SyntaxError);
110
111 // Strict mode doesn't affect the outer stop of strict code.
112 function NotStrict(eval) {
113 function Strict() {
114 "use strict";
115 }
116 with ({}) {};
117 }
OLDNEW
« no previous file with comments | « src/parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698