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

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

Issue 7053035: Fix a number of tests that incorrectly used assertUnreachable. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address comments. Created 9 years, 6 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/mjsunit/function-call.js ('k') | test/mjsunit/object-freeze.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 12 matching lines...) Expand all
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 // Tests the object.defineProperty method - ES 15.2.3.6 28 // Tests the object.defineProperty method - ES 15.2.3.6
29 29
30 // Flags: --allow-natives-syntax 30 // Flags: --allow-natives-syntax
31 31
32 // Check that an exception is thrown when null is passed as object. 32 // Check that an exception is thrown when null is passed as object.
33 var exception = false;
33 try { 34 try {
34 Object.defineProperty(null, null, null); 35 Object.defineProperty(null, null, null);
35 assertTrue(false);
36 } catch (e) { 36 } catch (e) {
37 exception = true;
37 assertTrue(/called on non-object/.test(e)); 38 assertTrue(/called on non-object/.test(e));
38 } 39 }
40 assertTrue(exception);
39 41
40 // Check that an exception is thrown when undefined is passed as object. 42 // Check that an exception is thrown when undefined is passed as object.
43 exception = false;
41 try { 44 try {
42 Object.defineProperty(undefined, undefined, undefined); 45 Object.defineProperty(undefined, undefined, undefined);
43 assertTrue(false);
44 } catch (e) { 46 } catch (e) {
47 exception = true;
45 assertTrue(/called on non-object/.test(e)); 48 assertTrue(/called on non-object/.test(e));
46 } 49 }
50 assertTrue(exception);
47 51
48 // Check that an exception is thrown when non-object is passed as object. 52 // Check that an exception is thrown when non-object is passed as object.
53 exception = false;
49 try { 54 try {
50 Object.defineProperty(0, "foo", undefined); 55 Object.defineProperty(0, "foo", undefined);
51 assertTrue(false);
52 } catch (e) { 56 } catch (e) {
57 exception = true;
53 assertTrue(/called on non-object/.test(e)); 58 assertTrue(/called on non-object/.test(e));
54 } 59 }
60 assertTrue(exception);
55 61
56 // Object. 62 // Object.
57 var obj1 = {}; 63 var obj1 = {};
58 64
59 // Values. 65 // Values.
60 var val1 = 0; 66 var val1 = 0;
61 var val2 = 0; 67 var val2 = 0;
62 var val3 = 0; 68 var val3 = 0;
63 69
64 function setter1() {val1++; } 70 function setter1() {val1++; }
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 694
689 // Make sure that we can't overwrite +0 with -0 and vice versa. 695 // Make sure that we can't overwrite +0 with -0 and vice versa.
690 var descMinusZero = {value: -0, configurable: false}; 696 var descMinusZero = {value: -0, configurable: false};
691 var descPlusZero = {value: +0, configurable: false}; 697 var descPlusZero = {value: +0, configurable: false};
692 698
693 Object.defineProperty(obj5, 'minuszero', descMinusZero); 699 Object.defineProperty(obj5, 'minuszero', descMinusZero);
694 700
695 // Make sure we can redefine with -0. 701 // Make sure we can redefine with -0.
696 Object.defineProperty(obj5, 'minuszero', descMinusZero); 702 Object.defineProperty(obj5, 'minuszero', descMinusZero);
697 703
704 exception = false;
698 try { 705 try {
699 Object.defineProperty(obj5, 'minuszero', descPlusZero); 706 Object.defineProperty(obj5, 'minuszero', descPlusZero);
700 assertUnreachable();
701 } catch (e) { 707 } catch (e) {
708 exception = true;
702 assertTrue(/Cannot redefine property/.test(e)); 709 assertTrue(/Cannot redefine property/.test(e));
703 } 710 }
711 assertTrue(exception);
704 712
705 713
706 Object.defineProperty(obj5, 'pluszero', descPlusZero); 714 Object.defineProperty(obj5, 'pluszero', descPlusZero);
707 715
708 // Make sure we can redefine with +0. 716 // Make sure we can redefine with +0.
709 Object.defineProperty(obj5, 'pluszero', descPlusZero); 717 Object.defineProperty(obj5, 'pluszero', descPlusZero);
710 718
719 exception = false;
711 try { 720 try {
712 Object.defineProperty(obj5, 'pluszero', descMinusZero); 721 Object.defineProperty(obj5, 'pluszero', descMinusZero);
713 assertUnreachable();
714 } catch (e) { 722 } catch (e) {
723 exception = true;
715 assertTrue(/Cannot redefine property/.test(e)); 724 assertTrue(/Cannot redefine property/.test(e));
716 } 725 }
726 assertTrue(exception);
717 727
718 728
719 var obj6 = {}; 729 var obj6 = {};
720 obj6[1] = 'foo'; 730 obj6[1] = 'foo';
721 obj6[2] = 'bar'; 731 obj6[2] = 'bar';
722 obj6[3] = '42'; 732 obj6[3] = '42';
723 obj6[4] = '43'; 733 obj6[4] = '43';
724 obj6[5] = '44'; 734 obj6[5] = '44';
725 735
726 var descElement = { value: 'foobar' }; 736 var descElement = { value: 'foobar' };
(...skipping 27 matching lines...) Expand all
754 try { 764 try {
755 Object.defineProperty(obj6, '2', descElement); 765 Object.defineProperty(obj6, '2', descElement);
756 desc = Object.getOwnPropertyDescriptor(obj6, '2'); 766 desc = Object.getOwnPropertyDescriptor(obj6, '2');
757 assertEquals(desc.value, 'foobar'); 767 assertEquals(desc.value, 'foobar');
758 } catch (e) { 768 } catch (e) {
759 assertUnreachable(); 769 assertUnreachable();
760 } 770 }
761 771
762 // Ensure that we can't change the descriptor of a 772 // Ensure that we can't change the descriptor of a
763 // non configurable property. 773 // non configurable property.
774 exception = false;
764 try { 775 try {
765 var descAccessor = { get: function() { return 0; } }; 776 var descAccessor = { get: function() { return 0; } };
766 Object.defineProperty(obj6, '2', descAccessor); 777 Object.defineProperty(obj6, '2', descAccessor);
767 assertUnreachable();
768 } catch (e) { 778 } catch (e) {
779 exception = true;
769 assertTrue(/Cannot redefine property/.test(e)); 780 assertTrue(/Cannot redefine property/.test(e));
770 } 781 }
782 assertTrue(exception);
771 783
772 Object.defineProperty(obj6, '2', descElementNonWritable); 784 Object.defineProperty(obj6, '2', descElementNonWritable);
773 desc = Object.getOwnPropertyDescriptor(obj6, '2'); 785 desc = Object.getOwnPropertyDescriptor(obj6, '2');
774 assertEquals(desc.value, 'foofoo'); 786 assertEquals(desc.value, 'foofoo');
775 assertFalse(desc.writable); 787 assertFalse(desc.writable);
776 assertTrue(desc.enumerable); 788 assertTrue(desc.enumerable);
777 assertFalse(desc.configurable); 789 assertFalse(desc.configurable);
778 790
779 Object.defineProperty(obj6, '3', descElementNonWritable); 791 Object.defineProperty(obj6, '3', descElementNonWritable);
780 desc = Object.getOwnPropertyDescriptor(obj6, '3'); 792 desc = Object.getOwnPropertyDescriptor(obj6, '3');
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 try { 863 try {
852 Object.defineProperty(arr, '2', descElement); 864 Object.defineProperty(arr, '2', descElement);
853 desc = Object.getOwnPropertyDescriptor(arr, '2'); 865 desc = Object.getOwnPropertyDescriptor(arr, '2');
854 assertEquals(desc.value, 'foobar'); 866 assertEquals(desc.value, 'foobar');
855 } catch (e) { 867 } catch (e) {
856 assertUnreachable(); 868 assertUnreachable();
857 } 869 }
858 870
859 // Ensure that we can't change the descriptor of a 871 // Ensure that we can't change the descriptor of a
860 // non configurable property. 872 // non configurable property.
873 exception = false;
861 try { 874 try {
862 var descAccessor = { get: function() { return 0; } }; 875 var descAccessor = { get: function() { return 0; } };
863 Object.defineProperty(arr, '2', descAccessor); 876 Object.defineProperty(arr, '2', descAccessor);
864 assertUnreachable();
865 } catch (e) { 877 } catch (e) {
878 exception = true;
866 assertTrue(/Cannot redefine property/.test(e)); 879 assertTrue(/Cannot redefine property/.test(e));
867 } 880 }
881 assertTrue(exception);
868 882
869 Object.defineProperty(arr, '2', descElementNonWritable); 883 Object.defineProperty(arr, '2', descElementNonWritable);
870 desc = Object.getOwnPropertyDescriptor(arr, '2'); 884 desc = Object.getOwnPropertyDescriptor(arr, '2');
871 assertEquals(desc.value, 'foofoo'); 885 assertEquals(desc.value, 'foofoo');
872 assertFalse(desc.writable); 886 assertFalse(desc.writable);
873 assertTrue(desc.enumerable); 887 assertTrue(desc.enumerable);
874 assertFalse(desc.configurable); 888 assertFalse(desc.configurable);
875 889
876 Object.defineProperty(arr, '3', descElementNonWritable); 890 Object.defineProperty(arr, '3', descElementNonWritable);
877 desc = Object.getOwnPropertyDescriptor(arr, '3'); 891 desc = Object.getOwnPropertyDescriptor(arr, '3');
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 { enumerable : false, configurable : false }, 1038 { enumerable : false, configurable : false },
1025 { get: getter1, set: setter1, enumerable : false, configurable : false }); 1039 { get: getter1, set: setter1, enumerable : false, configurable : false });
1026 1040
1027 // redefine of set only property with generic descriptor 1041 // redefine of set only property with generic descriptor
1028 o = {}; 1042 o = {};
1029 Object.defineProperty(o, 'p', 1043 Object.defineProperty(o, 'p',
1030 { set : setter1, enumerable: true, configurable: true }); 1044 { set : setter1, enumerable: true, configurable: true });
1031 testDefineProperty(o, 'p', 1045 testDefineProperty(o, 'p',
1032 { enumerable : false, configurable : false }, 1046 { enumerable : false, configurable : false },
1033 { get: undefined, set: setter1, enumerable : false, configurable : false }); 1047 { get: undefined, set: setter1, enumerable : false, configurable : false });
OLDNEW
« no previous file with comments | « test/mjsunit/function-call.js ('k') | test/mjsunit/object-freeze.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698