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

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

Issue 6814012: Strict mode fixes. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 8 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
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 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 assertThrows("var x = { get foo(" + word + ") { 'use strict'; } };", 380 assertThrows("var x = { get foo(" + word + ") { 'use strict'; } };",
381 SyntaxError); 381 SyntaxError);
382 assertThrows("var x = { set foo(" + word + ") { 'use strict'; } };", 382 assertThrows("var x = { set foo(" + word + ") { 'use strict'; } };",
383 SyntaxError); 383 SyntaxError);
384 } 384 }
385 385
386 for (var i = 0; i < future_reserved_words.length; i++) { 386 for (var i = 0; i < future_reserved_words.length; i++) {
387 testFutureReservedWord(future_reserved_words[i]); 387 testFutureReservedWord(future_reserved_words[i]);
388 } 388 }
389 389
390 function testAssignToUndefined(should_throw) { 390 function testAssignToUndefined(test, should_throw) {
391 "use strict";
392 try { 391 try {
393 possibly_undefined_variable_for_strict_mode_test = "should throw?"; 392 test();
394 } catch (e) { 393 } catch (e) {
395 assertTrue(should_throw, "strict mode"); 394 assertTrue(should_throw, "strict mode");
396 assertInstanceof(e, ReferenceError, "strict mode"); 395 assertInstanceof(e, ReferenceError, "strict mode");
397 return; 396 return;
398 } 397 }
399 assertFalse(should_throw, "strict mode"); 398 assertFalse(should_throw, "strict mode");
400 } 399 }
401 400
402 testAssignToUndefined(true); 401 function repeat(n, f) {
403 testAssignToUndefined(true); 402 for (var i = 0; i < n; i ++) { f(); }
404 testAssignToUndefined(true); 403 }
404
405 function assignToUndefined() {
406 "use strict";
407 possibly_undefined_variable_for_strict_mode_test = "should throw?";
408 }
409
410 testAssignToUndefined(assignToUndefined, true);
411 testAssignToUndefined(assignToUndefined, true);
412 testAssignToUndefined(assignToUndefined, true);
405 413
406 possibly_undefined_variable_for_strict_mode_test = "value"; 414 possibly_undefined_variable_for_strict_mode_test = "value";
407 415
408 testAssignToUndefined(false); 416 testAssignToUndefined(assignToUndefined, false);
409 testAssignToUndefined(false); 417 testAssignToUndefined(assignToUndefined, false);
410 testAssignToUndefined(false); 418 testAssignToUndefined(assignToUndefined, false);
411 419
412 delete possibly_undefined_variable_for_strict_mode_test; 420 delete possibly_undefined_variable_for_strict_mode_test;
413 421
414 testAssignToUndefined(true); 422 testAssignToUndefined(assignToUndefined, true);
415 testAssignToUndefined(true); 423 testAssignToUndefined(assignToUndefined, true);
416 testAssignToUndefined(true); 424 testAssignToUndefined(assignToUndefined, true);
417 425
418 function repeat(n, f) { 426 repeat(10, function() { testAssignToUndefined(assignToUndefined, true); });
419 for (var i = 0; i < n; i ++) { f(); } 427 possibly_undefined_variable_for_strict_mode_test = "value";
428 repeat(10, function() { testAssignToUndefined(assignToUndefined, false); });
429 delete possibly_undefined_variable_for_strict_mode_test;
430 repeat(10, function() { testAssignToUndefined(assignToUndefined, true); });
431 possibly_undefined_variable_for_strict_mode_test = undefined;
432 repeat(10, function() { testAssignToUndefined(assignToUndefined, false); });
433
434 function assignToUndefinedWithEval() {
435 "use strict";
436 possibly_undefined_variable_for_strict_mode_test_with_eval = "should throw?";
437 eval("");
420 } 438 }
421 439
422 repeat(10, function() { testAssignToUndefined(true); }); 440 testAssignToUndefined(assignToUndefinedWithEval, true);
423 possibly_undefined_variable_for_strict_mode_test = "value"; 441 testAssignToUndefined(assignToUndefinedWithEval, true);
424 repeat(10, function() { testAssignToUndefined(false); }); 442 testAssignToUndefined(assignToUndefinedWithEval, true);
425 delete possibly_undefined_variable_for_strict_mode_test; 443
426 repeat(10, function() { testAssignToUndefined(true); }); 444 possibly_undefined_variable_for_strict_mode_test_with_eval = "value";
427 possibly_undefined_variable_for_strict_mode_test = undefined; 445
428 repeat(10, function() { testAssignToUndefined(false); }); 446 testAssignToUndefined(assignToUndefinedWithEval, false);
447 testAssignToUndefined(assignToUndefinedWithEval, false);
448 testAssignToUndefined(assignToUndefinedWithEval, false);
449
450 delete possibly_undefined_variable_for_strict_mode_test_with_eval;
451
452 testAssignToUndefined(assignToUndefinedWithEval, true);
453 testAssignToUndefined(assignToUndefinedWithEval, true);
454 testAssignToUndefined(assignToUndefinedWithEval, true);
455
456 repeat(10, function() {
457 testAssignToUndefined(assignToUndefinedWithEval, true);
458 });
459 possibly_undefined_variable_for_strict_mode_test_with_eval = "value";
460 repeat(10, function() {
461 testAssignToUndefined(assignToUndefinedWithEval, false);
462 });
463 delete possibly_undefined_variable_for_strict_mode_test_with_eval;
464 repeat(10, function() {
465 testAssignToUndefined(assignToUndefinedWithEval, true);
466 });
467 possibly_undefined_variable_for_strict_mode_test_with_eval = undefined;
468 repeat(10, function() {
469 testAssignToUndefined(assignToUndefinedWithEval, false);
470 });
471
472
429 473
430 (function testDeleteNonConfigurable() { 474 (function testDeleteNonConfigurable() {
431 function delete_property(o) { 475 function delete_property(o) {
432 "use strict"; 476 "use strict";
433 delete o.property; 477 delete o.property;
434 } 478 }
435 function delete_element(o, i) { 479 function delete_element(o, i) {
436 "use strict"; 480 "use strict";
437 delete o[i]; 481 delete o[i];
438 } 482 }
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after
1128 } catch(e) { 1172 } catch(e) {
1129 return e instanceof TypeError; 1173 return e instanceof TypeError;
1130 } 1174 }
1131 return false; 1175 return false;
1132 } 1176 }
1133 1177
1134 for (var i = 0; i < 10; i ++) { 1178 for (var i = 0; i < 10; i ++) {
1135 assertEquals(test(i), true); 1179 assertEquals(test(i), true);
1136 } 1180 }
1137 })(); 1181 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698