OLD | NEW |
---|---|
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Flags: --harmony-classes --allow-natives-syntax | 5 // Flags: --harmony-classes --allow-natives-syntax |
6 | 6 |
7 (function TestSuperNamedLoads() { | 7 (function TestSuperNamedLoads() { |
8 function Base() { } | 8 function Base() { } |
9 function fBase() { } | 9 function fBase() { } |
10 Base.prototype = { | 10 Base.prototype = { |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
588 }; | 588 }; |
589 | 589 |
590 function Derived() {} | 590 function Derived() {} |
591 Derived.prototype = { | 591 Derived.prototype = { |
592 __proto__: Base.prototype, | 592 __proto__: Base.prototype, |
593 constructor: Derived, | 593 constructor: Derived, |
594 testSetter() { | 594 testSetter() { |
595 setCalled = 0; | 595 setCalled = 0; |
596 getCalled = 0; | 596 getCalled = 0; |
597 assertEquals('object', typeof this); | 597 assertEquals('object', typeof this); |
598 assertTrue(this instanceof Number) | 598 assertInstanceof(this, Number) |
599 assertEquals(42, this.valueOf()); | 599 assertEquals(42, this.valueOf()); |
600 assertEquals(1, super.x); | 600 assertEquals(1, super.x); |
601 assertEquals(1, getCalled); | 601 assertEquals(1, getCalled); |
602 assertEquals(0, setCalled); | 602 assertEquals(0, setCalled); |
603 | 603 |
604 assertEquals(5, super.x = 5); | 604 assertEquals(5, super.x = 5); |
605 assertEquals(1, getCalled); | 605 assertEquals(1, getCalled); |
606 assertEquals(1, setCalled); | 606 assertEquals(1, setCalled); |
607 | 607 |
608 assertEquals(6, super.x += 5); | 608 assertEquals(6, super.x += 5); |
(...skipping 19 matching lines...) Expand all Loading... | |
628 assertEquals(1, setCalled); | 628 assertEquals(1, setCalled); |
629 | 629 |
630 assertEquals(6, super.x += 5); | 630 assertEquals(6, super.x += 5); |
631 assertEquals(2, getCalled); | 631 assertEquals(2, getCalled); |
632 assertEquals(2, setCalled); | 632 assertEquals(2, setCalled); |
633 | 633 |
634 var ex; | 634 var ex; |
635 try { | 635 try { |
636 super.newProperty = 15; | 636 super.newProperty = 15; |
637 } catch (e) { ex = e; } | 637 } catch (e) { ex = e; } |
638 assertTrue(ex instanceof TypeError); | 638 assertInstanceof(ex, TypeError); |
639 } | 639 } |
640 } | 640 } |
641 | 641 |
642 Derived.prototype.testSetter.call(42); | 642 Derived.prototype.testSetter.call(42); |
643 Derived.prototype.testSetterStrict.call(42); | 643 Derived.prototype.testSetterStrict.call(42); |
644 | 644 |
645 function DerivedFromString() {} | 645 function DerivedFromString() {} |
646 DerivedFromString.prototype = { | 646 DerivedFromString.prototype = { |
647 __proto__: String.prototype, | 647 __proto__: String.prototype, |
648 f() { | 648 f() { |
649 'use strict'; | 649 'use strict'; |
650 assertTrue(42 === this); | 650 assertTrue(42 === this); |
651 assertEquals(String.prototype.toString, super.toString); | 651 assertEquals(String.prototype.toString, super.toString); |
652 var ex; | 652 var ex; |
653 try { | 653 try { |
654 super.toString(); | 654 super.toString(); |
655 } catch(e) { ex = e; } | 655 } catch(e) { ex = e; } |
656 | 656 |
657 assertTrue(ex instanceof TypeError); | 657 assertInstanceof(ex, TypeError); |
658 } | 658 } |
659 }; | 659 }; |
660 | 660 |
661 DerivedFromString.prototype.f.call(42); | 661 DerivedFromString.prototype.f.call(42); |
662 }()); | 662 }()); |
663 | 663 |
664 | 664 |
665 (function TestKeyedAccessorsOnPrimitives() { | 665 (function TestKeyedAccessorsOnPrimitives() { |
666 var x = 'x'; | 666 var x = 'x'; |
667 var newProperty = 'newProperty'; | 667 var newProperty = 'newProperty'; |
(...skipping 14 matching lines...) Expand all Loading... | |
682 }; | 682 }; |
683 | 683 |
684 function Derived() {} | 684 function Derived() {} |
685 Derived.prototype = { | 685 Derived.prototype = { |
686 __proto__: Base.prototype, | 686 __proto__: Base.prototype, |
687 constructor: Derived, | 687 constructor: Derived, |
688 testSetter() { | 688 testSetter() { |
689 setCalled = 0; | 689 setCalled = 0; |
690 getCalled = 0; | 690 getCalled = 0; |
691 assertEquals('object', typeof this); | 691 assertEquals('object', typeof this); |
692 assertTrue(this instanceof Number) | 692 assertInstanceof(this, Number) |
693 assertEquals(42, this.valueOf()); | 693 assertEquals(42, this.valueOf()); |
694 assertEquals(1, super[x]); | 694 assertEquals(1, super[x]); |
695 assertEquals(1, getCalled); | 695 assertEquals(1, getCalled); |
696 assertEquals(0, setCalled); | 696 assertEquals(0, setCalled); |
697 | 697 |
698 assertEquals(5, super[x] = 5); | 698 assertEquals(5, super[x] = 5); |
699 assertEquals(1, getCalled); | 699 assertEquals(1, getCalled); |
700 assertEquals(1, setCalled); | 700 assertEquals(1, setCalled); |
701 | 701 |
702 assertEquals(6, super[x] += 5); | 702 assertEquals(6, super[x] += 5); |
(...skipping 19 matching lines...) Expand all Loading... | |
722 assertEquals(1, setCalled); | 722 assertEquals(1, setCalled); |
723 | 723 |
724 assertEquals(6, super[x] += 5); | 724 assertEquals(6, super[x] += 5); |
725 assertEquals(2, getCalled); | 725 assertEquals(2, getCalled); |
726 assertEquals(2, setCalled); | 726 assertEquals(2, setCalled); |
727 | 727 |
728 var ex; | 728 var ex; |
729 try { | 729 try { |
730 super[newProperty] = 15; | 730 super[newProperty] = 15; |
731 } catch (e) { ex = e; } | 731 } catch (e) { ex = e; } |
732 assertTrue(ex instanceof TypeError); | 732 assertInstanceof(ex,TypeError); |
733 } | 733 } |
734 }; | 734 }; |
735 | 735 |
736 Derived.prototype.testSetter.call(42); | 736 Derived.prototype.testSetter.call(42); |
737 Derived.prototype.testSetterStrict.call(42); | 737 Derived.prototype.testSetterStrict.call(42); |
738 | 738 |
739 function DerivedFromString() {} | 739 function DerivedFromString() {} |
740 DerivedFromString.prototype = { | 740 DerivedFromString.prototype = { |
741 __proto__: String.prototype, | 741 __proto__: String.prototype, |
742 f() { | 742 f() { |
743 'use strict'; | 743 'use strict'; |
744 assertTrue(42 === this); | 744 assertTrue(42 === this); |
745 assertEquals(String.prototype.toString, super[toString]); | 745 assertEquals(String.prototype.toString, super[toString]); |
746 var ex; | 746 var ex; |
747 try { | 747 try { |
748 super[toString](); | 748 super[toString](); |
749 } catch(e) { ex = e; } | 749 } catch(e) { ex = e; } |
750 | 750 |
751 assertTrue(ex instanceof TypeError); | 751 assertInstanceof(ex, TypeError); |
752 } | 752 } |
753 }; | 753 }; |
754 DerivedFromString.prototype.f.call(42); | 754 DerivedFromString.prototype.f.call(42); |
755 }()); | 755 }()); |
756 | 756 |
757 | 757 |
758 (function TestNumericKeyedAccessorsOnPrimitives() { | 758 (function TestNumericKeyedAccessorsOnPrimitives() { |
759 var x = 42; | 759 var x = 42; |
760 var newProperty = 43; | 760 var newProperty = 43; |
761 var getCalled = 0; | 761 var getCalled = 0; |
(...skipping 15 matching lines...) Expand all Loading... | |
777 }); | 777 }); |
778 | 778 |
779 function Derived() {} | 779 function Derived() {} |
780 Derived.prototype = { | 780 Derived.prototype = { |
781 __proto__: Base.prototype, | 781 __proto__: Base.prototype, |
782 constructor: Derived, | 782 constructor: Derived, |
783 testSetter() { | 783 testSetter() { |
784 setCalled = 0; | 784 setCalled = 0; |
785 getCalled = 0; | 785 getCalled = 0; |
786 assertEquals('object', typeof this); | 786 assertEquals('object', typeof this); |
787 assertTrue(this instanceof Number) | 787 assertInstanceof(this, Number) |
788 assertEquals(42, this.valueOf()); | 788 assertEquals(42, this.valueOf()); |
789 assertEquals(1, super[x]); | 789 assertEquals(1, super[x]); |
790 assertEquals(1, getCalled); | 790 assertEquals(1, getCalled); |
791 assertEquals(0, setCalled); | 791 assertEquals(0, setCalled); |
792 | 792 |
793 assertEquals(5, super[x] = 5); | 793 assertEquals(5, super[x] = 5); |
794 assertEquals(1, getCalled); | 794 assertEquals(1, getCalled); |
795 assertEquals(1, setCalled); | 795 assertEquals(1, setCalled); |
796 | 796 |
797 assertEquals(6, super[x] += 5); | 797 assertEquals(6, super[x] += 5); |
(...skipping 19 matching lines...) Expand all Loading... | |
817 assertEquals(1, setCalled); | 817 assertEquals(1, setCalled); |
818 | 818 |
819 assertEquals(6, super[x] += 5); | 819 assertEquals(6, super[x] += 5); |
820 assertEquals(2, getCalled); | 820 assertEquals(2, getCalled); |
821 assertEquals(2, setCalled); | 821 assertEquals(2, setCalled); |
822 | 822 |
823 var ex; | 823 var ex; |
824 try { | 824 try { |
825 super[newProperty] = 15; | 825 super[newProperty] = 15; |
826 } catch (e) { ex = e; } | 826 } catch (e) { ex = e; } |
827 assertTrue(ex instanceof TypeError); | 827 assertInstanceof(ex, TypeError); |
828 } | 828 } |
829 }; | 829 }; |
830 | 830 |
831 Derived.prototype.testSetter.call(42); | 831 Derived.prototype.testSetter.call(42); |
832 Derived.prototype.testSetterStrict.call(42); | 832 Derived.prototype.testSetterStrict.call(42); |
833 }()); | 833 }()); |
834 | 834 |
835 | 835 |
836 (function TestKeyedNumericSetterOnExotics() { | 836 (function TestKeyedNumericSetterOnExotics() { |
837 function Base() {} | 837 function Base() {} |
838 function Derived() {} | 838 function Derived() {} |
839 Derived.prototype = { | 839 Derived.prototype = { |
840 __proto__: Base.prototype, | 840 __proto__: Base.prototype, |
841 callSetterOnArray() { | 841 callSetterOnArray() { |
842 super[42] = 1; | 842 super[42] = 1; |
843 }, | 843 }, |
844 callStrictSetterOnString() { | 844 callStrictSetterOnString() { |
845 'use strict'; | 845 'use strict'; |
846 assertEquals('string', typeof this); | 846 assertEquals('string', typeof this); |
847 assertTrue('abcdef' === this); | 847 assertTrue('abcdef' === this); |
848 var ex = null; | 848 var ex = null; |
849 try { | 849 try { |
850 super[5] = 'q'; | 850 super[5] = 'q'; |
851 } catch(e) { ex = e; } | 851 } catch(e) { ex = e; } |
852 assertTrue(ex instanceof TypeError); | 852 assertInstanceof(ex, TypeError); |
853 | 853 |
854 ex = null; | 854 ex = null; |
855 try { | 855 try { |
856 super[1024] = 'q'; | 856 super[1024] = 'q'; |
857 } catch(e) { ex = e; } | 857 } catch(e) { ex = e; } |
858 assertTrue(ex instanceof TypeError); | 858 assertInstanceof(ex, TypeError); |
859 } | 859 } |
860 }; | 860 }; |
861 | 861 |
862 var x = []; | 862 var x = []; |
863 assertEquals(0, x.length); | 863 assertEquals(0, x.length); |
864 Derived.prototype.callSetterOnArray.call(x); | 864 Derived.prototype.callSetterOnArray.call(x); |
865 assertEquals(43, x.length); | 865 assertEquals(43, x.length); |
866 assertEquals(1, x[42]); | 866 assertEquals(1, x[42]); |
867 | 867 |
868 var s = 'abcdef'; | 868 var s = 'abcdef'; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
956 }; | 956 }; |
957 var d = new Derived(); | 957 var d = new Derived(); |
958 d.mSloppy(); | 958 d.mSloppy(); |
959 assertEquals(10, d[x]); | 959 assertEquals(10, d[x]); |
960 var d1 = new Derived(); | 960 var d1 = new Derived(); |
961 d1.mStrict(); | 961 d1.mStrict(); |
962 assertEquals(10, d[x]); | 962 assertEquals(10, d[x]); |
963 }()); | 963 }()); |
964 | 964 |
965 | 965 |
966 (function TestSetterCreatingOwnProperties() { | 966 (function TestSetterCreatingOwnPropertiesReconfigurable() { |
967 var setterCalled; | |
968 function Base() {} | 967 function Base() {} |
969 function Derived() {} | 968 function Derived() {} |
970 Derived.prototype = { | 969 Derived.prototype = { |
970 __proto__: Base.prototype, | |
971 mSloppy() { | |
972 assertEquals(42, this.ownReadOnly); | |
973 super.ownReadOnly = 55; | |
974 assertEquals(55, this.ownReadOnly); | |
975 var descr = Object.getOwnPropertyDescriptor(this, 'ownReadOnly'); | |
976 assertEquals(55, descr.value); | |
977 assertTrue(descr.configurable); | |
978 assertFalse(descr.enumerable); | |
979 assertFalse(descr.writable); | |
980 assertFalse(Base.prototype.hasOwnProperty('ownReadOnly')); | |
981 | |
982 assertEquals(15, this.ownReadonlyAccessor); | |
983 super.ownReadonlyAccessor = 25; | |
984 assertEquals(25, this.ownReadonlyAccessor); | |
985 var descr = Object.getOwnPropertyDescriptor(this, 'ownReadonlyAccessor'); | |
986 assertEquals(25, descr.value); | |
987 assertTrue(descr.configurable); | |
988 assertFalse(descr.enumerable); | |
989 assertTrue(descr.writable); | |
990 assertFalse(Base.prototype.hasOwnProperty('ownReadonlyAccessor')); | |
991 | |
992 super.ownSetter = 35; | |
993 assertEquals(35, this.ownSetter); | |
994 var descr = Object.getOwnPropertyDescriptor(this, 'ownSetter'); | |
995 assertEquals(35, descr.value); | |
996 assertTrue(descr.configurable); | |
997 assertFalse(descr.enumerable); | |
998 assertTrue(descr.writable); | |
999 assertFalse(Base.prototype.hasOwnProperty('ownSetter')); | |
1000 }, | |
1001 mStrict() { | |
1002 'use strict'; | |
1003 assertEquals(42, this.ownReadOnly); | |
1004 super.ownReadOnly = 55; | |
1005 assertEquals(55, this.ownReadOnly); | |
1006 var descr = Object.getOwnPropertyDescriptor(this, 'ownReadOnly'); | |
1007 assertEquals(55, descr.value); | |
1008 assertTrue(descr.configurable); | |
1009 assertFalse(descr.enumerable); | |
1010 assertFalse(descr.writable); | |
1011 assertFalse(Base.prototype.hasOwnProperty('ownReadOnly')); | |
1012 | |
1013 assertEquals(15, this.ownReadonlyAccessor); | |
1014 super.ownReadonlyAccessor = 25; | |
1015 assertEquals(25, this.ownReadonlyAccessor); | |
1016 var descr = Object.getOwnPropertyDescriptor(this, 'ownReadonlyAccessor'); | |
1017 assertEquals(25, descr.value); | |
1018 assertTrue(descr.configurable); | |
1019 assertFalse(descr.enumerable); | |
1020 assertTrue(descr.writable); | |
1021 assertFalse(Base.prototype.hasOwnProperty('ownReadonlyAccessor')); | |
1022 | |
1023 super.ownSetter = 35; | |
1024 assertEquals(35, this.ownSetter); | |
1025 var descr = Object.getOwnPropertyDescriptor(this, 'ownSetter'); | |
1026 assertEquals(35, descr.value); | |
1027 assertTrue(descr.configurable); | |
1028 assertFalse(descr.enumerable); | |
1029 assertTrue(descr.writable); | |
1030 assertFalse(Base.prototype.hasOwnProperty('ownSetter')); | |
1031 }, | |
1032 }; | |
1033 | |
1034 var d = new Derived(); | |
1035 Object.defineProperty(d, 'ownReadOnly', { | |
1036 value: 42, | |
1037 writable: false, | |
1038 configurable: true | |
1039 }); | |
1040 Object.defineProperty(d, 'ownSetter', { | |
1041 set: function() { assertUnreachable(); }, | |
1042 configurable: true | |
1043 }); | |
1044 Object.defineProperty(d, 'ownReadonlyAccessor', { | |
1045 get: function() { return 15; }, | |
1046 configurable: true | |
1047 }); | |
1048 | |
1049 d.mSloppy(); | |
1050 | |
1051 var d = new Derived(); | |
1052 Object.defineProperty(d, 'ownReadOnly', { | |
1053 value: 42, | |
1054 writable: false, | |
1055 configurable: true | |
1056 }); | |
1057 Object.defineProperty(d, 'ownSetter', { | |
1058 set: function() { assertUnreachable(); }, | |
1059 configurable: true | |
1060 }); | |
1061 Object.defineProperty(d, 'ownReadonlyAccessor', { | |
1062 get: function() { return 15; }, | |
1063 configurable: true | |
1064 }); | |
1065 d.mStrict(); | |
1066 }()); | |
1067 | |
1068 | |
1069 (function TestSetterCreatingOwnPropertiesNonConfigurable() { | |
1070 function Base() {} | |
1071 function Derived() {} | |
1072 Derived.prototype = { | |
971 __proto__: Base.prototype, | 1073 __proto__: Base.prototype, |
972 mSloppy() { | 1074 mSloppy() { |
973 assertEquals(42, this.ownReadOnly); | 1075 assertEquals(42, this.ownReadOnly); |
974 super.ownReadOnly = 55; | 1076 super.ownReadOnly = 55; |
975 assertEquals(42, this.ownReadOnly); | 1077 assertEquals(42, this.ownReadOnly); |
1078 var descr = Object.getOwnPropertyDescriptor(this, 'ownReadOnly'); | |
1079 assertEquals(42, descr.value); | |
1080 assertFalse(descr.configurable); | |
1081 assertFalse(descr.enumerable); | |
1082 assertFalse(descr.writable); | |
1083 assertFalse(Base.prototype.hasOwnProperty('ownReadOnly')); | |
976 | 1084 |
1085 var ex; | |
977 assertEquals(15, this.ownReadonlyAccessor); | 1086 assertEquals(15, this.ownReadonlyAccessor); |
978 super.ownReadonlyAccessor = 55; | 1087 try { |
1088 super.ownReadonlyAccessor = 25; | |
1089 } catch (e) { | |
1090 ex = e; | |
1091 } | |
1092 assertInstanceof(ex, TypeError); | |
1093 assertEquals('Cannot redefine property: ownReadonlyAccessor', ex.message); | |
979 assertEquals(15, this.ownReadonlyAccessor); | 1094 assertEquals(15, this.ownReadonlyAccessor); |
980 | 1095 |
981 setterCalled = 0; | 1096 ex = null; |
982 super.ownSetter = 42; | 1097 try { |
983 assertEquals(1, setterCalled); | 1098 super.ownSetter = 35; |
1099 } catch (e) { | |
1100 ex = e; | |
1101 } | |
1102 assertInstanceof(ex, TypeError); | |
1103 assertEquals('Cannot redefine property: ownSetter', ex.message); | |
984 }, | 1104 }, |
985 mStrict() { | 1105 mStrict() { |
986 'use strict'; | 1106 'use strict'; |
1107 var ex; | |
987 assertEquals(42, this.ownReadOnly); | 1108 assertEquals(42, this.ownReadOnly); |
988 var ex; | |
989 try { | 1109 try { |
990 super.ownReadOnly = 55; | 1110 super.ownReadOnly = 55; |
991 } catch(e) { ex = e; } | 1111 } catch (e) { |
992 assertTrue(ex instanceof TypeError); | 1112 ex = e; |
1113 } | |
1114 assertInstanceof(ex, TypeError); | |
1115 assertEquals( | |
1116 "Cannot assign to read only property 'ownReadOnly' of #<Base>", | |
1117 ex.message); | |
993 assertEquals(42, this.ownReadOnly); | 1118 assertEquals(42, this.ownReadOnly); |
994 | 1119 |
1120 ex = null; | |
995 assertEquals(15, this.ownReadonlyAccessor); | 1121 assertEquals(15, this.ownReadonlyAccessor); |
1122 try { | |
1123 super.ownReadonlyAccessor = 25; | |
1124 } catch (e) { | |
1125 ex = e; | |
1126 } | |
1127 assertInstanceof(ex, TypeError); | |
1128 assertEquals('Cannot redefine property: ownReadonlyAccessor', ex.message); | |
1129 assertEquals(15, this.ownReadonlyAccessor); | |
1130 | |
996 ex = null; | 1131 ex = null; |
997 try { | 1132 try { |
998 super.ownReadonlyAccessor = 55; | 1133 super.ownSetter = 35; |
999 } catch(e) { ex = e; } | 1134 } catch (e) { |
1000 assertTrue(ex instanceof TypeError); | 1135 ex = e; |
1001 assertEquals(15, this.ownReadonlyAccessor); | 1136 } |
1002 | 1137 assertInstanceof(ex, TypeError); |
1003 setterCalled = 0; | 1138 assertEquals('Cannot redefine property: ownSetter', ex.message); |
1004 super.ownSetter = 42; | |
1005 assertEquals(1, setterCalled); | |
1006 } | 1139 } |
1007 }; | 1140 }; |
1008 | 1141 |
1009 var d = new Derived(); | 1142 var d = new Derived(); |
1010 Object.defineProperty(d, 'ownReadOnly', { value : 42, writable : false }); | 1143 Object.defineProperty(d, 'ownReadOnly', { value : 42, writable : false }); |
1011 Object.defineProperty(d, 'ownSetter', | 1144 Object.defineProperty(d, 'ownSetter', |
1012 { set : function() { setterCalled++; } }); | 1145 { set : function() { assertUnreachable(); } }); |
1013 Object.defineProperty(d, 'ownReadonlyAccessor', | 1146 Object.defineProperty(d, 'ownReadonlyAccessor', |
1014 { get : function() { return 15; }}); | 1147 { get : function() { return 15; }}); |
1015 d.mSloppy(); | 1148 d.mSloppy(); |
1016 d.mStrict(); | 1149 d.mStrict(); |
1017 }()); | 1150 }()); |
1018 | 1151 |
1019 | 1152 |
1020 (function TestSetterInForIn() { | 1153 (function TestSetterInForIn() { |
1021 var setCalled = 0; | 1154 var setCalled = 0; |
1022 var getCalled = 0; | 1155 var getCalled = 0; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1069 }; | 1202 }; |
1070 | 1203 |
1071 new Derived().testIter(); | 1204 new Derived().testIter(); |
1072 | 1205 |
1073 var x = 'x'; | 1206 var x = 'x'; |
1074 | 1207 |
1075 new Derived().testIterKeyed(); | 1208 new Derived().testIterKeyed(); |
1076 }()); | 1209 }()); |
1077 | 1210 |
1078 | 1211 |
1079 (function TestKeyedSetterCreatingOwnProperties() { | 1212 (function TestKeyedSetterCreatingOwnPropertiesReconfigurable() { |
1213 var ownReadOnly = 'ownReadOnly'; | |
1214 var ownReadonlyAccessor = 'ownReadonlyAccessor'; | |
1215 var ownSetter = 'ownSetter'; | |
1216 | |
1217 function Base() {} | |
1218 function Derived() {} | |
1219 Derived.prototype = { | |
1220 __proto__: Base.prototype, | |
1221 mSloppy() { | |
1222 assertEquals(42, this[ownReadOnly]); | |
1223 super[ownReadOnly] = 55; | |
1224 assertEquals(55, this[ownReadOnly]); | |
1225 var descr = Object.getOwnPropertyDescriptor(this, ownReadOnly); | |
1226 assertEquals(55, descr.value); | |
1227 assertTrue(descr.configurable); | |
1228 assertFalse(descr.enumerable); | |
1229 assertFalse(descr.writable); | |
1230 assertFalse(Base.prototype.hasOwnProperty(ownReadOnly)); | |
1231 | |
1232 assertEquals(15, this[ownReadonlyAccessor]); | |
1233 super[ownReadonlyAccessor] = 25; | |
1234 assertEquals(25, this[ownReadonlyAccessor]); | |
1235 var descr = Object.getOwnPropertyDescriptor(this, ownReadonlyAccessor); | |
1236 assertEquals(25, descr.value); | |
1237 assertTrue(descr.configurable); | |
1238 assertFalse(descr.enumerable); | |
1239 assertTrue(descr.writable); | |
1240 assertFalse(Base.prototype.hasOwnProperty(ownReadonlyAccessor)); | |
1241 | |
1242 super[ownSetter] = 35; | |
1243 assertEquals(35, this[ownSetter]); | |
1244 var descr = Object.getOwnPropertyDescriptor(this, ownSetter); | |
1245 assertEquals(35, descr.value); | |
1246 assertTrue(descr.configurable); | |
1247 assertFalse(descr.enumerable); | |
1248 assertTrue(descr.writable); | |
1249 assertFalse(Base.prototype.hasOwnProperty(ownSetter)); | |
1250 }, | |
1251 mStrict() { | |
1252 'use strict'; | |
1253 assertEquals(42, this[ownReadOnly]); | |
1254 super[ownReadOnly] = 55; | |
1255 assertEquals(55, this[ownReadOnly]); | |
1256 var descr = Object.getOwnPropertyDescriptor(this, ownReadOnly); | |
1257 assertEquals(55, descr.value); | |
1258 assertTrue(descr.configurable); | |
1259 assertFalse(descr.enumerable); | |
1260 assertFalse(descr.writable); | |
1261 assertFalse(Base.prototype.hasOwnProperty(ownReadOnly)); | |
1262 | |
1263 assertEquals(15, this[ownReadonlyAccessor]); | |
1264 super[ownReadonlyAccessor] = 25; | |
1265 assertEquals(25, this[ownReadonlyAccessor]); | |
1266 var descr = Object.getOwnPropertyDescriptor(this, 'ownReadonlyAccessor'); | |
1267 assertEquals(25, descr.value); | |
1268 assertTrue(descr.configurable); | |
1269 assertFalse(descr.enumerable); | |
1270 assertTrue(descr.writable); | |
1271 assertFalse(Base.prototype.hasOwnProperty('ownReadonlyAccessor')); | |
1272 | |
1273 super[ownSetter] = 35; | |
1274 assertEquals(35, this[ownSetter]); | |
1275 var descr = Object.getOwnPropertyDescriptor(this, ownSetter); | |
1276 assertEquals(35, descr.value); | |
1277 assertTrue(descr.configurable); | |
1278 assertFalse(descr.enumerable); | |
1279 assertTrue(descr.writable); | |
1280 assertFalse(Base.prototype.hasOwnProperty(ownSetter)); | |
1281 }, | |
1282 }; | |
1283 | |
1284 var d = new Derived(); | |
1285 Object.defineProperty(d, ownReadOnly, { | |
1286 value: 42, | |
1287 writable: false, | |
1288 configurable: true | |
1289 }); | |
1290 Object.defineProperty(d, ownSetter, { | |
1291 set: function() { assertUnreachable(); }, | |
1292 configurable: true | |
1293 }); | |
1294 Object.defineProperty(d, ownReadonlyAccessor, { | |
1295 get: function() { return 15; }, | |
1296 configurable: true | |
1297 }); | |
1298 | |
1299 d.mSloppy(); | |
1300 | |
1301 var d = new Derived(); | |
1302 Object.defineProperty(d, ownReadOnly, { | |
1303 value: 42, | |
1304 writable: false, | |
1305 configurable: true | |
1306 }); | |
1307 Object.defineProperty(d, ownSetter, { | |
1308 set: function() { assertUnreachable(); }, | |
1309 configurable: true | |
1310 }); | |
1311 Object.defineProperty(d, ownReadonlyAccessor, { | |
1312 get: function() { return 15; }, | |
1313 configurable: true | |
1314 }); | |
1315 d.mStrict(); | |
1316 })(); | |
1317 | |
1318 | |
1319 (function TestKeyedSetterCreatingOwnPropertiesNonConfigurable() { | |
1080 var ownReadOnly = 'ownReadOnly'; | 1320 var ownReadOnly = 'ownReadOnly'; |
1081 var ownReadonlyAccessor = 'ownReadonlyAccessor'; | 1321 var ownReadonlyAccessor = 'ownReadonlyAccessor'; |
1082 var ownSetter = 'ownSetter'; | 1322 var ownSetter = 'ownSetter'; |
1083 var setterCalled; | 1323 var setterCalled; |
1324 | |
1084 function Base() {} | 1325 function Base() {} |
1085 function Derived() {} | 1326 function Derived() {} |
1086 Derived.prototype = { | 1327 Derived.prototype = { |
1087 __proto__: Base.prototype, | 1328 __proto__: Base.prototype, |
1088 mSloppy() { | 1329 mSloppy() { |
1089 assertEquals(42, this[ownReadOnly]); | 1330 assertEquals(42, this[ownReadOnly]); |
1090 super[ownReadOnly] = 55; | 1331 super[ownReadOnly] = 55; |
1091 assertEquals(42, this[ownReadOnly]); | 1332 assertEquals(42, this[ownReadOnly]); |
1333 var descr = Object.getOwnPropertyDescriptor(this, ownReadOnly); | |
1334 assertEquals(42, descr.value); | |
1335 assertFalse(descr.configurable); | |
1336 assertFalse(descr.enumerable); | |
1337 assertFalse(descr.writable); | |
1338 assertFalse(Base.prototype.hasOwnProperty(ownReadOnly)); | |
1092 | 1339 |
1340 var ex; | |
1093 assertEquals(15, this[ownReadonlyAccessor]); | 1341 assertEquals(15, this[ownReadonlyAccessor]); |
1094 super[ownReadonlyAccessor] = 55; | 1342 try { |
1343 super[ownReadonlyAccessor] = 25; | |
1344 } catch (e) { | |
1345 ex = e; | |
1346 } | |
1347 assertInstanceof(ex, TypeError); | |
1348 assertEquals('Cannot redefine property: ownReadonlyAccessor', ex.message); | |
1095 assertEquals(15, this[ownReadonlyAccessor]); | 1349 assertEquals(15, this[ownReadonlyAccessor]); |
1096 | 1350 |
1097 setterCalled = 0; | 1351 setterCalled = 0; |
1098 super[ownSetter] = 42; | 1352 ex = null; |
1099 assertEquals(1, setterCalled); | 1353 try { |
1354 super[ownSetter] = 35; | |
1355 } catch (e) { | |
1356 ex = e; | |
1357 } | |
1358 assertInstanceof(ex, TypeError); | |
1359 assertEquals('Cannot redefine property: ownSetter', ex.message); | |
1360 assertEquals(0, setterCalled); | |
1100 }, | 1361 }, |
1101 mStrict() { | 1362 mStrict() { |
1102 'use strict'; | 1363 'use strict'; |
1103 assertEquals(42, this[ownReadOnly]); | |
1104 var ex; | 1364 var ex; |
1365 assertEquals(42, this.ownReadOnly); | |
1105 try { | 1366 try { |
1106 super[ownReadOnly] = 55; | 1367 super.ownReadOnly = 55; |
1107 } catch(e) { ex = e; } | 1368 } catch (e) { |
1108 assertTrue(ex instanceof TypeError); | 1369 ex = e; |
1109 assertEquals(42, this[ownReadOnly]); | 1370 } |
1371 assertInstanceof(ex, TypeError); | |
1372 assertEquals( | |
1373 "Cannot assign to read only property 'ownReadOnly' of #<Base>", | |
1374 ex.message); | |
1375 assertEquals(42, this.ownReadOnly); | |
1110 | 1376 |
1377 ex = null; | |
1111 assertEquals(15, this[ownReadonlyAccessor]); | 1378 assertEquals(15, this[ownReadonlyAccessor]); |
1112 ex = null; | |
1113 try { | 1379 try { |
1114 super[ownReadonlyAccessor] = 55; | 1380 super[ownReadonlyAccessor] = 25; |
1115 } catch(e) { ex = e; } | 1381 } catch (e) { |
1116 assertTrue(ex instanceof TypeError); | 1382 ex = e; |
1383 } | |
1384 assertInstanceof(ex, TypeError); | |
1385 assertEquals('Cannot redefine property: ownReadonlyAccessor', ex.message); | |
1117 assertEquals(15, this[ownReadonlyAccessor]); | 1386 assertEquals(15, this[ownReadonlyAccessor]); |
1118 | 1387 |
1119 setterCalled = 0; | 1388 setterCalled = 0; |
1120 super[ownSetter] = 42; | 1389 ex = null; |
1121 assertEquals(1, setterCalled); | 1390 try { |
1391 super[ownSetter] = 35; | |
1392 } catch (e) { | |
1393 ex = e; | |
1394 } | |
1395 assertInstanceof(ex, TypeError); | |
1396 assertEquals('Cannot redefine property: ownSetter', ex.message); | |
1397 assertEquals(0, setterCalled); | |
1122 } | 1398 } |
1123 }; | 1399 }; |
1124 | 1400 |
1125 var d = new Derived(); | 1401 var d = new Derived(); |
1126 Object.defineProperty(d, 'ownReadOnly', { value : 42, writable : false }); | 1402 Object.defineProperty(d, 'ownReadOnly', { value : 42, writable : false }); |
1127 Object.defineProperty(d, 'ownSetter', | 1403 Object.defineProperty(d, 'ownSetter', |
1128 { set : function() { setterCalled++; } }); | 1404 { set : function() { setterCalled++; } }); |
1129 Object.defineProperty(d, 'ownReadonlyAccessor', | 1405 Object.defineProperty(d, 'ownReadonlyAccessor', |
1130 { get : function() { return 15; }}); | 1406 { get : function() { return 15; }}); |
1131 d.mSloppy(); | 1407 d.mSloppy(); |
1132 d.mStrict(); | 1408 d.mStrict(); |
1409 | |
1133 }()); | 1410 }()); |
1134 | 1411 |
1135 | 1412 |
1413 // TODO(arv): This is broken | |
adamk
2015/02/17 22:47:45
Is this a stray TODO?
arv (Not doing code reviews)
2015/02/17 22:55:05
Done.
| |
1136 (function TestKeyedNumericSetterCreatingOwnProperties() { | 1414 (function TestKeyedNumericSetterCreatingOwnProperties() { |
adamk
2015/02/17 22:47:45
Is there any reason this test needs to duplicate a
arv (Not doing code reviews)
2015/02/17 22:55:05
That seems doable. Let me do that.
| |
1137 var ownReadOnly = 42; | 1415 var ownReadOnly = 42; |
1138 var ownReadonlyAccessor = 43; | 1416 var ownReadonlyAccessor = 43; |
1139 var ownSetter = 44; | 1417 var ownSetter = 44; |
1140 var setterCalled; | 1418 |
1141 function Base() {} | 1419 function Base() {} |
1142 function Derived() {} | 1420 function Derived() {} |
1143 Derived.prototype = { | 1421 Derived.prototype = { |
1144 __proto__: Base.prototype, | 1422 __proto__: Base.prototype, |
1145 mSloppy() { | 1423 mSloppy() { |
1146 assertEquals(42, this[ownReadOnly]); | 1424 assertEquals(42, this[ownReadOnly]); |
1147 super[ownReadOnly] = 55; | 1425 super[ownReadOnly] = 55; |
1148 assertEquals(42, this[ownReadOnly]); | 1426 assertEquals(42, this[ownReadOnly]); |
1149 | 1427 |
1428 var ex; | |
1150 assertEquals(15, this[ownReadonlyAccessor]); | 1429 assertEquals(15, this[ownReadonlyAccessor]); |
1151 super[ownReadonlyAccessor] = 55; | 1430 try { |
1431 super[ownReadonlyAccessor] = 55; | |
1432 } catch (e) { | |
1433 ex = e; | |
1434 } | |
1435 assertInstanceof(ex, TypeError); | |
1436 assertEquals('Cannot redefine property: 43', ex.message); | |
1152 assertEquals(15, this[ownReadonlyAccessor]); | 1437 assertEquals(15, this[ownReadonlyAccessor]); |
1153 | 1438 |
1154 setterCalled = 0; | 1439 ex = null; |
1155 super[ownSetter] = 42; | 1440 try { |
1156 assertEquals(1, setterCalled); | 1441 super[ownSetter] = 42; |
1442 } catch (e) { | |
1443 ex = e; | |
1444 } | |
1445 assertInstanceof(ex, TypeError); | |
1446 assertEquals('Cannot redefine property: 44', ex.message); | |
1157 }, | 1447 }, |
1158 mStrict() { | 1448 mStrict() { |
1159 'use strict'; | 1449 'use strict'; |
1450 var ex; | |
1160 assertEquals(42, this[ownReadOnly]); | 1451 assertEquals(42, this[ownReadOnly]); |
1161 var ex; | |
1162 try { | 1452 try { |
1163 super[ownReadOnly] = 55; | 1453 super[ownReadOnly] = 55; |
1164 } catch(e) { ex = e; } | 1454 } catch (e) { |
1165 assertTrue(ex instanceof TypeError); | 1455 ex = e; |
1456 } | |
1457 assertInstanceof(ex, TypeError); | |
1458 assertEquals("Cannot assign to read only property '42' of #<Base>", | |
1459 ex.message); | |
1166 assertEquals(42, this[ownReadOnly]); | 1460 assertEquals(42, this[ownReadOnly]); |
1167 | 1461 |
1168 assertEquals(15, this[ownReadonlyAccessor]); | 1462 assertEquals(15, this[ownReadonlyAccessor]); |
1463 try { | |
1464 super[ownReadonlyAccessor] = 55; | |
1465 } catch (e) { | |
1466 ex = e; | |
1467 } | |
1468 assertInstanceof(ex, TypeError); | |
1469 assertEquals('Cannot redefine property: 43', ex.message); | |
1470 assertEquals(15, this[ownReadonlyAccessor]); | |
1471 | |
1169 ex = null; | 1472 ex = null; |
1170 try { | 1473 try { |
1171 super[ownReadonlyAccessor] = 55; | 1474 super[ownSetter] = 42; |
1172 } catch(e) { ex = e; } | 1475 } catch (e) { |
1173 assertTrue(ex instanceof TypeError); | 1476 ex = e; |
1174 assertEquals(15, this[ownReadonlyAccessor]); | 1477 } |
1478 assertInstanceof(ex, TypeError); | |
1479 assertEquals('Cannot redefine property: 44', ex.message); | |
1175 | 1480 |
1176 setterCalled = 0; | |
1177 super[ownSetter] = 42; | |
1178 assertEquals(1, setterCalled); | |
1179 } | 1481 } |
1180 } | 1482 } |
1181 | 1483 |
1182 var d = new Derived(); | 1484 var d = new Derived(); |
1183 Object.defineProperty(d, ownReadOnly, { value : 42, writable : false }); | 1485 Object.defineProperty(d, ownReadOnly, { value : 42, writable : false }); |
1184 Object.defineProperty(d, ownSetter, | 1486 Object.defineProperty(d, ownSetter, |
1185 { set : function() { setterCalled++; } }); | 1487 { set : function() { assertUnreachable(); } }); |
1186 Object.defineProperty(d, ownReadonlyAccessor, | 1488 Object.defineProperty(d, ownReadonlyAccessor, |
1187 { get : function() { return 15; }}); | 1489 { get : function() { return 15; }}); |
1188 d.mSloppy(); | 1490 d.mSloppy(); |
1189 d.mStrict(); | 1491 d.mStrict(); |
1190 }()); | 1492 }()); |
1191 | 1493 |
1192 | 1494 |
1193 (function TestSetterNoProtoWalk() { | 1495 (function TestSetterNoProtoWalk() { |
1194 function Base() {} | 1496 function Base() {} |
1195 function Derived() {} | 1497 function Derived() {} |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1677 super.x = 10; | 1979 super.x = 10; |
1678 assertEquals(27, super.x); | 1980 assertEquals(27, super.x); |
1679 assertEquals(27, this.x); | 1981 assertEquals(27, this.x); |
1680 }, | 1982 }, |
1681 mStrict() { | 1983 mStrict() { |
1682 'use strict'; | 1984 'use strict'; |
1683 assertEquals(27, super.x); | 1985 assertEquals(27, super.x); |
1684 assertEquals(27, this.x); | 1986 assertEquals(27, this.x); |
1685 var ex = null; | 1987 var ex = null; |
1686 try { super.x = 10; } catch(e) { ex = e; } | 1988 try { super.x = 10; } catch(e) { ex = e; } |
1687 assertTrue(ex instanceof TypeError); | 1989 assertInstanceof(ex, TypeError); |
1688 assertEquals(27, super.x); | 1990 assertEquals(27, super.x); |
1689 assertEquals(27, this.x); | 1991 assertEquals(27, this.x); |
1690 } | 1992 } |
1691 }; | 1993 }; |
1692 new Derived().mSloppy(); | 1994 new Derived().mSloppy(); |
1693 new Derived().mStrict(); | 1995 new Derived().mStrict(); |
1694 }()); | 1996 }()); |
1695 | 1997 |
1696 | 1998 |
1697 (function TestSetterKeyedSuperNonWritable() { | 1999 (function TestSetterKeyedSuperNonWritable() { |
(...skipping 11 matching lines...) Expand all Loading... | |
1709 super[x] = 10; | 2011 super[x] = 10; |
1710 assertEquals(27, super[x]); | 2012 assertEquals(27, super[x]); |
1711 assertEquals(27, this[x]); | 2013 assertEquals(27, this[x]); |
1712 }, | 2014 }, |
1713 mStrict() { | 2015 mStrict() { |
1714 'use strict'; | 2016 'use strict'; |
1715 assertEquals(27, super[x]); | 2017 assertEquals(27, super[x]); |
1716 assertEquals(27, this[x]); | 2018 assertEquals(27, this[x]); |
1717 var ex = null; | 2019 var ex = null; |
1718 try { super[x] = 10; } catch(e) { ex = e; } | 2020 try { super[x] = 10; } catch(e) { ex = e; } |
1719 assertTrue(ex instanceof TypeError); | 2021 assertInstanceof(ex, TypeError); |
1720 assertEquals(27, super[x]); | 2022 assertEquals(27, super[x]); |
1721 assertEquals(27, this[x]); | 2023 assertEquals(27, this[x]); |
1722 } | 2024 } |
1723 }; | 2025 }; |
1724 new Derived().mSloppy(); | 2026 new Derived().mSloppy(); |
1725 new Derived().mStrict(); | 2027 new Derived().mStrict(); |
1726 }()); | 2028 }()); |
1727 | 2029 |
1728 | 2030 |
1729 (function TestSetterKeyedNumericSuperNonWritable() { | 2031 (function TestSetterKeyedNumericSuperNonWritable() { |
(...skipping 11 matching lines...) Expand all Loading... | |
1741 super[x] = 10; | 2043 super[x] = 10; |
1742 assertEquals(27, super[x]); | 2044 assertEquals(27, super[x]); |
1743 assertEquals(27, this[x]); | 2045 assertEquals(27, this[x]); |
1744 }, | 2046 }, |
1745 mStrict() { | 2047 mStrict() { |
1746 'use strict'; | 2048 'use strict'; |
1747 assertEquals(27, super[x]); | 2049 assertEquals(27, super[x]); |
1748 assertEquals(27, this[x]); | 2050 assertEquals(27, this[x]); |
1749 var ex = null; | 2051 var ex = null; |
1750 try { super[x] = 10; } catch(e) { ex = e; } | 2052 try { super[x] = 10; } catch(e) { ex = e; } |
1751 assertTrue(ex instanceof TypeError); | 2053 assertInstanceof(ex, TypeError); |
1752 assertEquals(27, super[x]); | 2054 assertEquals(27, super[x]); |
1753 assertEquals(27, this[x]); | 2055 assertEquals(27, this[x]); |
1754 } | 2056 } |
1755 }; | 2057 }; |
1756 new Derived().mSloppy(); | 2058 new Derived().mSloppy(); |
1757 new Derived().mStrict(); | 2059 new Derived().mStrict(); |
1758 }()); | 2060 }()); |
1759 | 2061 |
1760 | 2062 |
1761 (function TestSuperCall() { | 2063 (function TestSuperCall() { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1838 assertEquals(1, calls); | 2140 assertEquals(1, calls); |
1839 }()); | 2141 }()); |
1840 | 2142 |
1841 | 2143 |
1842 (function TestExtendsObject() { | 2144 (function TestExtendsObject() { |
1843 'use strict'; | 2145 'use strict'; |
1844 class F extends Object { } | 2146 class F extends Object { } |
1845 var f = new F(42); | 2147 var f = new F(42); |
1846 | 2148 |
1847 // TODO(dslomov,arv): Fix this. BUG=v8:3886. | 2149 // TODO(dslomov,arv): Fix this. BUG=v8:3886. |
1848 assertTrue(f instanceof Number); | 2150 assertInstanceof(f, Number); |
1849 }()); | 2151 }()); |
1850 | 2152 |
1851 (function TestSuperCallErrorCases() { | 2153 (function TestSuperCallErrorCases() { |
1852 'use strict'; | 2154 'use strict'; |
1853 class T extends Object { | 2155 class T extends Object { |
1854 constructor() { | 2156 constructor() { |
1855 super(); | 2157 super(); |
1856 } | 2158 } |
1857 } | 2159 } |
1858 | 2160 |
1859 T.__proto__ = null; | 2161 T.__proto__ = null; |
1860 assertThrows(function() { new T(); }, TypeError); | 2162 assertThrows(function() { new T(); }, TypeError); |
1861 }()); | 2163 }()); |
OLD | NEW |