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

Side by Side Diff: test/mjsunit/object-define-property.js

Issue 6035014: First cut at bug 992 (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Format to 80 columns Created 9 years, 11 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 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 731 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 assertTrue(desc.configurable); 742 assertTrue(desc.configurable);
743 743
744 // Redefine existing property with configurable: false. 744 // Redefine existing property with configurable: false.
745 Object.defineProperty(obj6, '2', descElementNonConfigurable); 745 Object.defineProperty(obj6, '2', descElementNonConfigurable);
746 desc = Object.getOwnPropertyDescriptor(obj6, '2'); 746 desc = Object.getOwnPropertyDescriptor(obj6, '2');
747 assertEquals(desc.value, 'barfoo'); 747 assertEquals(desc.value, 'barfoo');
748 assertTrue(desc.writable); 748 assertTrue(desc.writable);
749 assertTrue(desc.enumerable); 749 assertTrue(desc.enumerable);
750 assertFalse(desc.configurable); 750 assertFalse(desc.configurable);
751 751
752 // Ensure that we can't overwrite the non configurable element. 752 // Can use defineProperty to change the value of a non
753 // configurable property
Rico 2011/01/05 13:40:39 period at end of comment
Peter Hallam 2011/01/05 23:50:31 Done.
753 try { 754 try {
754 Object.defineProperty(obj6, '2', descElement); 755 Object.defineProperty(obj6, '2', descElement);
756 desc = Object.getOwnPropertyDescriptor(obj6, '2');
757 assertEquals(desc.value, 'foobar');
758 } catch (e) {
759 assertUnreachable();
760 }
761
762 // Ensure that we can't change the descriptor of a
763 // the non configurable property.
Rico 2011/01/05 13:40:39 a the -> a
Peter Hallam 2011/01/05 23:50:31 Done.
764 try {
765 var descAccessor = { get: function() { return 0; } };
Rico 2011/01/05 13:37:01 could we also try with descElementNonWritable, whi
Peter Hallam 2011/01/05 23:50:31 I've added a test for descElementNonWritable. Inte
766 Object.defineProperty(obj6, '2', descAccessor);
755 assertUnreachable(); 767 assertUnreachable();
756 } catch (e) { 768 } catch (e) {
757 assertTrue(/Cannot redefine property/.test(e)); 769 assertTrue(/Cannot redefine property/.test(e));
758 } 770 }
759 771
760 Object.defineProperty(obj6, '3', descElementNonWritable); 772 Object.defineProperty(obj6, '3', descElementNonWritable);
761 desc = Object.getOwnPropertyDescriptor(obj6, '3'); 773 desc = Object.getOwnPropertyDescriptor(obj6, '3');
762 assertEquals(desc.value, 'foofoo'); 774 assertEquals(desc.value, 'foofoo');
763 assertFalse(desc.writable); 775 assertFalse(desc.writable);
764 assertTrue(desc.enumerable); 776 assertTrue(desc.enumerable);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 assertTrue(desc.configurable); 832 assertTrue(desc.configurable);
821 833
822 // Redefine existing property with configurable: false. 834 // Redefine existing property with configurable: false.
823 Object.defineProperty(arr, '2', descElementNonConfigurable); 835 Object.defineProperty(arr, '2', descElementNonConfigurable);
824 desc = Object.getOwnPropertyDescriptor(arr, '2'); 836 desc = Object.getOwnPropertyDescriptor(arr, '2');
825 assertEquals(desc.value, 'barfoo'); 837 assertEquals(desc.value, 'barfoo');
826 assertTrue(desc.writable); 838 assertTrue(desc.writable);
827 assertTrue(desc.enumerable); 839 assertTrue(desc.enumerable);
828 assertFalse(desc.configurable); 840 assertFalse(desc.configurable);
829 841
830 // Ensure that we can't overwrite the non configurable element. 842 // Can use defineProperty to change the value of a non
843 // configurable property of an array
Rico 2011/01/05 13:40:39 period at end of comment
Peter Hallam 2011/01/05 23:50:31 Done.
831 try { 844 try {
832 Object.defineProperty(arr, '2', descElement); 845 Object.defineProperty(arr, '2', descElement);
846 desc = Object.getOwnPropertyDescriptor(arr, '2');
847 assertEquals(desc.value, 'foobar');
848 } catch (e) {
849 assertUnreachable();
850 }
851
852 // Ensure that we can't change the descriptor of a
853 // non configurable property.
854 try {
855 var descAccessor = { get: function() { return 0; } };
Rico 2011/01/05 13:37:01 Again, could we also try with descElementNonWritab
Peter Hallam 2011/01/05 23:50:31 Done. See comment above.
856 Object.defineProperty(arr, '2', descAccessor);
833 assertUnreachable(); 857 assertUnreachable();
834 } catch (e) { 858 } catch (e) {
835 assertTrue(/Cannot redefine property/.test(e)); 859 assertTrue(/Cannot redefine property/.test(e));
836 } 860 }
837 861
838 Object.defineProperty(arr, '3', descElementNonWritable); 862 Object.defineProperty(arr, '3', descElementNonWritable);
839 desc = Object.getOwnPropertyDescriptor(arr, '3'); 863 desc = Object.getOwnPropertyDescriptor(arr, '3');
840 assertEquals(desc.value, 'foofoo'); 864 assertEquals(desc.value, 'foofoo');
841 assertFalse(desc.writable); 865 assertFalse(desc.writable);
842 assertTrue(desc.enumerable); 866 assertTrue(desc.enumerable);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 assertEquals(undefined, o.x); 915 assertEquals(undefined, o.x);
892 o.x = 37; 916 o.x = 37;
893 assertEquals(undefined, o.x); 917 assertEquals(undefined, o.x);
894 918
895 // Ignore inherited properties. 919 // Ignore inherited properties.
896 o = { __proto__ : { x : 87 } }; 920 o = { __proto__ : { x : 87 } };
897 Object.defineProperty(o, "x", { writable: false }); 921 Object.defineProperty(o, "x", { writable: false });
898 assertEquals(undefined, o.x); 922 assertEquals(undefined, o.x);
899 o.x = 37; 923 o.x = 37;
900 assertEquals(undefined, o.x); 924 assertEquals(undefined, o.x);
OLDNEW
« src/v8natives.js ('K') | « src/v8natives.js ('k') | test/mjsunit/regress/regress-992.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698