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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 "octal\\032directive";\ | 162 "octal\\032directive";\ |
163 "use strict";\ | 163 "use strict";\ |
164 }', SyntaxError); | 164 }', SyntaxError); |
165 | 165 |
166 // Duplicate data properties. | 166 // Duplicate data properties. |
167 CheckStrictMode("var x = { dupe : 1, nondupe: 3, dupe : 2 };", SyntaxError); | 167 CheckStrictMode("var x = { dupe : 1, nondupe: 3, dupe : 2 };", SyntaxError); |
168 CheckStrictMode("var x = { '1234' : 1, '2345' : 2, '1234' : 3 };", SyntaxError); | 168 CheckStrictMode("var x = { '1234' : 1, '2345' : 2, '1234' : 3 };", SyntaxError); |
169 CheckStrictMode("var x = { '1234' : 1, '2345' : 2, 1234 : 3 };", SyntaxError); | 169 CheckStrictMode("var x = { '1234' : 1, '2345' : 2, 1234 : 3 };", SyntaxError); |
170 CheckStrictMode("var x = { 3.14 : 1, 2.71 : 2, 3.14 : 3 };", SyntaxError); | 170 CheckStrictMode("var x = { 3.14 : 1, 2.71 : 2, 3.14 : 3 };", SyntaxError); |
171 CheckStrictMode("var x = { 3.14 : 1, '3.14' : 2 };", SyntaxError); | 171 CheckStrictMode("var x = { 3.14 : 1, '3.14' : 2 };", SyntaxError); |
172 CheckStrictMode("var x = { 123: 1, 123.00000000000000000000000000000000000000000
000000000000000000000000001 : 2 }", SyntaxError); | 172 CheckStrictMode("var x = { \ |
| 173 123: 1, \ |
| 174 123.00000000000000000000000000000000000000000000000000000000000000000001: 2 \ |
| 175 }", SyntaxError); |
173 | 176 |
174 // Non-conflicting data properties. | 177 // Non-conflicting data properties. |
175 (function StrictModeNonDuplicate() { | 178 (function StrictModeNonDuplicate() { |
176 "use strict"; | 179 "use strict"; |
177 var x = { 123 : 1, "0123" : 2 }; | 180 var x = { 123 : 1, "0123" : 2 }; |
178 var x = { 123: 1, '123.0000000000000000000000000000000000000000000000000000000
0000000000001' : 2 } | 181 var x = { |
| 182 123: 1, |
| 183 '123.00000000000000000000000000000000000000000000000000000000000000000001': |
| 184 2 |
| 185 }; |
179 })(); | 186 })(); |
180 | 187 |
181 // Two getters (non-strict) | 188 // Two getters (non-strict) |
182 assertThrows("var x = { get foo() { }, get foo() { } };", SyntaxError); | 189 assertThrows("var x = { get foo() { }, get foo() { } };", SyntaxError); |
183 assertThrows("var x = { get foo(){}, get 'foo'(){}};", SyntaxError); | 190 assertThrows("var x = { get foo(){}, get 'foo'(){}};", SyntaxError); |
184 assertThrows("var x = { get 12(){}, get '12'(){}};", SyntaxError); | 191 assertThrows("var x = { get 12(){}, get '12'(){}};", SyntaxError); |
185 | 192 |
186 // Two setters (non-strict) | 193 // Two setters (non-strict) |
187 assertThrows("var x = { set foo(v) { }, set foo(v) { } };", SyntaxError); | 194 assertThrows("var x = { set foo(v) { }, set foo(v) { } };", SyntaxError); |
188 assertThrows("var x = { set foo(v) { }, set 'foo'(v) { } };", SyntaxError); | 195 assertThrows("var x = { set foo(v) { }, set 'foo'(v) { } };", SyntaxError); |
(...skipping 18 matching lines...) Expand all Loading... |
207 assertThrows("var x = { get foo() { }, foo: 'data' };", SyntaxError); | 214 assertThrows("var x = { get foo() { }, foo: 'data' };", SyntaxError); |
208 assertThrows("var x = { 'foo': 'data', get foo() { } };", SyntaxError); | 215 assertThrows("var x = { 'foo': 'data', get foo() { } };", SyntaxError); |
209 assertThrows("var x = { get 'foo'() { }, 'foo': 'data' };", SyntaxError); | 216 assertThrows("var x = { get 'foo'() { }, 'foo': 'data' };", SyntaxError); |
210 assertThrows("var x = { '12': 1, get '12'(){}};", SyntaxError); | 217 assertThrows("var x = { '12': 1, get '12'(){}};", SyntaxError); |
211 assertThrows("var x = { '12': 1, get 12(){}};", SyntaxError); | 218 assertThrows("var x = { '12': 1, get 12(){}};", SyntaxError); |
212 | 219 |
213 // Assignment to eval or arguments | 220 // Assignment to eval or arguments |
214 CheckStrictMode("function strict() { eval = undefined; }", SyntaxError); | 221 CheckStrictMode("function strict() { eval = undefined; }", SyntaxError); |
215 CheckStrictMode("function strict() { arguments = undefined; }", SyntaxError); | 222 CheckStrictMode("function strict() { arguments = undefined; }", SyntaxError); |
216 CheckStrictMode("function strict() { print(eval = undefined); }", SyntaxError); | 223 CheckStrictMode("function strict() { print(eval = undefined); }", SyntaxError); |
217 CheckStrictMode("function strict() { print(arguments = undefined); }", SyntaxErr
or); | 224 CheckStrictMode("function strict() { print(arguments = undefined); }", |
| 225 SyntaxError); |
218 CheckStrictMode("function strict() { var x = eval = undefined; }", SyntaxError); | 226 CheckStrictMode("function strict() { var x = eval = undefined; }", SyntaxError); |
219 CheckStrictMode("function strict() { var x = arguments = undefined; }", SyntaxEr
ror); | 227 CheckStrictMode("function strict() { var x = arguments = undefined; }", |
| 228 SyntaxError); |
220 | 229 |
221 // Compound assignment to eval or arguments | 230 // Compound assignment to eval or arguments |
222 CheckStrictMode("function strict() { eval *= undefined; }", SyntaxError); | 231 CheckStrictMode("function strict() { eval *= undefined; }", SyntaxError); |
223 CheckStrictMode("function strict() { arguments /= undefined; }", SyntaxError); | 232 CheckStrictMode("function strict() { arguments /= undefined; }", SyntaxError); |
224 CheckStrictMode("function strict() { print(eval %= undefined); }", SyntaxError); | 233 CheckStrictMode("function strict() { print(eval %= undefined); }", SyntaxError); |
225 CheckStrictMode("function strict() { print(arguments %= undefined); }", SyntaxEr
ror); | 234 CheckStrictMode("function strict() { print(arguments %= undefined); }", |
226 CheckStrictMode("function strict() { var x = eval += undefined; }", SyntaxError)
; | 235 SyntaxError); |
227 CheckStrictMode("function strict() { var x = arguments -= undefined; }", SyntaxE
rror); | 236 CheckStrictMode("function strict() { var x = eval += undefined; }", |
| 237 SyntaxError); |
| 238 CheckStrictMode("function strict() { var x = arguments -= undefined; }", |
| 239 SyntaxError); |
228 CheckStrictMode("function strict() { eval <<= undefined; }", SyntaxError); | 240 CheckStrictMode("function strict() { eval <<= undefined; }", SyntaxError); |
229 CheckStrictMode("function strict() { arguments >>= undefined; }", SyntaxError); | 241 CheckStrictMode("function strict() { arguments >>= undefined; }", SyntaxError); |
230 CheckStrictMode("function strict() { print(eval >>>= undefined); }", SyntaxError
); | 242 CheckStrictMode("function strict() { print(eval >>>= undefined); }", |
231 CheckStrictMode("function strict() { print(arguments &= undefined); }", SyntaxEr
ror); | 243 SyntaxError); |
232 CheckStrictMode("function strict() { var x = eval ^= undefined; }", SyntaxError)
; | 244 CheckStrictMode("function strict() { print(arguments &= undefined); }", |
233 CheckStrictMode("function strict() { var x = arguments |= undefined; }", SyntaxE
rror); | 245 SyntaxError); |
| 246 CheckStrictMode("function strict() { var x = eval ^= undefined; }", |
| 247 SyntaxError); |
| 248 CheckStrictMode("function strict() { var x = arguments |= undefined; }", |
| 249 SyntaxError); |
234 | 250 |
235 // Postfix increment with eval or arguments | 251 // Postfix increment with eval or arguments |
236 CheckStrictMode("function strict() { eval++; }", SyntaxError); | 252 CheckStrictMode("function strict() { eval++; }", SyntaxError); |
237 CheckStrictMode("function strict() { arguments++; }", SyntaxError); | 253 CheckStrictMode("function strict() { arguments++; }", SyntaxError); |
238 CheckStrictMode("function strict() { print(eval++); }", SyntaxError); | 254 CheckStrictMode("function strict() { print(eval++); }", SyntaxError); |
239 CheckStrictMode("function strict() { print(arguments++); }", SyntaxError); | 255 CheckStrictMode("function strict() { print(arguments++); }", SyntaxError); |
240 CheckStrictMode("function strict() { var x = eval++; }", SyntaxError); | 256 CheckStrictMode("function strict() { var x = eval++; }", SyntaxError); |
241 CheckStrictMode("function strict() { var x = arguments++; }", SyntaxError); | 257 CheckStrictMode("function strict() { var x = arguments++; }", SyntaxError); |
242 | 258 |
243 // Postfix decrement with eval or arguments | 259 // Postfix decrement with eval or arguments |
(...skipping 13 matching lines...) Expand all Loading... |
257 CheckStrictMode("function strict() { var x = ++arguments; }", SyntaxError); | 273 CheckStrictMode("function strict() { var x = ++arguments; }", SyntaxError); |
258 | 274 |
259 // Prefix decrement with eval or arguments | 275 // Prefix decrement with eval or arguments |
260 CheckStrictMode("function strict() { --eval; }", SyntaxError); | 276 CheckStrictMode("function strict() { --eval; }", SyntaxError); |
261 CheckStrictMode("function strict() { --arguments; }", SyntaxError); | 277 CheckStrictMode("function strict() { --arguments; }", SyntaxError); |
262 CheckStrictMode("function strict() { print(--eval); }", SyntaxError); | 278 CheckStrictMode("function strict() { print(--eval); }", SyntaxError); |
263 CheckStrictMode("function strict() { print(--arguments); }", SyntaxError); | 279 CheckStrictMode("function strict() { print(--arguments); }", SyntaxError); |
264 CheckStrictMode("function strict() { var x = --eval; }", SyntaxError); | 280 CheckStrictMode("function strict() { var x = --eval; }", SyntaxError); |
265 CheckStrictMode("function strict() { var x = --arguments; }", SyntaxError); | 281 CheckStrictMode("function strict() { var x = --arguments; }", SyntaxError); |
266 | 282 |
| 283 // Delete of an unqialified identifier |
| 284 CheckStrictMode("delete unqualified;", SyntaxError); |
| 285 CheckStrictMode("function strict() { delete unqualified; }", SyntaxError); |
| 286 CheckStrictMode("function function_name() { delete function_name; }", |
| 287 SyntaxError); |
| 288 CheckStrictMode("function strict(parameter) { delete parameter; }", |
| 289 SyntaxError); |
| 290 CheckStrictMode("function strict() { var variable; delete variable; }", |
| 291 SyntaxError); |
| 292 CheckStrictMode("var variable; delete variable;", SyntaxError); |
| 293 |
267 // Prefix unary operators other than delete, ++, -- are valid in strict mode | 294 // Prefix unary operators other than delete, ++, -- are valid in strict mode |
268 (function StrictModeUnaryOperators() { | 295 (function StrictModeUnaryOperators() { |
269 "use strict"; | 296 "use strict"; |
270 var x = [void eval, typeof eval, +eval, -eval, ~eval, !eval]; | 297 var x = [void eval, typeof eval, +eval, -eval, ~eval, !eval]; |
271 var y = [void arguments, typeof arguments, | 298 var y = [void arguments, typeof arguments, |
272 +arguments, -arguments, ~arguments, !arguments]; | 299 +arguments, -arguments, ~arguments, !arguments]; |
273 })(); | 300 })(); |
274 | 301 |
275 // 7.6.1.2 Future Reserved Words | 302 // 7.6.1.2 Future Reserved Words |
276 var future_reserved_words = [ | 303 var future_reserved_words = [ |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 CheckStrictMode("function foo (" + word + ") {}", SyntaxError); | 338 CheckStrictMode("function foo (" + word + ") {}", SyntaxError); |
312 CheckStrictMode("function foo (" + word + ", " + word + ") {}", SyntaxError); | 339 CheckStrictMode("function foo (" + word + ", " + word + ") {}", SyntaxError); |
313 CheckStrictMode("function foo (a, " + word + ") {}", SyntaxError); | 340 CheckStrictMode("function foo (a, " + word + ") {}", SyntaxError); |
314 CheckStrictMode("function foo (" + word + ", a) {}", SyntaxError); | 341 CheckStrictMode("function foo (" + word + ", a) {}", SyntaxError); |
315 CheckStrictMode("function foo (a, " + word + ", b) {}", SyntaxError); | 342 CheckStrictMode("function foo (a, " + word + ", b) {}", SyntaxError); |
316 CheckStrictMode("var foo = function (" + word + ") {}", SyntaxError); | 343 CheckStrictMode("var foo = function (" + word + ") {}", SyntaxError); |
317 | 344 |
318 // Function names and arguments when the body is strict | 345 // Function names and arguments when the body is strict |
319 assertThrows("function " + word + " () { 'use strict'; }", SyntaxError); | 346 assertThrows("function " + word + " () { 'use strict'; }", SyntaxError); |
320 assertThrows("function foo (" + word + ") 'use strict'; {}", SyntaxError); | 347 assertThrows("function foo (" + word + ") 'use strict'; {}", SyntaxError); |
321 assertThrows("function foo (" + word + ", " + word + ") { 'use strict'; }", Sy
ntaxError); | 348 assertThrows("function foo (" + word + ", " + word + ") { 'use strict'; }", |
| 349 SyntaxError); |
322 assertThrows("function foo (a, " + word + ") { 'use strict'; }", SyntaxError); | 350 assertThrows("function foo (a, " + word + ") { 'use strict'; }", SyntaxError); |
323 assertThrows("function foo (" + word + ", a) { 'use strict'; }", SyntaxError); | 351 assertThrows("function foo (" + word + ", a) { 'use strict'; }", SyntaxError); |
324 assertThrows("function foo (a, " + word + ", b) { 'use strict'; }", SyntaxErro
r); | 352 assertThrows("function foo (a, " + word + ", b) { 'use strict'; }", |
325 assertThrows("var foo = function (" + word + ") { 'use strict'; }", SyntaxErro
r); | 353 SyntaxError); |
| 354 assertThrows("var foo = function (" + word + ") { 'use strict'; }", |
| 355 SyntaxError); |
326 | 356 |
327 // get/set when the body is strict | 357 // get/set when the body is strict |
328 eval("var x = { get " + word + " () { 'use strict'; } };"); | 358 eval("var x = { get " + word + " () { 'use strict'; } };"); |
329 eval("var x = { set " + word + " (value) { 'use strict'; } };"); | 359 eval("var x = { set " + word + " (value) { 'use strict'; } };"); |
330 assertThrows("var x = { get foo(" + word + ") { 'use strict'; } };", SyntaxErr
or); | 360 assertThrows("var x = { get foo(" + word + ") { 'use strict'; } };", |
331 assertThrows("var x = { set foo(" + word + ") { 'use strict'; } };", SyntaxErr
or); | 361 SyntaxError); |
| 362 assertThrows("var x = { set foo(" + word + ") { 'use strict'; } };", |
| 363 SyntaxError); |
332 } | 364 } |
333 | 365 |
334 for (var i = 0; i < future_reserved_words.length; i++) { | 366 for (var i = 0; i < future_reserved_words.length; i++) { |
335 testFutureReservedWord(future_reserved_words[i]); | 367 testFutureReservedWord(future_reserved_words[i]); |
336 } | 368 } |
337 | 369 |
338 function testAssignToUndefined(should_throw) { | 370 function testAssignToUndefined(should_throw) { |
339 "use strict"; | 371 "use strict"; |
340 try { | 372 try { |
341 possibly_undefined_variable_for_strict_mode_test = "should throw?"; | 373 possibly_undefined_variable_for_strict_mode_test = "should throw?"; |
(...skipping 25 matching lines...) Expand all Loading... |
367 for (var i = 0; i < n; i ++) { f(); } | 399 for (var i = 0; i < n; i ++) { f(); } |
368 } | 400 } |
369 | 401 |
370 repeat(10, function() { testAssignToUndefined(true); }); | 402 repeat(10, function() { testAssignToUndefined(true); }); |
371 possibly_undefined_variable_for_strict_mode_test = "value"; | 403 possibly_undefined_variable_for_strict_mode_test = "value"; |
372 repeat(10, function() { testAssignToUndefined(false); }); | 404 repeat(10, function() { testAssignToUndefined(false); }); |
373 delete possibly_undefined_variable_for_strict_mode_test; | 405 delete possibly_undefined_variable_for_strict_mode_test; |
374 repeat(10, function() { testAssignToUndefined(true); }); | 406 repeat(10, function() { testAssignToUndefined(true); }); |
375 possibly_undefined_variable_for_strict_mode_test = undefined; | 407 possibly_undefined_variable_for_strict_mode_test = undefined; |
376 repeat(10, function() { testAssignToUndefined(false); }); | 408 repeat(10, function() { testAssignToUndefined(false); }); |
OLD | NEW |