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

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

Issue 6576024: (early draft) Strict mode - throw exception on assignment to read only property. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Assign to read only property in strict mode. 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/es5conform/es5conform.status ('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 682 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 assertEquals(callIndexedNonStrictGet(false), "object"); 693 assertEquals(callIndexedNonStrictGet(false), "object");
694 694
695 } 695 }
696 } finally { 696 } finally {
697 // Cleanup 697 // Cleanup
698 cleanup(String); 698 cleanup(String);
699 cleanup(Number); 699 cleanup(Number);
700 cleanup(Boolean); 700 cleanup(Boolean);
701 } 701 }
702 })(); 702 })();
703
704
705 (function ObjectEnvironment() {
706 var o = {};
707 Object.defineProperty(o, "foo", { value: "FOO", writable: false });
708 assertThrows(
709 function () {
710 with (o) {
711 (function() {
712 "use strict";
713 foo = "Hello";
714 })();
715 }
716 },
717 TypeError);
718 })();
719
720
721 (function TestSetPropertyWithoutSetter() {
722 var o = { get foo() { return "Yey"; } };
723 assertThrows(
724 function broken() {
725 "use strict";
726 o.foo = (0xBADBAD00 >> 1);
727 },
728 TypeError);
729 })();
730
731
732 (function TestSetPropertyNonConfigurable() {
733 var frozen = Object.freeze({});
734 var sealed = Object.seal({});
735
736 function strict(o) {
737 "use strict";
738 o.property = "value";
739 }
740
741 assertThrows(function() { strict(frozen); }, TypeError);
742 assertThrows(function() { strict(sealed); }, TypeError);
743 })();
744
745
746 (function TestAssignmentToReadOnlyProperty() {
747 "use strict";
748
749 var o = {};
750 Object.defineProperty(o, "property", { value: 7 });
751
752 assertThrows(function() { o.property = "new value"; }, TypeError);
753 assertThrows(function() { o.property += 10; }, TypeError);
754 assertThrows(function() { o.property -= 10; }, TypeError);
755 assertThrows(function() { o.property *= 10; }, TypeError);
756 assertThrows(function() { o.property /= 10; }, TypeError);
757 assertThrows(function() { o.property++; }, TypeError);
758 assertThrows(function() { o.property--; }, TypeError);
759 assertThrows(function() { ++o.property; }, TypeError);
760 assertThrows(function() { --o.property; }, TypeError);
761
762 var name = "prop" + "erty"; // to avoid symbol path.
763 assertThrows(function() { o[name] = "new value"; }, TypeError);
764 assertThrows(function() { o[name] += 10; }, TypeError);
765 assertThrows(function() { o[name] -= 10; }, TypeError);
766 assertThrows(function() { o[name] *= 10; }, TypeError);
767 assertThrows(function() { o[name] /= 10; }, TypeError);
768 assertThrows(function() { o[name]++; }, TypeError);
769 assertThrows(function() { o[name]--; }, TypeError);
770 assertThrows(function() { ++o[name]; }, TypeError);
771 assertThrows(function() { --o[name]; }, TypeError);
772
773 assertEquals(o.property, 7);
774 })();
775
776
777 (function TestAssignmentToReadOnlyLoop() {
778 var name = "prop" + "erty"; // to avoid symbol path.
779 var o = {};
780 Object.defineProperty(o, "property", { value: 7 });
781
782 function strict(o, name) {
783 "use strict";
784 o[name] = "new value";
785 }
786
787 for (var i = 0; i < 10; i ++) {
788 try {
789 strict(o, name);
790 assertUnreachable();
791 } catch(e) {
792 assertInstanceof(e, TypeError);
793 }
794 }
795 })();
796
797
798 // Specialized KeyedStoreIC experiencing miss.
799 (function testKeyedStoreICStrict() {
800 var o = [9,8,7,6,5,4,3,2,1];
801
802 function test(o, i, v) {
803 "use strict";
804 o[i] = v;
805 }
806
807 for (var i = 0; i < 10; i ++) {
808 test(o, 5, 17); // start specialized for smi indices
809 assertEquals(o[5], 17);
810 test(o, "a", 19);
811 assertEquals(o["a"], 19);
812 test(o, "5", 29);
813 assertEquals(o[5], 29);
814 test(o, 100000, 31);
815 assertEquals(o[100000], 31);
816 }
817 })();
OLDNEW
« no previous file with comments | « test/es5conform/es5conform.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698