Chromium Code Reviews| Index: test/mjsunit/strict-mode.js |
| diff --git a/test/mjsunit/strict-mode.js b/test/mjsunit/strict-mode.js |
| index 3cb6d329237b9aa01ff7fda137b4f3725460574c..3f2811173be6341db7341a325025ae238283c963 100644 |
| --- a/test/mjsunit/strict-mode.js |
| +++ b/test/mjsunit/strict-mode.js |
| @@ -271,3 +271,61 @@ CheckStrictMode("function strict() { var x = --arguments; }", SyntaxError); |
| var y = [void arguments, typeof arguments, |
| +arguments, -arguments, ~arguments, !arguments]; |
| })(); |
| + |
| +// 7.6.1.2 Future Reserved Words |
| +var future_reserved_words = [ |
| + "class", |
| + "enum", |
| + "export", |
| + "extends", |
| + "import", |
| + "super", |
| + "implements", |
| + "interface", |
| + "let", |
| + "package", |
| + "private", |
| + "protected", |
| + "public", |
| + "static", |
| + "yield" ]; |
| + |
| +function testFutureReservedWord(word) { |
| + // Simple use of each reserved word |
| + CheckStrictMode("var " + word + " = 1;", SyntaxError); |
| + |
| + // object literal properties |
| + eval("var x = { " + word + " : 42 };"); |
| + eval("var x = { get " + word + " () {} };"); |
| + eval("var x = { set " + word + " (value) {} };"); |
| + |
| + // Function names and arguments, strict and non-strict contexts |
| + CheckStrictMode("function " + word + " () {}", SyntaxError); |
| + CheckStrictMode("function foo (" + word + ") {}", SyntaxError); |
| + CheckStrictMode("function foo (" + word + ", " + word + ") {}", SyntaxError); |
| + CheckStrictMode("function foo (a, " + word + ") {}", SyntaxError); |
| + CheckStrictMode("function foo (" + word + ", a) {}", SyntaxError); |
| + CheckStrictMode("function foo (a, " + word + ", b) {}", SyntaxError); |
| + CheckStrictMode("var foo = function (" + word + ") {}", SyntaxError); |
| + |
| + // Function names and arguments when the body is strict |
| + assertThrows("function " + word + " () { 'use strict'; }", SyntaxError); |
| + assertThrows("function foo (" + word + ") 'use strict'; {}", SyntaxError); |
| + assertThrows("function foo (" + word + ", " + word + ") { 'use strict'; }", SyntaxError); |
| + assertThrows("function foo (a, " + word + ") { 'use strict'; }", SyntaxError); |
| + assertThrows("function foo (" + word + ", a) { 'use strict'; }", SyntaxError); |
| + assertThrows("function foo (a, " + word + ", b) { 'use strict'; }", SyntaxError); |
| + assertThrows("var foo = function (" + word + ") { 'use strict'; }", SyntaxError); |
| + |
| + // get/set when the body is strict |
| + eval("var x = { get " + word + " () { 'use strict'; } };"); |
| + eval("var x = { set " + word + " (value) { 'use strict'; } };"); |
|
Lasse Reichstein
2011/02/03 11:55:07
Try with the word as a string literal as well. It
Peter Hallam
2011/02/04 18:32:41
Done.
|
| + assertThrows("var x = { get foo(" + word + ") { 'use strict'; } };", SyntaxError); |
| + assertThrows("var x = { set foo(" + word + ") { 'use strict'; } };", SyntaxError); |
| +} |
| + |
| +for (var i = 0; i < future_reserved_words.length; i++) { |
| + testFutureReservedWord(future_reserved_words[i]); |
| +} |
| + |
| + |