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

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

Issue 6246064: Issue 117 - strict mode and future reserved words (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 10 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
« src/preparser.cc ('K') | « src/token.h ('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
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 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 CheckStrictMode("function strict() { var x = --eval; }", SyntaxError); 264 CheckStrictMode("function strict() { var x = --eval; }", SyntaxError);
265 CheckStrictMode("function strict() { var x = --arguments; }", SyntaxError); 265 CheckStrictMode("function strict() { var x = --arguments; }", SyntaxError);
266 266
267 // Prefix unary operators other than delete, ++, -- are valid in strict mode 267 // Prefix unary operators other than delete, ++, -- are valid in strict mode
268 (function StrictModeUnaryOperators() { 268 (function StrictModeUnaryOperators() {
269 "use strict"; 269 "use strict";
270 var x = [void eval, typeof eval, +eval, -eval, ~eval, !eval]; 270 var x = [void eval, typeof eval, +eval, -eval, ~eval, !eval];
271 var y = [void arguments, typeof arguments, 271 var y = [void arguments, typeof arguments,
272 +arguments, -arguments, ~arguments, !arguments]; 272 +arguments, -arguments, ~arguments, !arguments];
273 })(); 273 })();
274
275 // 7.6.1.2 Future Reserved Words
276 var future_reserved_words = [
277 "class",
278 "enum",
279 "export",
280 "extends",
281 "import",
282 "super",
283 "implements",
284 "interface",
285 "let",
286 "package",
287 "private",
288 "protected",
289 "public",
290 "static",
291 "yield" ];
292
293 function testFutureReservedWord(word) {
294 // Simple use of each reserved word
295 CheckStrictMode("var " + word + " = 1;", SyntaxError);
296
297 // object literal properties
298 eval("var x = { " + word + " : 42 };");
299 eval("var x = { get " + word + " () {} };");
300 eval("var x = { set " + word + " (value) {} };");
301
302 // Function names and arguments, strict and non-strict contexts
303 CheckStrictMode("function " + word + " () {}", SyntaxError);
304 CheckStrictMode("function foo (" + word + ") {}", SyntaxError);
305 CheckStrictMode("function foo (" + word + ", " + word + ") {}", SyntaxError);
306 CheckStrictMode("function foo (a, " + word + ") {}", SyntaxError);
307 CheckStrictMode("function foo (" + word + ", a) {}", SyntaxError);
308 CheckStrictMode("function foo (a, " + word + ", b) {}", SyntaxError);
309 CheckStrictMode("var foo = function (" + word + ") {}", SyntaxError);
310
311 // Function names and arguments when the body is strict
312 assertThrows("function " + word + " () { 'use strict'; }", SyntaxError);
313 assertThrows("function foo (" + word + ") 'use strict'; {}", SyntaxError);
314 assertThrows("function foo (" + word + ", " + word + ") { 'use strict'; }", Sy ntaxError);
315 assertThrows("function foo (a, " + word + ") { 'use strict'; }", SyntaxError);
316 assertThrows("function foo (" + word + ", a) { 'use strict'; }", SyntaxError);
317 assertThrows("function foo (a, " + word + ", b) { 'use strict'; }", SyntaxErro r);
318 assertThrows("var foo = function (" + word + ") { 'use strict'; }", SyntaxErro r);
319
320 // get/set when the body is strict
321 eval("var x = { get " + word + " () { 'use strict'; } };");
322 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.
323 assertThrows("var x = { get foo(" + word + ") { 'use strict'; } };", SyntaxErr or);
324 assertThrows("var x = { set foo(" + word + ") { 'use strict'; } };", SyntaxErr or);
325 }
326
327 for (var i = 0; i < future_reserved_words.length; i++) {
328 testFutureReservedWord(future_reserved_words[i]);
329 }
330
331
OLDNEW
« src/preparser.cc ('K') | « src/token.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698