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

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: Created 9 years, 10 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 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 (function TestSetPropertyNonConfigurable() {
732 var frozen = Object.freeze({});
733 var sealed = Object.seal({});
734
735 function strict(o) {
736 "use strict";
737 o.property = "value";
738 }
739
740 assertThrows(function() { strict(frozen); }, TypeError);
741 assertThrows(function() { strict(sealed); }, TypeError);
742 })();
743
744 (function TestAssignmentToReadOnlyPropert() {
745 "use strict";
746
747 var o = {};
748 Object.defineProperty(o, "property", { value: 7 });
749
750 assertThrows(function() { o.property = "new value"; }, TypeError);
751 assertThrows(function() { o.property += 10; }, TypeError);
752 assertThrows(function() { o.property -= 10; }, TypeError);
753 assertThrows(function() { o.property *= 10; }, TypeError);
754 assertThrows(function() { o.property /= 10; }, TypeError);
755 assertThrows(function() { o.property++; }, TypeError);
756 assertThrows(function() { o.property--; }, TypeError);
757 assertThrows(function() { ++o.property; }, TypeError);
758 assertThrows(function() { --o.property; }, TypeError);
759
760 var name = "prop" + "erty"; // to avoid symbol path.
761 assertThrows(function() { o[name] = "new value"; }, TypeError);
762 assertThrows(function() { o[name] += 10; }, TypeError);
763 assertThrows(function() { o[name] -= 10; }, TypeError);
764 assertThrows(function() { o[name] *= 10; }, TypeError);
765 assertThrows(function() { o[name] /= 10; }, TypeError);
766 assertThrows(function() { o[name]++; }, TypeError);
767 assertThrows(function() { o[name]--; }, TypeError);
768 assertThrows(function() { ++o[name]; }, TypeError);
769 assertThrows(function() { --o[name]; }, TypeError);
770
771 assertEquals(o.property, 7);
772 })();
773
774 // TODO(mmaly): Add loop test, something like:
775 /*
776 (function outer() {
777 "use strict";
778 var name = "prop" + "erty"; // to avoid symbol path.
779 var o = {};
780 Object.defineProperty(o, "property", { value: 7 });
781
782 function broken(o, name) {
783 o[name] = "new value";
784 }
785 try { broken(o, name); } catch(e) { print(e); }
786 try { broken(o, name); } catch(e) { print(e); }
787 try { broken(o, name); } catch(e) { print(e); }
788 try { broken(o, name); } catch(e) { print(e); }
789 })();
790 */
OLDNEW
« test/es5conform/es5conform.status ('K') | « test/es5conform/es5conform.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698