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

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

Issue 7348008: Merge up to 8597 to experimental/gc from the bleeding edge. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/gc/
Patch Set: '' Created 9 years, 5 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/regress/regress-regexp-codeflush.js ('k') | test/mjsunit/strict-mode-eval.js » ('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 // setter parameter when the body is strict
378 eval("var x = { get " + word + " () { 'use strict'; } };"); 377 CheckStrictMode("var x = { set foo(" + word + ") {} };", SyntaxError);
379 eval("var x = { set " + word + " (value) { 'use strict'; } };");
380 assertThrows("var x = { get foo(" + word + ") { 'use strict'; } };",
381 SyntaxError);
382 assertThrows("var x = { set foo(" + word + ") { 'use strict'; } };", 378 assertThrows("var x = { set foo(" + word + ") { 'use strict'; } };",
383 SyntaxError); 379 SyntaxError);
384 } 380 }
385 381
386 for (var i = 0; i < future_reserved_words.length; i++) { 382 for (var i = 0; i < future_strict_reserved_words.length; i++) {
387 testFutureReservedWord(future_reserved_words[i]); 383 testFutureStrictReservedWord(future_strict_reserved_words[i]);
388 } 384 }
389 385
390 function testAssignToUndefined(test, should_throw) { 386 function testAssignToUndefined(test, should_throw) {
391 try { 387 try {
392 test(); 388 test();
393 } catch (e) { 389 } catch (e) {
394 assertTrue(should_throw, "strict mode"); 390 assertTrue(should_throw, "strict mode");
395 assertInstanceof(e, ReferenceError, "strict mode"); 391 assertInstanceof(e, ReferenceError, "strict mode");
396 return; 392 return;
397 } 393 }
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 var name = "prop" + "erty"; // to avoid symbol path. 831 var name = "prop" + "erty"; // to avoid symbol path.
836 var o = {}; 832 var o = {};
837 Object.defineProperty(o, "property", { value: 7 }); 833 Object.defineProperty(o, "property", { value: 7 });
838 834
839 function strict(o, name) { 835 function strict(o, name) {
840 "use strict"; 836 "use strict";
841 o[name] = "new value"; 837 o[name] = "new value";
842 } 838 }
843 839
844 for (var i = 0; i < 10; i ++) { 840 for (var i = 0; i < 10; i ++) {
841 var exception = false;
845 try { 842 try {
846 strict(o, name); 843 strict(o, name);
847 assertUnreachable();
848 } catch(e) { 844 } catch(e) {
845 exception = true;
849 assertInstanceof(e, TypeError); 846 assertInstanceof(e, TypeError);
850 } 847 }
848 assertTrue(exception);
851 } 849 }
852 })(); 850 })();
853 851
854 852
855 // Specialized KeyedStoreIC experiencing miss. 853 // Specialized KeyedStoreIC experiencing miss.
856 (function testKeyedStoreICStrict() { 854 (function testKeyedStoreICStrict() {
857 var o = [9,8,7,6,5,4,3,2,1]; 855 var o = [9,8,7,6,5,4,3,2,1];
858 856
859 function test(o, i, v) { 857 function test(o, i, v) {
860 "use strict"; 858 "use strict";
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
1179 assertEquals(test(i), true); 1177 assertEquals(test(i), true);
1180 } 1178 }
1181 })(); 1179 })();
1182 1180
1183 1181
1184 (function TestStrictModeEval() { 1182 (function TestStrictModeEval() {
1185 "use strict"; 1183 "use strict";
1186 eval("var eval_local = 10;"); 1184 eval("var eval_local = 10;");
1187 assertThrows(function() { return eval_local; }, ReferenceError); 1185 assertThrows(function() { return eval_local; }, ReferenceError);
1188 })(); 1186 })();
OLDNEW
« no previous file with comments | « test/mjsunit/regress/regress-regexp-codeflush.js ('k') | test/mjsunit/strict-mode-eval.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698