OLD | NEW |
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 Loading... |
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 // Can use defineProperty to change the value of a non | 752 // Ensure that we can't overwrite the non configurable element. |
753 // configurable property. | |
754 try { | 753 try { |
755 Object.defineProperty(obj6, '2', descElement); | 754 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 // non configurable property. | |
764 try { | |
765 var descAccessor = { get: function() { return 0; } }; | |
766 Object.defineProperty(obj6, '2', descAccessor); | |
767 assertUnreachable(); | 755 assertUnreachable(); |
768 } catch (e) { | 756 } catch (e) { |
769 assertTrue(/Cannot redefine property/.test(e)); | 757 assertTrue(/Cannot redefine property/.test(e)); |
770 } | 758 } |
771 | 759 |
772 Object.defineProperty(obj6, '2', descElementNonWritable); | |
773 desc = Object.getOwnPropertyDescriptor(obj6, '2'); | |
774 assertEquals(desc.value, 'foofoo'); | |
775 assertFalse(desc.writable); | |
776 assertTrue(desc.enumerable); | |
777 assertFalse(desc.configurable); | |
778 | |
779 Object.defineProperty(obj6, '3', descElementNonWritable); | 760 Object.defineProperty(obj6, '3', descElementNonWritable); |
780 desc = Object.getOwnPropertyDescriptor(obj6, '3'); | 761 desc = Object.getOwnPropertyDescriptor(obj6, '3'); |
781 assertEquals(desc.value, 'foofoo'); | 762 assertEquals(desc.value, 'foofoo'); |
782 assertFalse(desc.writable); | 763 assertFalse(desc.writable); |
783 assertTrue(desc.enumerable); | 764 assertTrue(desc.enumerable); |
784 assertTrue(desc.configurable); | 765 assertTrue(desc.configurable); |
785 | 766 |
786 // Redefine existing property with configurable: false. | 767 // Redefine existing property with configurable: false. |
787 Object.defineProperty(obj6, '4', descElementNonEnumerable); | 768 Object.defineProperty(obj6, '4', descElementNonEnumerable); |
788 desc = Object.getOwnPropertyDescriptor(obj6, '4'); | 769 desc = Object.getOwnPropertyDescriptor(obj6, '4'); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
839 assertTrue(desc.configurable); | 820 assertTrue(desc.configurable); |
840 | 821 |
841 // Redefine existing property with configurable: false. | 822 // Redefine existing property with configurable: false. |
842 Object.defineProperty(arr, '2', descElementNonConfigurable); | 823 Object.defineProperty(arr, '2', descElementNonConfigurable); |
843 desc = Object.getOwnPropertyDescriptor(arr, '2'); | 824 desc = Object.getOwnPropertyDescriptor(arr, '2'); |
844 assertEquals(desc.value, 'barfoo'); | 825 assertEquals(desc.value, 'barfoo'); |
845 assertTrue(desc.writable); | 826 assertTrue(desc.writable); |
846 assertTrue(desc.enumerable); | 827 assertTrue(desc.enumerable); |
847 assertFalse(desc.configurable); | 828 assertFalse(desc.configurable); |
848 | 829 |
849 // Can use defineProperty to change the value of a non | 830 // Ensure that we can't overwrite the non configurable element. |
850 // configurable property of an array. | |
851 try { | 831 try { |
852 Object.defineProperty(arr, '2', descElement); | 832 Object.defineProperty(arr, '2', descElement); |
853 desc = Object.getOwnPropertyDescriptor(arr, '2'); | |
854 assertEquals(desc.value, 'foobar'); | |
855 } catch (e) { | |
856 assertUnreachable(); | |
857 } | |
858 | |
859 // Ensure that we can't change the descriptor of a | |
860 // non configurable property. | |
861 try { | |
862 var descAccessor = { get: function() { return 0; } }; | |
863 Object.defineProperty(arr, '2', descAccessor); | |
864 assertUnreachable(); | 833 assertUnreachable(); |
865 } catch (e) { | 834 } catch (e) { |
866 assertTrue(/Cannot redefine property/.test(e)); | 835 assertTrue(/Cannot redefine property/.test(e)); |
867 } | 836 } |
868 | 837 |
869 Object.defineProperty(arr, '2', descElementNonWritable); | |
870 desc = Object.getOwnPropertyDescriptor(arr, '2'); | |
871 assertEquals(desc.value, 'foofoo'); | |
872 assertFalse(desc.writable); | |
873 assertTrue(desc.enumerable); | |
874 assertFalse(desc.configurable); | |
875 | |
876 Object.defineProperty(arr, '3', descElementNonWritable); | 838 Object.defineProperty(arr, '3', descElementNonWritable); |
877 desc = Object.getOwnPropertyDescriptor(arr, '3'); | 839 desc = Object.getOwnPropertyDescriptor(arr, '3'); |
878 assertEquals(desc.value, 'foofoo'); | 840 assertEquals(desc.value, 'foofoo'); |
879 assertFalse(desc.writable); | 841 assertFalse(desc.writable); |
880 assertTrue(desc.enumerable); | 842 assertTrue(desc.enumerable); |
881 assertTrue(desc.configurable); | 843 assertTrue(desc.configurable); |
882 | 844 |
883 // Redefine existing property with configurable: false. | 845 // Redefine existing property with configurable: false. |
884 Object.defineProperty(arr, '4', descElementNonEnumerable); | 846 Object.defineProperty(arr, '4', descElementNonEnumerable); |
885 desc = Object.getOwnPropertyDescriptor(arr, '4'); | 847 desc = Object.getOwnPropertyDescriptor(arr, '4'); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
929 assertEquals(undefined, o.x); | 891 assertEquals(undefined, o.x); |
930 o.x = 37; | 892 o.x = 37; |
931 assertEquals(undefined, o.x); | 893 assertEquals(undefined, o.x); |
932 | 894 |
933 // Ignore inherited properties. | 895 // Ignore inherited properties. |
934 o = { __proto__ : { x : 87 } }; | 896 o = { __proto__ : { x : 87 } }; |
935 Object.defineProperty(o, "x", { writable: false }); | 897 Object.defineProperty(o, "x", { writable: false }); |
936 assertEquals(undefined, o.x); | 898 assertEquals(undefined, o.x); |
937 o.x = 37; | 899 o.x = 37; |
938 assertEquals(undefined, o.x); | 900 assertEquals(undefined, o.x); |
OLD | NEW |