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

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

Issue 6364008: Strict mode: function constructor tests. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: 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 | « no previous file | 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
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 26 matching lines...) Expand all
37 }"); 37 }");
38 assertThrows("\ 38 assertThrows("\
39 function outer() {\ 39 function outer() {\
40 'use strict';\ 40 'use strict';\
41 function inner() {\n" 41 function inner() {\n"
42 + code + 42 + code +
43 "\n}\ 43 "\n}\
44 }", exception); 44 }", exception);
45 } 45 }
46 46
47 function CheckFunctionConstructorStrictMode() {
48 var args = [];
49 for (var i = 0; i < arguments.length; i ++) {
50 args[i] = arguments[i];
51 }
52 // Create non-strict function. No exception.
53 args[arguments.length] = "";
54 assertDoesNotThrow(function() {
55 Function.apply(this, args);
56 });
57 // Create strict mode function. Exception expected.
58 args[arguments.length] = "'use strict';";
59 assertThrows(function() {
60 Function.apply(this, args);
61 }, SyntaxError);
62 }
63
47 // Incorrect 'use strict' directive. 64 // Incorrect 'use strict' directive.
48 function UseStrictEscape() { 65 function UseStrictEscape() {
49 "use\\x20strict"; 66 "use\\x20strict";
50 with ({}) {}; 67 with ({}) {};
51 } 68 }
52 69
53 // 'use strict' in non-directive position. 70 // 'use strict' in non-directive position.
54 function UseStrictNonDirective() { 71 function UseStrictNonDirective() {
55 void(0); 72 void(0);
56 "use strict"; 73 "use strict";
(...skipping 26 matching lines...) Expand all
83 100
84 // Property accessor parameter named 'eval'. 101 // Property accessor parameter named 'eval'.
85 CheckStrictMode("var o = { set foo(eval) {} }", SyntaxError) 102 CheckStrictMode("var o = { set foo(eval) {} }", SyntaxError)
86 103
87 // Property accessor parameter named 'arguments'. 104 // Property accessor parameter named 'arguments'.
88 CheckStrictMode("var o = { set foo(arguments) {} }", SyntaxError) 105 CheckStrictMode("var o = { set foo(arguments) {} }", SyntaxError)
89 106
90 // Duplicate function parameter name. 107 // Duplicate function parameter name.
91 CheckStrictMode("function foo(a, b, c, d, b) {}", SyntaxError) 108 CheckStrictMode("function foo(a, b, c, d, b) {}", SyntaxError)
92 109
110 // Function constructor: eval parameter name.
111 CheckFunctionConstructorStrictMode("eval")
112
113 // Function constructor: arguments parameter name.
114 CheckFunctionConstructorStrictMode("arguments")
115
116 // Function constructor: duplicate parameter name.
117 CheckFunctionConstructorStrictMode("a", "b", "c", "b")
118 CheckFunctionConstructorStrictMode("a,b,c,b")
119
93 // catch(eval) 120 // catch(eval)
94 CheckStrictMode("try{}catch(eval){};", SyntaxError) 121 CheckStrictMode("try{}catch(eval){};", SyntaxError)
95 122
96 // catch(arguments) 123 // catch(arguments)
97 CheckStrictMode("try{}catch(arguments){};", SyntaxError) 124 CheckStrictMode("try{}catch(arguments){};", SyntaxError)
98 125
99 // var eval 126 // var eval
100 CheckStrictMode("var eval;", SyntaxError) 127 CheckStrictMode("var eval;", SyntaxError)
101 128
102 // var arguments 129 // var arguments
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 CheckStrictMode("var x = { 3.14 : 1, '3.14' : 2 };", SyntaxError) 165 CheckStrictMode("var x = { 3.14 : 1, '3.14' : 2 };", SyntaxError)
139 CheckStrictMode("var x = { 123: 1, 123.00000000000000000000000000000000000000000 000000000000000000000000001 : 2 }", SyntaxError) 166 CheckStrictMode("var x = { 123: 1, 123.00000000000000000000000000000000000000000 000000000000000000000000001 : 2 }", SyntaxError)
140 167
141 // Non-conflicting data properties. 168 // Non-conflicting data properties.
142 function StrictModeNonDuplicate() { 169 function StrictModeNonDuplicate() {
143 "use strict"; 170 "use strict";
144 var x = { 123 : 1, "0123" : 2 }; 171 var x = { 123 : 1, "0123" : 2 };
145 var x = { 123: 1, '123.0000000000000000000000000000000000000000000000000000000 0000000000001' : 2 } 172 var x = { 123: 1, '123.0000000000000000000000000000000000000000000000000000000 0000000000001' : 2 }
146 } 173 }
147 174
148 //CheckStrictMode("", SyntaxError)
149
150 // Two getters (non-strict) 175 // Two getters (non-strict)
151 assertThrows("var x = { get foo() { }, get foo() { } };", SyntaxError) 176 assertThrows("var x = { get foo() { }, get foo() { } };", SyntaxError)
152 assertThrows("var x = { get foo(){}, get 'foo'(){}};", SyntaxError) 177 assertThrows("var x = { get foo(){}, get 'foo'(){}};", SyntaxError)
153 assertThrows("var x = { get 12(){}, get '12'(){}};", SyntaxError) 178 assertThrows("var x = { get 12(){}, get '12'(){}};", SyntaxError)
154 179
155 // Two setters (non-strict) 180 // Two setters (non-strict)
156 assertThrows("var x = { set foo(v) { }, set foo(v) { } };", SyntaxError) 181 assertThrows("var x = { set foo(v) { }, set foo(v) { } };", SyntaxError)
157 assertThrows("var x = { set foo(v) { }, set 'foo'(v) { } };", SyntaxError) 182 assertThrows("var x = { set foo(v) { }, set 'foo'(v) { } };", SyntaxError)
158 assertThrows("var x = { set 13(v) { }, set '13'(v) { } };", SyntaxError) 183 assertThrows("var x = { set 13(v) { }, set '13'(v) { } };", SyntaxError)
159 184
(...skipping 11 matching lines...) Expand all
171 assertThrows("var x = { '12': 1, set '12'(v){}};", SyntaxError); 196 assertThrows("var x = { '12': 1, set '12'(v){}};", SyntaxError);
172 assertThrows("var x = { '12': 1, set 12(v){}};", SyntaxError); 197 assertThrows("var x = { '12': 1, set 12(v){}};", SyntaxError);
173 198
174 // Getter and data (non-strict) 199 // Getter and data (non-strict)
175 assertThrows("var x = { foo: 'data', get foo() { } };", SyntaxError) 200 assertThrows("var x = { foo: 'data', get foo() { } };", SyntaxError)
176 assertThrows("var x = { get foo() { }, foo: 'data' };", SyntaxError) 201 assertThrows("var x = { get foo() { }, foo: 'data' };", SyntaxError)
177 assertThrows("var x = { 'foo': 'data', get foo() { } };", SyntaxError) 202 assertThrows("var x = { 'foo': 'data', get foo() { } };", SyntaxError)
178 assertThrows("var x = { get 'foo'() { }, 'foo': 'data' };", SyntaxError) 203 assertThrows("var x = { get 'foo'() { }, 'foo': 'data' };", SyntaxError)
179 assertThrows("var x = { '12': 1, get '12'(){}};", SyntaxError); 204 assertThrows("var x = { '12': 1, get '12'(){}};", SyntaxError);
180 assertThrows("var x = { '12': 1, get 12(){}};", SyntaxError); 205 assertThrows("var x = { '12': 1, get 12(){}};", SyntaxError);
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698