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