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

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

Issue 6697023: Merge 6800:7180 from the bleeding edge branch to the experimental/gc branch. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/gc/
Patch Set: Created 9 years, 9 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/sin-cos.js ('k') | test/mjsunit/tools/tickprocessor-test-func-info.log » ('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 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 CheckStrictMode("function strict() { var x = ++arguments; }", SyntaxError); 273 CheckStrictMode("function strict() { var x = ++arguments; }", SyntaxError);
274 274
275 // Prefix decrement with eval or arguments 275 // Prefix decrement with eval or arguments
276 CheckStrictMode("function strict() { --eval; }", SyntaxError); 276 CheckStrictMode("function strict() { --eval; }", SyntaxError);
277 CheckStrictMode("function strict() { --arguments; }", SyntaxError); 277 CheckStrictMode("function strict() { --arguments; }", SyntaxError);
278 CheckStrictMode("function strict() { print(--eval); }", SyntaxError); 278 CheckStrictMode("function strict() { print(--eval); }", SyntaxError);
279 CheckStrictMode("function strict() { print(--arguments); }", SyntaxError); 279 CheckStrictMode("function strict() { print(--arguments); }", SyntaxError);
280 CheckStrictMode("function strict() { var x = --eval; }", SyntaxError); 280 CheckStrictMode("function strict() { var x = --eval; }", SyntaxError);
281 CheckStrictMode("function strict() { var x = --arguments; }", SyntaxError); 281 CheckStrictMode("function strict() { var x = --arguments; }", SyntaxError);
282 282
283 // Use of const in strict mode is disallowed in anticipation of ES Harmony.
284 CheckStrictMode("const x = 0;", SyntaxError);
285 CheckStrictMode("for (const x = 0; false;) {}", SyntaxError);
286 CheckStrictMode("function strict() { const x = 0; }", SyntaxError);
287
288 // Strict mode only allows functions in SourceElements
289 CheckStrictMode("if (true) { function invalid() {} }", SyntaxError);
290 CheckStrictMode("for (;false;) { function invalid() {} }", SyntaxError);
291 CheckStrictMode("{ function invalid() {} }", SyntaxError);
292 CheckStrictMode("try { function invalid() {} } catch(e) {}", SyntaxError);
293 CheckStrictMode("try { } catch(e) { function invalid() {} }", SyntaxError);
294 CheckStrictMode("function outer() {{ function invalid() {} }}", SyntaxError);
295
283 // Delete of an unqualified identifier 296 // Delete of an unqualified identifier
284 CheckStrictMode("delete unqualified;", SyntaxError); 297 CheckStrictMode("delete unqualified;", SyntaxError);
285 CheckStrictMode("function strict() { delete unqualified; }", SyntaxError); 298 CheckStrictMode("function strict() { delete unqualified; }", SyntaxError);
286 CheckStrictMode("function function_name() { delete function_name; }", 299 CheckStrictMode("function function_name() { delete function_name; }",
287 SyntaxError); 300 SyntaxError);
288 CheckStrictMode("function strict(parameter) { delete parameter; }", 301 CheckStrictMode("function strict(parameter) { delete parameter; }",
289 SyntaxError); 302 SyntaxError);
290 CheckStrictMode("function strict() { var variable; delete variable; }", 303 CheckStrictMode("function strict() { var variable; delete variable; }",
291 SyntaxError); 304 SyntaxError);
292 CheckStrictMode("var variable; delete variable;", SyntaxError); 305 CheckStrictMode("var variable; delete variable;", SyntaxError);
293 306
307 (function TestStrictDelete() {
308 "use strict";
309 // "delete this" is allowed in strict mode and should work.
310 function strict_delete() { delete this; }
311 strict_delete();
312 })();
313
294 // Prefix unary operators other than delete, ++, -- are valid in strict mode 314 // Prefix unary operators other than delete, ++, -- are valid in strict mode
295 (function StrictModeUnaryOperators() { 315 (function StrictModeUnaryOperators() {
296 "use strict"; 316 "use strict";
297 var x = [void eval, typeof eval, +eval, -eval, ~eval, !eval]; 317 var x = [void eval, typeof eval, +eval, -eval, ~eval, !eval];
298 var y = [void arguments, typeof arguments, 318 var y = [void arguments, typeof arguments,
299 +arguments, -arguments, ~arguments, !arguments]; 319 +arguments, -arguments, ~arguments, !arguments];
300 })(); 320 })();
301 321
302 // 7.6.1.2 Future Reserved Words 322 // 7.6.1.2 Future Reserved Words
303 var future_reserved_words = [ 323 var future_reserved_words = [
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 assertEquals(object[1], "one"); 451 assertEquals(object[1], "one");
432 assertThrows(function() { delete_element(object, "7"); }, TypeError); 452 assertThrows(function() { delete_element(object, "7"); }, TypeError);
433 assertThrows(function() { delete_element(object, 7); }, TypeError); 453 assertThrows(function() { delete_element(object, 7); }, TypeError);
434 assertEquals(object[7], "seven"); 454 assertEquals(object[7], "seven");
435 assertThrows(function() { delete_element(object, "3.14"); }, TypeError); 455 assertThrows(function() { delete_element(object, "3.14"); }, TypeError);
436 assertThrows(function() { delete_element(object, 3.14); }, TypeError); 456 assertThrows(function() { delete_element(object, 3.14); }, TypeError);
437 assertEquals(object[3.14], "pi"); 457 assertEquals(object[3.14], "pi");
438 })(); 458 })();
439 459
440 // Not transforming this in Function.call and Function.apply. 460 // Not transforming this in Function.call and Function.apply.
441 (function testThisTransform() { 461 (function testThisTransformCallApply() {
442 function non_strict() { 462 function non_strict() {
443 return this; 463 return this;
444 } 464 }
445 function strict() { 465 function strict() {
446 "use strict"; 466 "use strict";
447 return this; 467 return this;
448 } 468 }
449 469
450 var global_object = (function() { return this; })(); 470 var global_object = (function() { return this; })();
451 var object = {}; 471 var object = {};
(...skipping 19 matching lines...) Expand all
471 assertEquals(typeof strict.call("Hello"), "string"); 491 assertEquals(typeof strict.call("Hello"), "string");
472 assertTrue(strict.call(object) === object); 492 assertTrue(strict.call(object) === object);
473 493
474 // Strict apply. 494 // Strict apply.
475 assertTrue(strict.apply(null) === null); 495 assertTrue(strict.apply(null) === null);
476 assertTrue(strict.apply(undefined) === undefined); 496 assertTrue(strict.apply(undefined) === undefined);
477 assertEquals(typeof strict.apply(7), "number"); 497 assertEquals(typeof strict.apply(7), "number");
478 assertEquals(typeof strict.apply("Hello"), "string"); 498 assertEquals(typeof strict.apply("Hello"), "string");
479 assertTrue(strict.apply(object) === object); 499 assertTrue(strict.apply(object) === object);
480 })(); 500 })();
501
502 (function testThisTransform() {
503 try {
504 function strict() {
505 "use strict";
506 return typeof(this);
507 }
508 function nonstrict() {
509 return typeof(this);
510 }
511
512 // Concat to avoid symbol.
513 var strict_name = "str" + "ict";
514 var nonstrict_name = "non" + "str" + "ict";
515 var strict_number = 17;
516 var nonstrict_number = 19;
517 var strict_name_get = "str" + "ict" + "get";
518 var nonstrict_name_get = "non" + "str" + "ict" + "get"
519 var strict_number_get = 23;
520 var nonstrict_number_get = 29;
521
522 function install(t) {
523 t.prototype.strict = strict;
524 t.prototype.nonstrict = nonstrict;
525 t.prototype[strict_number] = strict;
526 t.prototype[nonstrict_number] = nonstrict;
527 Object.defineProperty(t.prototype, strict_name_get,
528 { get: function() { return strict; },
529 configurable: true });
530 Object.defineProperty(t.prototype, nonstrict_name_get,
531 { get: function() { return nonstrict; },
532 configurable: true });
533 Object.defineProperty(t.prototype, strict_number_get,
534 { get: function() { return strict; },
535 configurable: true });
536 Object.defineProperty(t.prototype, nonstrict_number_get,
537 { get: function() { return nonstrict; },
538 configurable: true });
539 }
540
541 function cleanup(t) {
542 delete t.prototype.strict;
543 delete t.prototype.nonstrict;
544 delete t.prototype[strict_number];
545 delete t.prototype[nonstrict_number];
546 delete t.prototype[strict_name_get];
547 delete t.prototype[nonstrict_name_get];
548 delete t.prototype[strict_number_get];
549 delete t.prototype[nonstrict_number_get];
550 }
551
552 // Set up fakes
553 install(String);
554 install(Number);
555 install(Boolean)
556
557 function callStrict(o) {
558 return o.strict();
559 }
560 function callNonStrict(o) {
561 return o.nonstrict();
562 }
563 function callKeyedStrict(o) {
564 return o[strict_name]();
565 }
566 function callKeyedNonStrict(o) {
567 return o[nonstrict_name]();
568 }
569 function callIndexedStrict(o) {
570 return o[strict_number]();
571 }
572 function callIndexedNonStrict(o) {
573 return o[nonstrict_number]();
574 }
575 function callStrictGet(o) {
576 return o.strictget();
577 }
578 function callNonStrictGet(o) {
579 return o.nonstrictget();
580 }
581 function callKeyedStrictGet(o) {
582 return o[strict_name_get]();
583 }
584 function callKeyedNonStrictGet(o) {
585 return o[nonstrict_name_get]();
586 }
587 function callIndexedStrictGet(o) {
588 return o[strict_number_get]();
589 }
590 function callIndexedNonStrictGet(o) {
591 return o[nonstrict_number_get]();
592 }
593
594 for (var i = 0; i < 10; i ++) {
595 assertEquals(("hello").strict(), "string");
596 assertEquals(("hello").nonstrict(), "object");
597 assertEquals(("hello")[strict_name](), "string");
598 assertEquals(("hello")[nonstrict_name](), "object");
599 assertEquals(("hello")[strict_number](), "string");
600 assertEquals(("hello")[nonstrict_number](), "object");
601
602 assertEquals((10 + i).strict(), "number");
603 assertEquals((10 + i).nonstrict(), "object");
604 assertEquals((10 + i)[strict_name](), "number");
605 assertEquals((10 + i)[nonstrict_name](), "object");
606 assertEquals((10 + i)[strict_number](), "number");
607 assertEquals((10 + i)[nonstrict_number](), "object");
608
609 assertEquals((true).strict(), "boolean");
610 assertEquals((true).nonstrict(), "object");
611 assertEquals((true)[strict_name](), "boolean");
612 assertEquals((true)[nonstrict_name](), "object");
613 assertEquals((true)[strict_number](), "boolean");
614 assertEquals((true)[nonstrict_number](), "object");
615
616 assertEquals((false).strict(), "boolean");
617 assertEquals((false).nonstrict(), "object");
618 assertEquals((false)[strict_name](), "boolean");
619 assertEquals((false)[nonstrict_name](), "object");
620 assertEquals((false)[strict_number](), "boolean");
621 assertEquals((false)[nonstrict_number](), "object");
622
623 assertEquals(callStrict("howdy"), "string");
624 assertEquals(callNonStrict("howdy"), "object");
625 assertEquals(callKeyedStrict("howdy"), "string");
626 assertEquals(callKeyedNonStrict("howdy"), "object");
627 assertEquals(callIndexedStrict("howdy"), "string");
628 assertEquals(callIndexedNonStrict("howdy"), "object");
629
630 assertEquals(callStrict(17 + i), "number");
631 assertEquals(callNonStrict(17 + i), "object");
632 assertEquals(callKeyedStrict(17 + i), "number");
633 assertEquals(callKeyedNonStrict(17 + i), "object");
634 assertEquals(callIndexedStrict(17 + i), "number");
635 assertEquals(callIndexedNonStrict(17 + i), "object");
636
637 assertEquals(callStrict(true), "boolean");
638 assertEquals(callNonStrict(true), "object");
639 assertEquals(callKeyedStrict(true), "boolean");
640 assertEquals(callKeyedNonStrict(true), "object");
641 assertEquals(callIndexedStrict(true), "boolean");
642 assertEquals(callIndexedNonStrict(true), "object");
643
644 assertEquals(callStrict(false), "boolean");
645 assertEquals(callNonStrict(false), "object");
646 assertEquals(callKeyedStrict(false), "boolean");
647 assertEquals(callKeyedNonStrict(false), "object");
648 assertEquals(callIndexedStrict(false), "boolean");
649 assertEquals(callIndexedNonStrict(false), "object");
650
651 // All of the above, with getters
652 assertEquals(("hello").strictget(), "string");
653 assertEquals(("hello").nonstrictget(), "object");
654 assertEquals(("hello")[strict_name_get](), "string");
655 assertEquals(("hello")[nonstrict_name_get](), "object");
656 assertEquals(("hello")[strict_number_get](), "string");
657 assertEquals(("hello")[nonstrict_number_get](), "object");
658
659 assertEquals((10 + i).strictget(), "number");
660 assertEquals((10 + i).nonstrictget(), "object");
661 assertEquals((10 + i)[strict_name_get](), "number");
662 assertEquals((10 + i)[nonstrict_name_get](), "object");
663 assertEquals((10 + i)[strict_number_get](), "number");
664 assertEquals((10 + i)[nonstrict_number_get](), "object");
665
666 assertEquals((true).strictget(), "boolean");
667 assertEquals((true).nonstrictget(), "object");
668 assertEquals((true)[strict_name_get](), "boolean");
669 assertEquals((true)[nonstrict_name_get](), "object");
670 assertEquals((true)[strict_number_get](), "boolean");
671 assertEquals((true)[nonstrict_number_get](), "object");
672
673 assertEquals((false).strictget(), "boolean");
674 assertEquals((false).nonstrictget(), "object");
675 assertEquals((false)[strict_name_get](), "boolean");
676 assertEquals((false)[nonstrict_name_get](), "object");
677 assertEquals((false)[strict_number_get](), "boolean");
678 assertEquals((false)[nonstrict_number_get](), "object");
679
680 assertEquals(callStrictGet("howdy"), "string");
681 assertEquals(callNonStrictGet("howdy"), "object");
682 assertEquals(callKeyedStrictGet("howdy"), "string");
683 assertEquals(callKeyedNonStrictGet("howdy"), "object");
684 assertEquals(callIndexedStrictGet("howdy"), "string");
685 assertEquals(callIndexedNonStrictGet("howdy"), "object");
686
687 assertEquals(callStrictGet(17 + i), "number");
688 assertEquals(callNonStrictGet(17 + i), "object");
689 assertEquals(callKeyedStrictGet(17 + i), "number");
690 assertEquals(callKeyedNonStrictGet(17 + i), "object");
691 assertEquals(callIndexedStrictGet(17 + i), "number");
692 assertEquals(callIndexedNonStrictGet(17 + i), "object");
693
694 assertEquals(callStrictGet(true), "boolean");
695 assertEquals(callNonStrictGet(true), "object");
696 assertEquals(callKeyedStrictGet(true), "boolean");
697 assertEquals(callKeyedNonStrictGet(true), "object");
698 assertEquals(callIndexedStrictGet(true), "boolean");
699 assertEquals(callIndexedNonStrictGet(true), "object");
700
701 assertEquals(callStrictGet(false), "boolean");
702 assertEquals(callNonStrictGet(false), "object");
703 assertEquals(callKeyedStrictGet(false), "boolean");
704 assertEquals(callKeyedNonStrictGet(false), "object");
705 assertEquals(callIndexedStrictGet(false), "boolean");
706 assertEquals(callIndexedNonStrictGet(false), "object");
707
708 }
709 } finally {
710 // Cleanup
711 cleanup(String);
712 cleanup(Number);
713 cleanup(Boolean);
714 }
715 })();
716
717
718 (function ObjectEnvironment() {
719 var o = {};
720 Object.defineProperty(o, "foo", { value: "FOO", writable: false });
721 assertThrows(
722 function () {
723 with (o) {
724 (function() {
725 "use strict";
726 foo = "Hello";
727 })();
728 }
729 },
730 TypeError);
731 })();
732
733
734 (function TestSetPropertyWithoutSetter() {
735 var o = { get foo() { return "Yey"; } };
736 assertThrows(
737 function broken() {
738 "use strict";
739 o.foo = (0xBADBAD00 >> 1);
740 },
741 TypeError);
742 })();
743
744
745 (function TestSetPropertyNonConfigurable() {
746 var frozen = Object.freeze({});
747 var sealed = Object.seal({});
748
749 function strict(o) {
750 "use strict";
751 o.property = "value";
752 }
753
754 assertThrows(function() { strict(frozen); }, TypeError);
755 assertThrows(function() { strict(sealed); }, TypeError);
756 })();
757
758
759 (function TestAssignmentToReadOnlyProperty() {
760 "use strict";
761
762 var o = {};
763 Object.defineProperty(o, "property", { value: 7 });
764
765 assertThrows(function() { o.property = "new value"; }, TypeError);
766 assertThrows(function() { o.property += 10; }, TypeError);
767 assertThrows(function() { o.property -= 10; }, TypeError);
768 assertThrows(function() { o.property *= 10; }, TypeError);
769 assertThrows(function() { o.property /= 10; }, TypeError);
770 assertThrows(function() { o.property++; }, TypeError);
771 assertThrows(function() { o.property--; }, TypeError);
772 assertThrows(function() { ++o.property; }, TypeError);
773 assertThrows(function() { --o.property; }, TypeError);
774
775 var name = "prop" + "erty"; // to avoid symbol path.
776 assertThrows(function() { o[name] = "new value"; }, TypeError);
777 assertThrows(function() { o[name] += 10; }, TypeError);
778 assertThrows(function() { o[name] -= 10; }, TypeError);
779 assertThrows(function() { o[name] *= 10; }, TypeError);
780 assertThrows(function() { o[name] /= 10; }, TypeError);
781 assertThrows(function() { o[name]++; }, TypeError);
782 assertThrows(function() { o[name]--; }, TypeError);
783 assertThrows(function() { ++o[name]; }, TypeError);
784 assertThrows(function() { --o[name]; }, TypeError);
785
786 assertEquals(o.property, 7);
787 })();
788
789
790 (function TestAssignmentToReadOnlyLoop() {
791 var name = "prop" + "erty"; // to avoid symbol path.
792 var o = {};
793 Object.defineProperty(o, "property", { value: 7 });
794
795 function strict(o, name) {
796 "use strict";
797 o[name] = "new value";
798 }
799
800 for (var i = 0; i < 10; i ++) {
801 try {
802 strict(o, name);
803 assertUnreachable();
804 } catch(e) {
805 assertInstanceof(e, TypeError);
806 }
807 }
808 })();
809
810
811 // Specialized KeyedStoreIC experiencing miss.
812 (function testKeyedStoreICStrict() {
813 var o = [9,8,7,6,5,4,3,2,1];
814
815 function test(o, i, v) {
816 "use strict";
817 o[i] = v;
818 }
819
820 for (var i = 0; i < 10; i ++) {
821 test(o, 5, 17); // start specialized for smi indices
822 assertEquals(o[5], 17);
823 test(o, "a", 19);
824 assertEquals(o["a"], 19);
825 test(o, "5", 29);
826 assertEquals(o[5], 29);
827 test(o, 100000, 31);
828 assertEquals(o[100000], 31);
829 }
830 })();
831
832
833 (function TestSetElementWithoutSetter() {
834 "use strict";
835
836 var o = { };
837 Object.defineProperty(o, 0, { get : function() { } });
838
839 var zero_smi = 0;
840 var zero_number = new Number(0);
841 var zero_symbol = "0";
842 var zero_string = "-0-".substring(1,2);
843
844 assertThrows(function() { o[zero_smi] = "new value"; }, TypeError);
845 assertThrows(function() { o[zero_number] = "new value"; }, TypeError);
846 assertThrows(function() { o[zero_symbol] = "new value"; }, TypeError);
847 assertThrows(function() { o[zero_string] = "new value"; }, TypeError);
848 })();
849
850
851 (function TestSetElementNonConfigurable() {
852 "use strict";
853 var frozen = Object.freeze({});
854 var sealed = Object.seal({});
855
856 var zero_number = 0;
857 var zero_symbol = "0";
858 var zero_string = "-0-".substring(1,2);
859
860 assertThrows(function() { frozen[zero_number] = "value"; }, TypeError);
861 assertThrows(function() { sealed[zero_number] = "value"; }, TypeError);
862 assertThrows(function() { frozen[zero_symbol] = "value"; }, TypeError);
863 assertThrows(function() { sealed[zero_symbol] = "value"; }, TypeError);
864 assertThrows(function() { frozen[zero_string] = "value"; }, TypeError);
865 assertThrows(function() { sealed[zero_string] = "value"; }, TypeError);
866 })();
867
868
869 (function TestAssignmentToReadOnlyElement() {
870 "use strict";
871
872 var o = {};
873 Object.defineProperty(o, 7, { value: 17 });
874
875 var seven_smi = 7;
876 var seven_number = new Number(7);
877 var seven_symbol = "7";
878 var seven_string = "-7-".substring(1,2);
879
880 // Index with number.
881 assertThrows(function() { o[seven_smi] = "value"; }, TypeError);
882 assertThrows(function() { o[seven_smi] += 10; }, TypeError);
883 assertThrows(function() { o[seven_smi] -= 10; }, TypeError);
884 assertThrows(function() { o[seven_smi] *= 10; }, TypeError);
885 assertThrows(function() { o[seven_smi] /= 10; }, TypeError);
886 assertThrows(function() { o[seven_smi]++; }, TypeError);
887 assertThrows(function() { o[seven_smi]--; }, TypeError);
888 assertThrows(function() { ++o[seven_smi]; }, TypeError);
889 assertThrows(function() { --o[seven_smi]; }, TypeError);
890
891 assertThrows(function() { o[seven_number] = "value"; }, TypeError);
892 assertThrows(function() { o[seven_number] += 10; }, TypeError);
893 assertThrows(function() { o[seven_number] -= 10; }, TypeError);
894 assertThrows(function() { o[seven_number] *= 10; }, TypeError);
895 assertThrows(function() { o[seven_number] /= 10; }, TypeError);
896 assertThrows(function() { o[seven_number]++; }, TypeError);
897 assertThrows(function() { o[seven_number]--; }, TypeError);
898 assertThrows(function() { ++o[seven_number]; }, TypeError);
899 assertThrows(function() { --o[seven_number]; }, TypeError);
900
901 assertThrows(function() { o[seven_symbol] = "value"; }, TypeError);
902 assertThrows(function() { o[seven_symbol] += 10; }, TypeError);
903 assertThrows(function() { o[seven_symbol] -= 10; }, TypeError);
904 assertThrows(function() { o[seven_symbol] *= 10; }, TypeError);
905 assertThrows(function() { o[seven_symbol] /= 10; }, TypeError);
906 assertThrows(function() { o[seven_symbol]++; }, TypeError);
907 assertThrows(function() { o[seven_symbol]--; }, TypeError);
908 assertThrows(function() { ++o[seven_symbol]; }, TypeError);
909 assertThrows(function() { --o[seven_symbol]; }, TypeError);
910
911 assertThrows(function() { o[seven_string] = "value"; }, TypeError);
912 assertThrows(function() { o[seven_string] += 10; }, TypeError);
913 assertThrows(function() { o[seven_string] -= 10; }, TypeError);
914 assertThrows(function() { o[seven_string] *= 10; }, TypeError);
915 assertThrows(function() { o[seven_string] /= 10; }, TypeError);
916 assertThrows(function() { o[seven_string]++; }, TypeError);
917 assertThrows(function() { o[seven_string]--; }, TypeError);
918 assertThrows(function() { ++o[seven_string]; }, TypeError);
919 assertThrows(function() { --o[seven_string]; }, TypeError);
920
921 assertEquals(o[seven_number], 17);
922 assertEquals(o[seven_symbol], 17);
923 assertEquals(o[seven_string], 17);
924 })();
925
926
927 (function TestAssignmentToReadOnlyLoop() {
928 "use strict";
929
930 var o = {};
931 Object.defineProperty(o, 7, { value: 17 });
932
933 var seven_smi = 7;
934 var seven_number = new Number(7);
935 var seven_symbol = "7";
936 var seven_string = "-7-".substring(1,2);
937
938 for (var i = 0; i < 10; i ++) {
939 assertThrows(function() { o[seven_smi] = "value" }, TypeError);
940 assertThrows(function() { o[seven_number] = "value" }, TypeError);
941 assertThrows(function() { o[seven_symbol] = "value" }, TypeError);
942 assertThrows(function() { o[seven_string] = "value" }, TypeError);
943 }
944
945 assertEquals(o[7], 17);
946 })();
947
948
949 (function TestAssignmentToStringLength() {
950 "use strict";
951
952 var str_val = "string";
953 var str_obj = new String(str_val);
954 var str_cat = str_val + str_val + str_obj;
955
956 assertThrows(function() { str_val.length = 1; }, TypeError);
957 assertThrows(function() { str_obj.length = 1; }, TypeError);
958 assertThrows(function() { str_cat.length = 1; }, TypeError);
959 })();
960
961
962 (function TestArgumentsAliasing() {
963 function strict(a, b) {
964 "use strict";
965 a = "c";
966 b = "d";
967 return [a, b, arguments[0], arguments[1]];
968 }
969
970 function nonstrict(a, b) {
971 a = "c";
972 b = "d";
973 return [a, b, arguments[0], arguments[1]];
974 }
975
976 assertEquals(["c", "d", "a", "b"], strict("a", "b"));
977 assertEquals(["c", "d", "c", "d"], nonstrict("a", "b"));
978 })();
OLDNEW
« no previous file with comments | « test/mjsunit/sin-cos.js ('k') | test/mjsunit/tools/tickprocessor-test-func-info.log » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698