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

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

Issue 7207007: Proper handling of future reserved words in strict and normal mode. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: addressed comments Created 9 years, 6 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 | « test/mjsunit/keywords-and-reserved_words.js ('k') | test/preparser/strict-identifiers.pyt » ('j') | 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 Function.apply(this, args); 60 Function.apply(this, args);
61 }, SyntaxError); 61 }, SyntaxError);
62 } 62 }
63 63
64 // Incorrect 'use strict' directive. 64 // Incorrect 'use strict' directive.
65 (function UseStrictEscape() { 65 (function UseStrictEscape() {
66 "use\\x20strict"; 66 "use\\x20strict";
67 with ({}) {}; 67 with ({}) {};
68 })(); 68 })();
69 69
70 // Incorrectly place 'use strict' directive.
71 assertThrows("function foo (x) 'use strict'; {}", SyntaxError);
72
70 // 'use strict' in non-directive position. 73 // 'use strict' in non-directive position.
71 (function UseStrictNonDirective() { 74 (function UseStrictNonDirective() {
72 void(0); 75 void(0);
73 "use strict"; 76 "use strict";
74 with ({}) {}; 77 with ({}) {};
75 })(); 78 })();
76 79
77 // Multiple directives, including "use strict". 80 // Multiple directives, including "use strict".
78 assertThrows('\ 81 assertThrows('\
79 "directive 1";\ 82 "directive 1";\
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 })(); 315 })();
313 316
314 // Prefix unary operators other than delete, ++, -- are valid in strict mode 317 // Prefix unary operators other than delete, ++, -- are valid in strict mode
315 (function StrictModeUnaryOperators() { 318 (function StrictModeUnaryOperators() {
316 "use strict"; 319 "use strict";
317 var x = [void eval, typeof eval, +eval, -eval, ~eval, !eval]; 320 var x = [void eval, typeof eval, +eval, -eval, ~eval, !eval];
318 var y = [void arguments, typeof arguments, 321 var y = [void arguments, typeof arguments,
319 +arguments, -arguments, ~arguments, !arguments]; 322 +arguments, -arguments, ~arguments, !arguments];
320 })(); 323 })();
321 324
322 // 7.6.1.2 Future Reserved Words 325 // 7.6.1.2 Future Reserved Words in strict mode
323 var future_reserved_words = [ 326 var future_strict_reserved_words = [
324 "class",
325 "enum",
326 "export",
327 "extends",
328 "import",
329 "super",
330 "implements", 327 "implements",
331 "interface", 328 "interface",
332 "let", 329 "let",
333 "package", 330 "package",
334 "private", 331 "private",
335 "protected", 332 "protected",
336 "public", 333 "public",
337 "static", 334 "static",
338 "yield" ]; 335 "yield" ];
339 336
340 function testFutureReservedWord(word) { 337 function testFutureStrictReservedWord(word) {
341 // Simple use of each reserved word 338 // Simple use of each reserved word
342 CheckStrictMode("var " + word + " = 1;", SyntaxError); 339 CheckStrictMode("var " + word + " = 1;", SyntaxError);
340 CheckStrictMode("typeof (" + word + ");", SyntaxError);
343 341
344 // object literal properties 342 // object literal properties
345 eval("var x = { " + word + " : 42 };"); 343 eval("var x = { " + word + " : 42 };");
346 eval("var x = { get " + word + " () {} };"); 344 eval("var x = { get " + word + " () {} };");
347 eval("var x = { set " + word + " (value) {} };"); 345 eval("var x = { set " + word + " (value) {} };");
346 eval("var x = { get " + word + " () { 'use strict'; } };");
347 eval("var x = { set " + word + " (value) { 'use strict'; } };");
348 348
349 // object literal with string literal property names 349 // object literal with string literal property names
350 eval("var x = { '" + word + "' : 42 };"); 350 eval("var x = { '" + word + "' : 42 };");
351 eval("var x = { get '" + word + "' () { } };"); 351 eval("var x = { get '" + word + "' () { } };");
352 eval("var x = { set '" + word + "' (value) { } };"); 352 eval("var x = { set '" + word + "' (value) { } };");
353 eval("var x = { get '" + word + "' () { 'use strict'; } };"); 353 eval("var x = { get '" + word + "' () { 'use strict'; } };");
354 eval("var x = { set '" + word + "' (value) { 'use strict'; } };"); 354 eval("var x = { set '" + word + "' (value) { 'use strict'; } };");
355 355
356 // Function names and arguments, strict and non-strict contexts 356 // Function names and arguments, strict and non-strict contexts
357 CheckStrictMode("function " + word + " () {}", SyntaxError); 357 CheckStrictMode("function " + word + " () {}", SyntaxError);
358 CheckStrictMode("function foo (" + word + ") {}", SyntaxError); 358 CheckStrictMode("function foo (" + word + ") {}", SyntaxError);
359 CheckStrictMode("function foo (" + word + ", " + word + ") {}", SyntaxError); 359 CheckStrictMode("function foo (" + word + ", " + word + ") {}", SyntaxError);
360 CheckStrictMode("function foo (a, " + word + ") {}", SyntaxError); 360 CheckStrictMode("function foo (a, " + word + ") {}", SyntaxError);
361 CheckStrictMode("function foo (" + word + ", a) {}", SyntaxError); 361 CheckStrictMode("function foo (" + word + ", a) {}", SyntaxError);
362 CheckStrictMode("function foo (a, " + word + ", b) {}", SyntaxError); 362 CheckStrictMode("function foo (a, " + word + ", b) {}", SyntaxError);
363 CheckStrictMode("var foo = function (" + word + ") {}", SyntaxError); 363 CheckStrictMode("var foo = function (" + word + ") {}", SyntaxError);
364 364
365 // Function names and arguments when the body is strict 365 // Function names and arguments when the body is strict
366 assertThrows("function " + word + " () { 'use strict'; }", SyntaxError); 366 assertThrows("function " + word + " () { 'use strict'; }", SyntaxError);
367 assertThrows("function foo (" + word + ") 'use strict'; {}", SyntaxError);
368 assertThrows("function foo (" + word + ", " + word + ") { 'use strict'; }", 367 assertThrows("function foo (" + word + ", " + word + ") { 'use strict'; }",
369 SyntaxError); 368 SyntaxError);
370 assertThrows("function foo (a, " + word + ") { 'use strict'; }", SyntaxError); 369 assertThrows("function foo (a, " + word + ") { 'use strict'; }", SyntaxError);
371 assertThrows("function foo (" + word + ", a) { 'use strict'; }", SyntaxError); 370 assertThrows("function foo (" + word + ", a) { 'use strict'; }", SyntaxError);
372 assertThrows("function foo (a, " + word + ", b) { 'use strict'; }", 371 assertThrows("function foo (a, " + word + ", b) { 'use strict'; }",
373 SyntaxError); 372 SyntaxError);
374 assertThrows("var foo = function (" + word + ") { 'use strict'; }", 373 assertThrows("var foo = function (" + word + ") { 'use strict'; }",
375 SyntaxError); 374 SyntaxError);
376 375
377 // get/set when the body is strict 376 // get/set when the body is strict
378 eval("var x = { get " + word + " () { 'use strict'; } };"); 377 // Getters don't have formal parameters, so particularly future reserved
379 eval("var x = { set " + word + " (value) { 'use strict'; } };"); 378 // keywords are disallowed.
380 assertThrows("var x = { get foo(" + word + ") { 'use strict'; } };", 379 assertThrows("var x = { get foo(" + word + ") { 'use strict'; } };",
381 SyntaxError); 380 SyntaxError);
382 assertThrows("var x = { set foo(" + word + ") { 'use strict'; } };", 381 assertThrows("var x = { set foo(" + word + ") { 'use strict'; } };",
383 SyntaxError); 382 SyntaxError);
384 } 383 }
385 384
386 for (var i = 0; i < future_reserved_words.length; i++) { 385 for (var i = 0; i < future_strict_reserved_words.length; i++) {
387 testFutureReservedWord(future_reserved_words[i]); 386 testFutureStrictReservedWord(future_strict_reserved_words[i]);
388 } 387 }
389 388
390 function testAssignToUndefined(test, should_throw) { 389 function testAssignToUndefined(test, should_throw) {
391 try { 390 try {
392 test(); 391 test();
393 } catch (e) { 392 } catch (e) {
394 assertTrue(should_throw, "strict mode"); 393 assertTrue(should_throw, "strict mode");
395 assertInstanceof(e, ReferenceError, "strict mode"); 394 assertInstanceof(e, ReferenceError, "strict mode");
396 return; 395 return;
397 } 396 }
(...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after
1181 assertEquals(test(i), true); 1180 assertEquals(test(i), true);
1182 } 1181 }
1183 })(); 1182 })();
1184 1183
1185 1184
1186 (function TestStrictModeEval() { 1185 (function TestStrictModeEval() {
1187 "use strict"; 1186 "use strict";
1188 eval("var eval_local = 10;"); 1187 eval("var eval_local = 10;");
1189 assertThrows(function() { return eval_local; }, ReferenceError); 1188 assertThrows(function() { return eval_local; }, ReferenceError);
1190 })(); 1189 })();
OLDNEW
« no previous file with comments | « test/mjsunit/keywords-and-reserved_words.js ('k') | test/preparser/strict-identifiers.pyt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698