Chromium Code Reviews| 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 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 312 })(); | 312 })(); |
| 313 | 313 |
| 314 // Prefix unary operators other than delete, ++, -- are valid in strict mode | 314 // Prefix unary operators other than delete, ++, -- are valid in strict mode |
| 315 (function StrictModeUnaryOperators() { | 315 (function StrictModeUnaryOperators() { |
| 316 "use strict"; | 316 "use strict"; |
| 317 var x = [void eval, typeof eval, +eval, -eval, ~eval, !eval]; | 317 var x = [void eval, typeof eval, +eval, -eval, ~eval, !eval]; |
| 318 var y = [void arguments, typeof arguments, | 318 var y = [void arguments, typeof arguments, |
| 319 +arguments, -arguments, ~arguments, !arguments]; | 319 +arguments, -arguments, ~arguments, !arguments]; |
| 320 })(); | 320 })(); |
| 321 | 321 |
| 322 // 7.6.1.2 Future Reserved Words | 322 // 7.6.1.2 Future Reserved Words in strict mode |
| 323 var future_reserved_words = [ | 323 var future_strict_reserved_words = [ |
| 324 "class", | |
| 325 "enum", | |
| 326 "export", | |
| 327 "extends", | |
| 328 "import", | |
| 329 "super", | |
| 330 "implements", | 324 "implements", |
| 331 "interface", | 325 "interface", |
| 332 "let", | 326 "let", |
| 333 "package", | 327 "package", |
| 334 "private", | 328 "private", |
| 335 "protected", | 329 "protected", |
| 336 "public", | 330 "public", |
| 337 "static", | 331 "static", |
| 338 "yield" ]; | 332 "yield" ]; |
| 339 | 333 |
| 340 function testFutureReservedWord(word) { | 334 function testFutureStrictReservedWord(word) { |
| 341 // Simple use of each reserved word | 335 // Simple use of each reserved word |
| 342 CheckStrictMode("var " + word + " = 1;", SyntaxError); | 336 CheckStrictMode("var " + word + " = 1;", SyntaxError); |
| 337 CheckStrictMode("typeof (" + word + ");", SyntaxError); | |
| 343 | 338 |
| 344 // object literal properties | 339 // object literal properties |
| 345 eval("var x = { " + word + " : 42 };"); | 340 eval("var x = { " + word + " : 42 };"); |
| 346 eval("var x = { get " + word + " () {} };"); | 341 eval("var x = { get " + word + " () {} };"); |
| 347 eval("var x = { set " + word + " (value) {} };"); | 342 eval("var x = { set " + word + " (value) {} };"); |
| 348 | 343 |
| 349 // object literal with string literal property names | 344 // object literal with string literal property names |
| 350 eval("var x = { '" + word + "' : 42 };"); | 345 eval("var x = { '" + word + "' : 42 };"); |
| 351 eval("var x = { get '" + word + "' () { } };"); | 346 eval("var x = { get '" + word + "' () { } };"); |
| 352 eval("var x = { set '" + word + "' (value) { } };"); | 347 eval("var x = { set '" + word + "' (value) { } };"); |
| 353 eval("var x = { get '" + word + "' () { 'use strict'; } };"); | 348 eval("var x = { get '" + word + "' () { 'use strict'; } };"); |
| 354 eval("var x = { set '" + word + "' (value) { 'use strict'; } };"); | 349 eval("var x = { set '" + word + "' (value) { 'use strict'; } };"); |
| 355 | 350 |
| 356 // Function names and arguments, strict and non-strict contexts | 351 // Function names and arguments, strict and non-strict contexts |
| 357 CheckStrictMode("function " + word + " () {}", SyntaxError); | 352 CheckStrictMode("function " + word + " () {}", SyntaxError); |
| 358 CheckStrictMode("function foo (" + word + ") {}", SyntaxError); | 353 CheckStrictMode("function foo (" + word + ") {}", SyntaxError); |
| 359 CheckStrictMode("function foo (" + word + ", " + word + ") {}", SyntaxError); | 354 CheckStrictMode("function foo (" + word + ", " + word + ") {}", SyntaxError); |
| 360 CheckStrictMode("function foo (a, " + word + ") {}", SyntaxError); | 355 CheckStrictMode("function foo (a, " + word + ") {}", SyntaxError); |
| 361 CheckStrictMode("function foo (" + word + ", a) {}", SyntaxError); | 356 CheckStrictMode("function foo (" + word + ", a) {}", SyntaxError); |
| 362 CheckStrictMode("function foo (a, " + word + ", b) {}", SyntaxError); | 357 CheckStrictMode("function foo (a, " + word + ", b) {}", SyntaxError); |
| 363 CheckStrictMode("var foo = function (" + word + ") {}", SyntaxError); | 358 CheckStrictMode("var foo = function (" + word + ") {}", SyntaxError); |
| 364 | 359 |
| 365 // Function names and arguments when the body is strict | 360 // Function names and arguments when the body is strict |
| 366 assertThrows("function " + word + " () { 'use strict'; }", SyntaxError); | 361 assertThrows("function " + word + " () { 'use strict'; }", SyntaxError); |
| 367 assertThrows("function foo (" + word + ") 'use strict'; {}", SyntaxError); | 362 assertThrows("function foo (" + word + ") 'use strict'; {}", SyntaxError); |
|
Lasse Reichstein
2011/06/22 20:29:33
This is just a plain syntax error, unrelated to 'w
Steven
2011/06/24 11:34:59
Moved it outside of the loop.
On 2011/06/22 20:29:
| |
| 368 assertThrows("function foo (" + word + ", " + word + ") { 'use strict'; }", | 363 assertThrows("function foo (" + word + ", " + word + ") { 'use strict'; }", |
| 369 SyntaxError); | 364 SyntaxError); |
| 370 assertThrows("function foo (a, " + word + ") { 'use strict'; }", SyntaxError); | 365 assertThrows("function foo (a, " + word + ") { 'use strict'; }", SyntaxError); |
| 371 assertThrows("function foo (" + word + ", a) { 'use strict'; }", SyntaxError); | 366 assertThrows("function foo (" + word + ", a) { 'use strict'; }", SyntaxError); |
| 372 assertThrows("function foo (a, " + word + ", b) { 'use strict'; }", | 367 assertThrows("function foo (a, " + word + ", b) { 'use strict'; }", |
| 373 SyntaxError); | 368 SyntaxError); |
| 374 assertThrows("var foo = function (" + word + ") { 'use strict'; }", | 369 assertThrows("var foo = function (" + word + ") { 'use strict'; }", |
| 375 SyntaxError); | 370 SyntaxError); |
| 376 | 371 |
| 377 // get/set when the body is strict | 372 // get/set when the body is strict |
| 378 eval("var x = { get " + word + " () { 'use strict'; } };"); | 373 eval("var x = { get " + word + " () { 'use strict'; } };"); |
| 379 eval("var x = { set " + word + " (value) { 'use strict'; } };"); | 374 eval("var x = { set " + word + " (value) { 'use strict'; } };"); |
|
Lasse Reichstein
2011/06/22 20:29:33
Duplicates line 348 and 349.
Steven
2011/06/24 11:34:59
Lines 348-349 are slightly different because they
Lasse Reichstein
2011/06/24 12:38:04
Sounds fine.
| |
| 380 assertThrows("var x = { get foo(" + word + ") { 'use strict'; } };", | 375 assertThrows("var x = { get foo(" + word + ") { 'use strict'; } };", |
| 381 SyntaxError); | 376 SyntaxError); |
| 382 assertThrows("var x = { set foo(" + word + ") { 'use strict'; } };", | 377 assertThrows("var x = { set foo(" + word + ") { 'use strict'; } };", |
| 383 SyntaxError); | 378 SyntaxError); |
| 384 } | 379 } |
| 385 | 380 |
| 386 for (var i = 0; i < future_reserved_words.length; i++) { | 381 for (var i = 0; i < future_strict_reserved_words.length; i++) { |
| 387 testFutureReservedWord(future_reserved_words[i]); | 382 testFutureStrictReservedWord(future_strict_reserved_words[i]); |
| 388 } | 383 } |
| 389 | 384 |
| 390 function testAssignToUndefined(test, should_throw) { | 385 function testAssignToUndefined(test, should_throw) { |
| 391 try { | 386 try { |
| 392 test(); | 387 test(); |
| 393 } catch (e) { | 388 } catch (e) { |
| 394 assertTrue(should_throw, "strict mode"); | 389 assertTrue(should_throw, "strict mode"); |
| 395 assertInstanceof(e, ReferenceError, "strict mode"); | 390 assertInstanceof(e, ReferenceError, "strict mode"); |
| 396 return; | 391 return; |
| 397 } | 392 } |
| (...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1181 assertEquals(test(i), true); | 1176 assertEquals(test(i), true); |
| 1182 } | 1177 } |
| 1183 })(); | 1178 })(); |
| 1184 | 1179 |
| 1185 | 1180 |
| 1186 (function TestStrictModeEval() { | 1181 (function TestStrictModeEval() { |
| 1187 "use strict"; | 1182 "use strict"; |
| 1188 eval("var eval_local = 10;"); | 1183 eval("var eval_local = 10;"); |
| 1189 assertThrows(function() { return eval_local; }, ReferenceError); | 1184 assertThrows(function() { return eval_local; }, ReferenceError); |
| 1190 })(); | 1185 })(); |
| OLD | NEW |