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

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: Address code review comments 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
« no previous file with comments | « 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 // object literal with string literal property names
303 eval("var x = { '" + word + "' : 42 };");
304 eval("var x = { get '" + word + "' () { } };");
305 eval("var x = { set '" + word + "' (value) { } };");
306 eval("var x = { get '" + word + "' () { 'use strict'; } };");
307 eval("var x = { set '" + word + "' (value) { 'use strict'; } };");
308
309 // Function names and arguments, strict and non-strict contexts
310 CheckStrictMode("function " + word + " () {}", SyntaxError);
311 CheckStrictMode("function foo (" + word + ") {}", SyntaxError);
312 CheckStrictMode("function foo (" + word + ", " + word + ") {}", SyntaxError);
313 CheckStrictMode("function foo (a, " + word + ") {}", SyntaxError);
314 CheckStrictMode("function foo (" + word + ", a) {}", SyntaxError);
315 CheckStrictMode("function foo (a, " + word + ", b) {}", SyntaxError);
316 CheckStrictMode("var foo = function (" + word + ") {}", SyntaxError);
317
318 // Function names and arguments when the body is strict
319 assertThrows("function " + word + " () { 'use strict'; }", SyntaxError);
320 assertThrows("function foo (" + word + ") 'use strict'; {}", SyntaxError);
321 assertThrows("function foo (" + word + ", " + word + ") { 'use strict'; }", Sy ntaxError);
322 assertThrows("function foo (a, " + word + ") { 'use strict'; }", SyntaxError);
323 assertThrows("function foo (" + word + ", a) { 'use strict'; }", SyntaxError);
324 assertThrows("function foo (a, " + word + ", b) { 'use strict'; }", SyntaxErro r);
325 assertThrows("var foo = function (" + word + ") { 'use strict'; }", SyntaxErro r);
326
327 // get/set when the body is strict
328 eval("var x = { get " + word + " () { 'use strict'; } };");
329 eval("var x = { set " + word + " (value) { 'use strict'; } };");
330 assertThrows("var x = { get foo(" + word + ") { 'use strict'; } };", SyntaxErr or);
331 assertThrows("var x = { set foo(" + word + ") { 'use strict'; } };", SyntaxErr or);
332 }
333
334 for (var i = 0; i < future_reserved_words.length; i++) {
335 testFutureReservedWord(future_reserved_words[i]);
336 }
337
338
OLDNEW
« no previous file with comments | « src/token.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698