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 = { |
971 __proto__: Base.prototype, | 970 __proto__: Base.prototype, |
972 mSloppy() { | 971 mSloppy() { |
973 assertEquals(42, this.ownReadOnly); | 972 assertEquals(42, this.ownReadOnly); |
974 super.ownReadOnly = 55; | 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 = { |
| 1073 __proto__: Base.prototype, |
| 1074 mSloppy() { |
| 1075 assertEquals(42, this.ownReadOnly); |
| 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 |
977 assertEquals(15, this.ownReadonlyAccessor); | 1085 assertEquals(15, this.ownReadonlyAccessor); |
978 super.ownReadonlyAccessor = 55; | 1086 super.ownReadonlyAccessor = 25; |
979 assertEquals(15, this.ownReadonlyAccessor); | 1087 assertEquals(15, this.ownReadonlyAccessor); |
| 1088 var descr = Object.getOwnPropertyDescriptor(this, 'ownReadonlyAccessor'); |
| 1089 assertFalse(descr.configurable); |
| 1090 assertFalse(descr.enumerable); |
| 1091 assertFalse(Base.prototype.hasOwnProperty('ownReadonlyAccessor')); |
980 | 1092 |
981 setterCalled = 0; | 1093 super.ownSetter = 35; |
982 super.ownSetter = 42; | 1094 var descr = Object.getOwnPropertyDescriptor(this, 'ownSetter'); |
983 assertEquals(1, setterCalled); | 1095 assertFalse(descr.configurable); |
| 1096 assertFalse(descr.enumerable); |
| 1097 assertFalse(Base.prototype.hasOwnProperty('ownSetter')); |
984 }, | 1098 }, |
985 mStrict() { | 1099 mStrict() { |
986 'use strict'; | 1100 'use strict'; |
| 1101 var ex; |
987 assertEquals(42, this.ownReadOnly); | 1102 assertEquals(42, this.ownReadOnly); |
988 var ex; | |
989 try { | 1103 try { |
990 super.ownReadOnly = 55; | 1104 super.ownReadOnly = 55; |
991 } catch(e) { ex = e; } | 1105 } catch (e) { |
992 assertTrue(ex instanceof TypeError); | 1106 ex = e; |
| 1107 } |
| 1108 assertInstanceof(ex, TypeError); |
| 1109 assertEquals( |
| 1110 "Cannot assign to read only property 'ownReadOnly' of #<Base>", |
| 1111 ex.message); |
993 assertEquals(42, this.ownReadOnly); | 1112 assertEquals(42, this.ownReadOnly); |
994 | 1113 |
| 1114 ex = null; |
995 assertEquals(15, this.ownReadonlyAccessor); | 1115 assertEquals(15, this.ownReadonlyAccessor); |
| 1116 try { |
| 1117 super.ownReadonlyAccessor = 25; |
| 1118 } catch (e) { |
| 1119 ex = e; |
| 1120 } |
| 1121 assertInstanceof(ex, TypeError); |
| 1122 assertEquals('Cannot redefine property: ownReadonlyAccessor', ex.message); |
| 1123 assertEquals(15, this.ownReadonlyAccessor); |
| 1124 |
996 ex = null; | 1125 ex = null; |
997 try { | 1126 try { |
998 super.ownReadonlyAccessor = 55; | 1127 super.ownSetter = 35; |
999 } catch(e) { ex = e; } | 1128 } catch (e) { |
1000 assertTrue(ex instanceof TypeError); | 1129 ex = e; |
1001 assertEquals(15, this.ownReadonlyAccessor); | 1130 } |
1002 | 1131 assertInstanceof(ex, TypeError); |
1003 setterCalled = 0; | 1132 assertEquals('Cannot redefine property: ownSetter', ex.message); |
1004 super.ownSetter = 42; | |
1005 assertEquals(1, setterCalled); | |
1006 } | 1133 } |
1007 }; | 1134 }; |
1008 | 1135 |
1009 var d = new Derived(); | 1136 var d = new Derived(); |
1010 Object.defineProperty(d, 'ownReadOnly', { value : 42, writable : false }); | 1137 Object.defineProperty(d, 'ownReadOnly', { value : 42, writable : false }); |
1011 Object.defineProperty(d, 'ownSetter', | 1138 Object.defineProperty(d, 'ownSetter', |
1012 { set : function() { setterCalled++; } }); | 1139 { set : function() { assertUnreachable(); } }); |
1013 Object.defineProperty(d, 'ownReadonlyAccessor', | 1140 Object.defineProperty(d, 'ownReadonlyAccessor', |
1014 { get : function() { return 15; }}); | 1141 { get : function() { return 15; }}); |
1015 d.mSloppy(); | 1142 d.mSloppy(); |
1016 d.mStrict(); | 1143 d.mStrict(); |
1017 }()); | 1144 }()); |
1018 | 1145 |
1019 | 1146 |
1020 (function TestSetterInForIn() { | 1147 (function TestSetterInForIn() { |
1021 var setCalled = 0; | 1148 var setCalled = 0; |
1022 var getCalled = 0; | 1149 var getCalled = 0; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1069 }; | 1196 }; |
1070 | 1197 |
1071 new Derived().testIter(); | 1198 new Derived().testIter(); |
1072 | 1199 |
1073 var x = 'x'; | 1200 var x = 'x'; |
1074 | 1201 |
1075 new Derived().testIterKeyed(); | 1202 new Derived().testIterKeyed(); |
1076 }()); | 1203 }()); |
1077 | 1204 |
1078 | 1205 |
1079 (function TestKeyedSetterCreatingOwnProperties() { | 1206 function TestKeyedSetterCreatingOwnPropertiesReconfigurable(ownReadOnly, |
1080 var ownReadOnly = 'ownReadOnly'; | 1207 ownReadonlyAccessor, ownSetter) { |
1081 var ownReadonlyAccessor = 'ownReadonlyAccessor'; | |
1082 var ownSetter = 'ownSetter'; | |
1083 var setterCalled; | |
1084 function Base() {} | 1208 function Base() {} |
1085 function Derived() {} | 1209 function Derived() {} |
1086 Derived.prototype = { | 1210 Derived.prototype = { |
1087 __proto__: Base.prototype, | 1211 __proto__: Base.prototype, |
1088 mSloppy() { | 1212 mSloppy() { |
1089 assertEquals(42, this[ownReadOnly]); | 1213 assertEquals(42, this[ownReadOnly]); |
1090 super[ownReadOnly] = 55; | 1214 super[ownReadOnly] = 55; |
1091 assertEquals(42, this[ownReadOnly]); | 1215 assertEquals(55, this[ownReadOnly]); |
| 1216 var descr = Object.getOwnPropertyDescriptor(this, ownReadOnly); |
| 1217 assertEquals(55, descr.value); |
| 1218 assertTrue(descr.configurable); |
| 1219 assertFalse(descr.enumerable); |
| 1220 assertFalse(descr.writable); |
| 1221 assertFalse(Base.prototype.hasOwnProperty(ownReadOnly)); |
1092 | 1222 |
1093 assertEquals(15, this[ownReadonlyAccessor]); | 1223 assertEquals(15, this[ownReadonlyAccessor]); |
1094 super[ownReadonlyAccessor] = 55; | 1224 super[ownReadonlyAccessor] = 25; |
1095 assertEquals(15, this[ownReadonlyAccessor]); | 1225 assertEquals(25, this[ownReadonlyAccessor]); |
| 1226 var descr = Object.getOwnPropertyDescriptor(this, ownReadonlyAccessor); |
| 1227 assertEquals(25, descr.value); |
| 1228 assertTrue(descr.configurable); |
| 1229 assertFalse(descr.enumerable); |
| 1230 assertTrue(descr.writable); |
| 1231 assertFalse(Base.prototype.hasOwnProperty(ownReadonlyAccessor)); |
1096 | 1232 |
1097 setterCalled = 0; | 1233 super[ownSetter] = 35; |
1098 super[ownSetter] = 42; | 1234 assertEquals(35, this[ownSetter]); |
1099 assertEquals(1, setterCalled); | 1235 var descr = Object.getOwnPropertyDescriptor(this, ownSetter); |
| 1236 assertEquals(35, descr.value); |
| 1237 assertTrue(descr.configurable); |
| 1238 assertFalse(descr.enumerable); |
| 1239 assertTrue(descr.writable); |
| 1240 assertFalse(Base.prototype.hasOwnProperty(ownSetter)); |
1100 }, | 1241 }, |
1101 mStrict() { | 1242 mStrict() { |
1102 'use strict'; | 1243 'use strict'; |
1103 assertEquals(42, this[ownReadOnly]); | 1244 assertEquals(42, this[ownReadOnly]); |
1104 var ex; | 1245 super[ownReadOnly] = 55; |
1105 try { | 1246 assertEquals(55, this[ownReadOnly]); |
1106 super[ownReadOnly] = 55; | 1247 var descr = Object.getOwnPropertyDescriptor(this, ownReadOnly); |
1107 } catch(e) { ex = e; } | 1248 assertEquals(55, descr.value); |
1108 assertTrue(ex instanceof TypeError); | 1249 assertTrue(descr.configurable); |
1109 assertEquals(42, this[ownReadOnly]); | 1250 assertFalse(descr.enumerable); |
| 1251 assertFalse(descr.writable); |
| 1252 assertFalse(Base.prototype.hasOwnProperty(ownReadOnly)); |
1110 | 1253 |
1111 assertEquals(15, this[ownReadonlyAccessor]); | 1254 assertEquals(15, this[ownReadonlyAccessor]); |
1112 ex = null; | 1255 super[ownReadonlyAccessor] = 25; |
1113 try { | 1256 assertEquals(25, this[ownReadonlyAccessor]); |
1114 super[ownReadonlyAccessor] = 55; | 1257 var descr = Object.getOwnPropertyDescriptor(this, ownReadonlyAccessor); |
1115 } catch(e) { ex = e; } | 1258 assertEquals(25, descr.value); |
1116 assertTrue(ex instanceof TypeError); | 1259 assertTrue(descr.configurable); |
1117 assertEquals(15, this[ownReadonlyAccessor]); | 1260 assertFalse(descr.enumerable); |
| 1261 assertTrue(descr.writable); |
| 1262 assertFalse(Base.prototype.hasOwnProperty(ownReadonlyAccessor)); |
1118 | 1263 |
1119 setterCalled = 0; | 1264 super[ownSetter] = 35; |
1120 super[ownSetter] = 42; | 1265 assertEquals(35, this[ownSetter]); |
1121 assertEquals(1, setterCalled); | 1266 var descr = Object.getOwnPropertyDescriptor(this, ownSetter); |
1122 } | 1267 assertEquals(35, descr.value); |
| 1268 assertTrue(descr.configurable); |
| 1269 assertFalse(descr.enumerable); |
| 1270 assertTrue(descr.writable); |
| 1271 assertFalse(Base.prototype.hasOwnProperty(ownSetter)); |
| 1272 }, |
1123 }; | 1273 }; |
1124 | 1274 |
1125 var d = new Derived(); | 1275 var d = new Derived(); |
1126 Object.defineProperty(d, 'ownReadOnly', { value : 42, writable : false }); | 1276 Object.defineProperty(d, ownReadOnly, { |
1127 Object.defineProperty(d, 'ownSetter', | 1277 value: 42, |
1128 { set : function() { setterCalled++; } }); | 1278 writable: false, |
1129 Object.defineProperty(d, 'ownReadonlyAccessor', | 1279 configurable: true |
1130 { get : function() { return 15; }}); | 1280 }); |
| 1281 Object.defineProperty(d, ownSetter, { |
| 1282 set: function() { assertUnreachable(); }, |
| 1283 configurable: true |
| 1284 }); |
| 1285 Object.defineProperty(d, ownReadonlyAccessor, { |
| 1286 get: function() { return 15; }, |
| 1287 configurable: true |
| 1288 }); |
| 1289 |
1131 d.mSloppy(); | 1290 d.mSloppy(); |
| 1291 |
| 1292 var d = new Derived(); |
| 1293 Object.defineProperty(d, ownReadOnly, { |
| 1294 value: 42, |
| 1295 writable: false, |
| 1296 configurable: true |
| 1297 }); |
| 1298 Object.defineProperty(d, ownSetter, { |
| 1299 set: function() { assertUnreachable(); }, |
| 1300 configurable: true |
| 1301 }); |
| 1302 Object.defineProperty(d, ownReadonlyAccessor, { |
| 1303 get: function() { return 15; }, |
| 1304 configurable: true |
| 1305 }); |
1132 d.mStrict(); | 1306 d.mStrict(); |
1133 }()); | 1307 } |
| 1308 TestKeyedSetterCreatingOwnPropertiesReconfigurable('ownReadOnly', |
| 1309 'ownReadonlyAccessor', |
| 1310 'ownSetter'); |
| 1311 TestKeyedSetterCreatingOwnPropertiesReconfigurable(42, 43, 44); |
1134 | 1312 |
1135 | 1313 |
1136 (function TestKeyedNumericSetterCreatingOwnProperties() { | 1314 function TestKeyedSetterCreatingOwnPropertiesNonConfigurable( |
1137 var ownReadOnly = 42; | 1315 ownReadOnly, ownReadonlyAccessor, ownSetter) { |
1138 var ownReadonlyAccessor = 43; | |
1139 var ownSetter = 44; | |
1140 var setterCalled; | |
1141 function Base() {} | 1316 function Base() {} |
1142 function Derived() {} | 1317 function Derived() {} |
1143 Derived.prototype = { | 1318 Derived.prototype = { |
1144 __proto__: Base.prototype, | 1319 __proto__: Base.prototype, |
1145 mSloppy() { | 1320 mSloppy() { |
1146 assertEquals(42, this[ownReadOnly]); | 1321 assertEquals(42, this[ownReadOnly]); |
1147 super[ownReadOnly] = 55; | 1322 super[ownReadOnly] = 55; |
1148 assertEquals(42, this[ownReadOnly]); | 1323 assertEquals(42, this[ownReadOnly]); |
| 1324 var descr = Object.getOwnPropertyDescriptor(this, ownReadOnly); |
| 1325 assertEquals(42, descr.value); |
| 1326 assertFalse(descr.configurable); |
| 1327 assertFalse(descr.enumerable); |
| 1328 assertFalse(descr.writable); |
| 1329 assertFalse(Base.prototype.hasOwnProperty(ownReadOnly)); |
1149 | 1330 |
1150 assertEquals(15, this[ownReadonlyAccessor]); | 1331 assertEquals(15, this[ownReadonlyAccessor]); |
1151 super[ownReadonlyAccessor] = 55; | 1332 super[ownReadonlyAccessor] = 25; |
1152 assertEquals(15, this[ownReadonlyAccessor]); | 1333 assertEquals(15, this[ownReadonlyAccessor]); |
| 1334 var descr = Object.getOwnPropertyDescriptor(this, ownReadonlyAccessor); |
| 1335 assertFalse(descr.configurable); |
| 1336 assertFalse(descr.enumerable); |
| 1337 assertFalse(Base.prototype.hasOwnProperty(ownReadonlyAccessor)); |
1153 | 1338 |
1154 setterCalled = 0; | 1339 super[ownSetter] = 35; |
1155 super[ownSetter] = 42; | 1340 var descr = Object.getOwnPropertyDescriptor(this, ownSetter); |
1156 assertEquals(1, setterCalled); | 1341 assertFalse(descr.configurable); |
| 1342 assertFalse(descr.enumerable); |
| 1343 assertFalse(Base.prototype.hasOwnProperty(ownSetter)); |
1157 }, | 1344 }, |
1158 mStrict() { | 1345 mStrict() { |
1159 'use strict'; | 1346 'use strict'; |
| 1347 var ex; |
1160 assertEquals(42, this[ownReadOnly]); | 1348 assertEquals(42, this[ownReadOnly]); |
1161 var ex; | |
1162 try { | 1349 try { |
1163 super[ownReadOnly] = 55; | 1350 super[ownReadOnly] = 55; |
1164 } catch(e) { ex = e; } | 1351 } catch (e) { |
1165 assertTrue(ex instanceof TypeError); | 1352 ex = e; |
| 1353 } |
| 1354 assertInstanceof(ex, TypeError); |
| 1355 assertEquals( |
| 1356 "Cannot assign to read only property '" + ownReadOnly + |
| 1357 "' of #<Base>", |
| 1358 ex.message); |
1166 assertEquals(42, this[ownReadOnly]); | 1359 assertEquals(42, this[ownReadOnly]); |
1167 | 1360 |
| 1361 ex = null; |
1168 assertEquals(15, this[ownReadonlyAccessor]); | 1362 assertEquals(15, this[ownReadonlyAccessor]); |
| 1363 try { |
| 1364 super[ownReadonlyAccessor] = 25; |
| 1365 } catch (e) { |
| 1366 ex = e; |
| 1367 } |
| 1368 assertInstanceof(ex, TypeError); |
| 1369 assertEquals('Cannot redefine property: ' + ownReadonlyAccessor, |
| 1370 ex.message); |
| 1371 assertEquals(15, this[ownReadonlyAccessor]); |
| 1372 |
1169 ex = null; | 1373 ex = null; |
1170 try { | 1374 try { |
1171 super[ownReadonlyAccessor] = 55; | 1375 super[ownSetter] = 35; |
1172 } catch(e) { ex = e; } | 1376 } catch (e) { |
1173 assertTrue(ex instanceof TypeError); | 1377 ex = e; |
1174 assertEquals(15, this[ownReadonlyAccessor]); | 1378 } |
1175 | 1379 assertInstanceof(ex, TypeError); |
1176 setterCalled = 0; | 1380 assertEquals('Cannot redefine property: ' + ownSetter, ex.message); |
1177 super[ownSetter] = 42; | |
1178 assertEquals(1, setterCalled); | |
1179 } | 1381 } |
1180 } | 1382 }; |
1181 | 1383 |
1182 var d = new Derived(); | 1384 var d = new Derived(); |
1183 Object.defineProperty(d, ownReadOnly, { value : 42, writable : false }); | 1385 Object.defineProperty(d, ownReadOnly, { value : 42, writable : false }); |
1184 Object.defineProperty(d, ownSetter, | 1386 Object.defineProperty(d, ownSetter, |
1185 { set : function() { setterCalled++; } }); | 1387 { set : function() { assertUnreachable(); } }); |
1186 Object.defineProperty(d, ownReadonlyAccessor, | 1388 Object.defineProperty(d, ownReadonlyAccessor, |
1187 { get : function() { return 15; }}); | 1389 { get : function() { return 15; }}); |
1188 d.mSloppy(); | 1390 d.mSloppy(); |
1189 d.mStrict(); | 1391 d.mStrict(); |
1190 }()); | 1392 } |
| 1393 TestKeyedSetterCreatingOwnPropertiesNonConfigurable('ownReadOnly', |
| 1394 'ownReadonlyAccessor', 'ownSetter'); |
| 1395 TestKeyedSetterCreatingOwnPropertiesNonConfigurable(42, 43, 44); |
1191 | 1396 |
1192 | 1397 |
1193 (function TestSetterNoProtoWalk() { | 1398 (function TestSetterNoProtoWalk() { |
1194 function Base() {} | 1399 function Base() {} |
1195 function Derived() {} | 1400 function Derived() {} |
1196 var getCalled; | 1401 var getCalled; |
1197 var setCalled; | 1402 var setCalled; |
1198 Derived.prototype = { | 1403 Derived.prototype = { |
1199 __proto__: Base.prototype, | 1404 __proto__: Base.prototype, |
1200 get x() { getCalled++; return 42; }, | 1405 get x() { getCalled++; return 42; }, |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1677 super.x = 10; | 1882 super.x = 10; |
1678 assertEquals(27, super.x); | 1883 assertEquals(27, super.x); |
1679 assertEquals(27, this.x); | 1884 assertEquals(27, this.x); |
1680 }, | 1885 }, |
1681 mStrict() { | 1886 mStrict() { |
1682 'use strict'; | 1887 'use strict'; |
1683 assertEquals(27, super.x); | 1888 assertEquals(27, super.x); |
1684 assertEquals(27, this.x); | 1889 assertEquals(27, this.x); |
1685 var ex = null; | 1890 var ex = null; |
1686 try { super.x = 10; } catch(e) { ex = e; } | 1891 try { super.x = 10; } catch(e) { ex = e; } |
1687 assertTrue(ex instanceof TypeError); | 1892 assertInstanceof(ex, TypeError); |
1688 assertEquals(27, super.x); | 1893 assertEquals(27, super.x); |
1689 assertEquals(27, this.x); | 1894 assertEquals(27, this.x); |
1690 } | 1895 } |
1691 }; | 1896 }; |
1692 new Derived().mSloppy(); | 1897 new Derived().mSloppy(); |
1693 new Derived().mStrict(); | 1898 new Derived().mStrict(); |
1694 }()); | 1899 }()); |
1695 | 1900 |
1696 | 1901 |
1697 (function TestSetterKeyedSuperNonWritable() { | 1902 (function TestSetterKeyedSuperNonWritable() { |
(...skipping 11 matching lines...) Expand all Loading... |
1709 super[x] = 10; | 1914 super[x] = 10; |
1710 assertEquals(27, super[x]); | 1915 assertEquals(27, super[x]); |
1711 assertEquals(27, this[x]); | 1916 assertEquals(27, this[x]); |
1712 }, | 1917 }, |
1713 mStrict() { | 1918 mStrict() { |
1714 'use strict'; | 1919 'use strict'; |
1715 assertEquals(27, super[x]); | 1920 assertEquals(27, super[x]); |
1716 assertEquals(27, this[x]); | 1921 assertEquals(27, this[x]); |
1717 var ex = null; | 1922 var ex = null; |
1718 try { super[x] = 10; } catch(e) { ex = e; } | 1923 try { super[x] = 10; } catch(e) { ex = e; } |
1719 assertTrue(ex instanceof TypeError); | 1924 assertInstanceof(ex, TypeError); |
1720 assertEquals(27, super[x]); | 1925 assertEquals(27, super[x]); |
1721 assertEquals(27, this[x]); | 1926 assertEquals(27, this[x]); |
1722 } | 1927 } |
1723 }; | 1928 }; |
1724 new Derived().mSloppy(); | 1929 new Derived().mSloppy(); |
1725 new Derived().mStrict(); | 1930 new Derived().mStrict(); |
1726 }()); | 1931 }()); |
1727 | 1932 |
1728 | 1933 |
1729 (function TestSetterKeyedNumericSuperNonWritable() { | 1934 (function TestSetterKeyedNumericSuperNonWritable() { |
(...skipping 11 matching lines...) Expand all Loading... |
1741 super[x] = 10; | 1946 super[x] = 10; |
1742 assertEquals(27, super[x]); | 1947 assertEquals(27, super[x]); |
1743 assertEquals(27, this[x]); | 1948 assertEquals(27, this[x]); |
1744 }, | 1949 }, |
1745 mStrict() { | 1950 mStrict() { |
1746 'use strict'; | 1951 'use strict'; |
1747 assertEquals(27, super[x]); | 1952 assertEquals(27, super[x]); |
1748 assertEquals(27, this[x]); | 1953 assertEquals(27, this[x]); |
1749 var ex = null; | 1954 var ex = null; |
1750 try { super[x] = 10; } catch(e) { ex = e; } | 1955 try { super[x] = 10; } catch(e) { ex = e; } |
1751 assertTrue(ex instanceof TypeError); | 1956 assertInstanceof(ex, TypeError); |
1752 assertEquals(27, super[x]); | 1957 assertEquals(27, super[x]); |
1753 assertEquals(27, this[x]); | 1958 assertEquals(27, this[x]); |
1754 } | 1959 } |
1755 }; | 1960 }; |
1756 new Derived().mSloppy(); | 1961 new Derived().mSloppy(); |
1757 new Derived().mStrict(); | 1962 new Derived().mStrict(); |
1758 }()); | 1963 }()); |
1759 | 1964 |
1760 | 1965 |
1761 (function TestSuperCall() { | 1966 (function TestSuperCall() { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1838 assertEquals(1, calls); | 2043 assertEquals(1, calls); |
1839 }()); | 2044 }()); |
1840 | 2045 |
1841 | 2046 |
1842 (function TestExtendsObject() { | 2047 (function TestExtendsObject() { |
1843 'use strict'; | 2048 'use strict'; |
1844 class F extends Object { } | 2049 class F extends Object { } |
1845 var f = new F(42); | 2050 var f = new F(42); |
1846 | 2051 |
1847 // TODO(dslomov,arv): Fix this. BUG=v8:3886. | 2052 // TODO(dslomov,arv): Fix this. BUG=v8:3886. |
1848 assertTrue(f instanceof Number); | 2053 assertInstanceof(f, Number); |
1849 }()); | 2054 }()); |
1850 | 2055 |
1851 (function TestSuperCallErrorCases() { | 2056 (function TestSuperCallErrorCases() { |
1852 'use strict'; | 2057 'use strict'; |
1853 class T extends Object { | 2058 class T extends Object { |
1854 constructor() { | 2059 constructor() { |
1855 super(); | 2060 super(); |
1856 } | 2061 } |
1857 } | 2062 } |
1858 | 2063 |
1859 T.__proto__ = null; | 2064 T.__proto__ = null; |
1860 assertThrows(function() { new T(); }, TypeError); | 2065 assertThrows(function() { new T(); }, TypeError); |
1861 }()); | 2066 }()); |
OLD | NEW |