OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 957 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
968 obj[symbol]++; | 968 obj[symbol]++; |
969 obj[symbol] *= 3; | 969 obj[symbol] *= 3; |
970 delete obj[symbol]; | 970 delete obj[symbol]; |
971 obj.__defineSetter__(symbol, function() {}); | 971 obj.__defineSetter__(symbol, function() {}); |
972 obj.__defineGetter__(symbol, function() {}); | 972 obj.__defineGetter__(symbol, function() {}); |
973 Object.deliverChangeRecords(observer.callback); | 973 Object.deliverChangeRecords(observer.callback); |
974 observer.assertNotCalled(); | 974 observer.assertNotCalled(); |
975 | 975 |
976 | 976 |
977 // Test all kinds of objects generically. | 977 // Test all kinds of objects generically. |
978 function TestObserveConfigurable(obj, prop) { | 978 function TestObserveConfigurable(obj, prop, is_writable) { |
979 reset(); | 979 reset(); |
| 980 var valueWhenDeleted = is_writable ? 3 : obj[prop]; |
980 Object.observe(obj, observer.callback); | 981 Object.observe(obj, observer.callback); |
981 Object.unobserve(obj, observer.callback); | 982 Object.unobserve(obj, observer.callback); |
982 obj[prop] = 1; | 983 obj[prop] = 1; |
983 Object.observe(obj, observer.callback); | 984 Object.observe(obj, observer.callback); |
984 obj[prop] = 2; | 985 obj[prop] = 2; |
985 obj[prop] = 3; | 986 obj[prop] = valueWhenDeleted; |
986 delete obj[prop]; | 987 delete obj[prop]; |
987 obj[prop] = 4; | 988 // If the deleted obj[prop] exposed another 'prop' along the |
| 989 // prototype chain, only update it if it doesn't have an |
| 990 // (inheritable) accessor or it is a read-only data property. If |
| 991 // either of those is true, then instead create an own property with |
| 992 // the descriptor that [[Put]] mandates for a new property (ES-5.1, |
| 993 // 8.12.5.6) |
| 994 var createOwnProperty = false; |
| 995 for (var o = Object.getPrototypeOf(obj); o; o = Object.getPrototypeOf(o)) { |
| 996 var desc = Object.getOwnPropertyDescriptor(o, prop); |
| 997 if (desc) { |
| 998 if (!desc.writable) |
| 999 createOwnProperty = true; |
| 1000 break; |
| 1001 } |
| 1002 } |
| 1003 if (createOwnProperty) |
| 1004 Object.defineProperty(obj, prop, { |
| 1005 value: 4, |
| 1006 writable: true, |
| 1007 enumerable: true, |
| 1008 configurable: true |
| 1009 }); |
| 1010 else |
| 1011 obj[prop] = 4; |
988 obj[prop] = 4; // ignored | 1012 obj[prop] = 4; // ignored |
989 obj[prop] = 5; | 1013 obj[prop] = 5; |
990 Object.defineProperty(obj, prop, {value: 6}); | 1014 Object.defineProperty(obj, prop, {value: 6}); |
991 Object.defineProperty(obj, prop, {writable: false}); | 1015 Object.defineProperty(obj, prop, {writable: false}); |
992 obj[prop] = 7; // ignored | 1016 obj[prop] = 7; // ignored |
993 Object.defineProperty(obj, prop, {value: 8}); | 1017 Object.defineProperty(obj, prop, {value: 8}); |
994 Object.defineProperty(obj, prop, {value: 7, writable: true}); | 1018 Object.defineProperty(obj, prop, {value: 7, writable: true}); |
995 Object.defineProperty(obj, prop, {get: function() {}}); | 1019 Object.defineProperty(obj, prop, {get: function() {}}); |
996 Object.defineProperty(obj, prop, {get: frozenFunction}); | 1020 Object.defineProperty(obj, prop, {get: frozenFunction}); |
997 Object.defineProperty(obj, prop, {get: frozenFunction}); // ignored | 1021 Object.defineProperty(obj, prop, {get: frozenFunction}); // ignored |
998 Object.defineProperty(obj, prop, {get: frozenFunction, set: frozenFunction}); | 1022 Object.defineProperty(obj, prop, {get: frozenFunction, set: frozenFunction}); |
999 Object.defineProperty(obj, prop, {set: frozenFunction}); // ignored | 1023 Object.defineProperty(obj, prop, {set: frozenFunction}); // ignored |
1000 Object.defineProperty(obj, prop, {get: undefined, set: frozenFunction}); | 1024 Object.defineProperty(obj, prop, {get: undefined, set: frozenFunction}); |
1001 obj.__defineSetter__(prop, frozenFunction); // ignored | 1025 obj.__defineSetter__(prop, frozenFunction); // ignored |
1002 obj.__defineSetter__(prop, function() {}); | 1026 obj.__defineSetter__(prop, function() {}); |
1003 obj.__defineGetter__(prop, function() {}); | 1027 obj.__defineGetter__(prop, function() {}); |
1004 delete obj[prop]; | 1028 delete obj[prop]; |
1005 delete obj[prop]; // ignored | 1029 delete obj[prop]; // ignored |
1006 obj.__defineGetter__(prop, function() {}); | 1030 obj.__defineGetter__(prop, function() {}); |
1007 delete obj[prop]; | 1031 delete obj[prop]; |
1008 Object.defineProperty(obj, prop, {get: function() {}, configurable: true}); | 1032 Object.defineProperty(obj, prop, {get: function() {}, configurable: true}); |
1009 Object.defineProperty(obj, prop, {value: 9, writable: true}); | 1033 Object.defineProperty(obj, prop, {value: 9, writable: true}); |
1010 obj[prop] = 10; | 1034 obj[prop] = 10; |
1011 ++obj[prop]; | 1035 ++obj[prop]; |
1012 obj[prop]++; | 1036 obj[prop]++; |
1013 obj[prop] *= 3; | 1037 obj[prop] *= 3; |
1014 delete obj[prop]; | 1038 delete obj[prop]; |
1015 Object.defineProperty(obj, prop, {value: 11, configurable: true}); | 1039 Object.defineProperty(obj, prop, {value: 11, configurable: true}); |
1016 Object.deliverChangeRecords(observer.callback); | 1040 Object.deliverChangeRecords(observer.callback); |
1017 observer.assertCallbackRecords([ | 1041 |
1018 { object: obj, name: prop, type: "update", oldValue: 1 }, | 1042 var expected = [ |
1019 { object: obj, name: prop, type: "update", oldValue: 2 }, | 1043 { object: obj, name: prop, type: "delete", oldValue: valueWhenDeleted }, |
1020 { object: obj, name: prop, type: "delete", oldValue: 3 }, | |
1021 { object: obj, name: prop, type: "add" }, | 1044 { object: obj, name: prop, type: "add" }, |
1022 { object: obj, name: prop, type: "update", oldValue: 4 }, | 1045 { object: obj, name: prop, type: "update", oldValue: 4 }, |
1023 { object: obj, name: prop, type: "update", oldValue: 5 }, | 1046 { object: obj, name: prop, type: "update", oldValue: 5 }, |
1024 { object: obj, name: prop, type: "reconfigure" }, | 1047 { object: obj, name: prop, type: "reconfigure" }, |
1025 { object: obj, name: prop, type: "update", oldValue: 6 }, | 1048 { object: obj, name: prop, type: "update", oldValue: 6 }, |
1026 { object: obj, name: prop, type: "reconfigure", oldValue: 8 }, | 1049 { object: obj, name: prop, type: "reconfigure", oldValue: 8 }, |
1027 { object: obj, name: prop, type: "reconfigure", oldValue: 7 }, | 1050 { object: obj, name: prop, type: "reconfigure", oldValue: 7 }, |
1028 { object: obj, name: prop, type: "reconfigure" }, | 1051 { object: obj, name: prop, type: "reconfigure" }, |
1029 { object: obj, name: prop, type: "reconfigure" }, | 1052 { object: obj, name: prop, type: "reconfigure" }, |
1030 { object: obj, name: prop, type: "reconfigure" }, | 1053 { object: obj, name: prop, type: "reconfigure" }, |
1031 { object: obj, name: prop, type: "reconfigure" }, | 1054 { object: obj, name: prop, type: "reconfigure" }, |
1032 { object: obj, name: prop, type: "reconfigure" }, | 1055 { object: obj, name: prop, type: "reconfigure" }, |
1033 { object: obj, name: prop, type: "delete" }, | 1056 { object: obj, name: prop, type: "delete" }, |
1034 { object: obj, name: prop, type: "add" }, | 1057 { object: obj, name: prop, type: "add" }, |
1035 { object: obj, name: prop, type: "delete" }, | 1058 { object: obj, name: prop, type: "delete" }, |
1036 { object: obj, name: prop, type: "add" }, | 1059 { object: obj, name: prop, type: "add" }, |
1037 { object: obj, name: prop, type: "reconfigure" }, | 1060 { object: obj, name: prop, type: "reconfigure" }, |
1038 { object: obj, name: prop, type: "update", oldValue: 9 }, | 1061 { object: obj, name: prop, type: "update", oldValue: 9 }, |
1039 { object: obj, name: prop, type: "update", oldValue: 10 }, | 1062 { object: obj, name: prop, type: "update", oldValue: 10 }, |
1040 { object: obj, name: prop, type: "update", oldValue: 11 }, | 1063 { object: obj, name: prop, type: "update", oldValue: 11 }, |
1041 { object: obj, name: prop, type: "update", oldValue: 12 }, | 1064 { object: obj, name: prop, type: "update", oldValue: 12 }, |
1042 { object: obj, name: prop, type: "delete", oldValue: 36 }, | 1065 { object: obj, name: prop, type: "delete", oldValue: 36 }, |
1043 { object: obj, name: prop, type: "add" }, | 1066 { object: obj, name: prop, type: "add" }, |
1044 ]); | 1067 ]; |
| 1068 |
| 1069 if (is_writable) { |
| 1070 expected.unshift( |
| 1071 { object: obj, name: prop, type: "update", oldValue: 1 }, |
| 1072 { object: obj, name: prop, type: "update", oldValue: 2 }); |
| 1073 } |
| 1074 |
| 1075 observer.assertCallbackRecords(expected); |
1045 Object.unobserve(obj, observer.callback); | 1076 Object.unobserve(obj, observer.callback); |
1046 delete obj[prop]; | 1077 delete obj[prop]; |
1047 } | 1078 } |
1048 | 1079 |
1049 function TestObserveNonConfigurable(obj, prop, desc) { | 1080 function TestObserveNonConfigurable(obj, prop, desc) { |
1050 reset(); | 1081 reset(); |
1051 Object.observe(obj, observer.callback); | 1082 Object.observe(obj, observer.callback); |
1052 Object.unobserve(obj, observer.callback); | 1083 Object.unobserve(obj, observer.callback); |
1053 obj[prop] = 1; | 1084 obj[prop] = 1; |
1054 Object.observe(obj, observer.callback); | 1085 Object.observe(obj, observer.callback); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1136 (obj instanceof ArrayBuffer && prop == 1) | 1167 (obj instanceof ArrayBuffer && prop == 1) |
1137 } | 1168 } |
1138 | 1169 |
1139 for (var i in objects) for (var j in properties) { | 1170 for (var i in objects) for (var j in properties) { |
1140 var obj = objects[i]; | 1171 var obj = objects[i]; |
1141 var prop = properties[j]; | 1172 var prop = properties[j]; |
1142 if (blacklisted(obj, prop)) continue; | 1173 if (blacklisted(obj, prop)) continue; |
1143 var desc = Object.getOwnPropertyDescriptor(obj, prop); | 1174 var desc = Object.getOwnPropertyDescriptor(obj, prop); |
1144 print("***", typeof obj, stringifyNoThrow(obj), prop); | 1175 print("***", typeof obj, stringifyNoThrow(obj), prop); |
1145 if (!desc || desc.configurable) | 1176 if (!desc || desc.configurable) |
1146 TestObserveConfigurable(obj, prop); | 1177 TestObserveConfigurable(obj, prop, !desc || desc.writable); |
1147 else if (desc.writable) | 1178 else if (desc.writable) |
1148 TestObserveNonConfigurable(obj, prop, desc); | 1179 TestObserveNonConfigurable(obj, prop, desc); |
1149 } | 1180 } |
1150 | 1181 |
1151 | 1182 |
1152 // Observing array length (including truncation) | 1183 // Observing array length (including truncation) |
1153 reset(); | 1184 reset(); |
1154 var arr = ['a', 'b', 'c', 'd']; | 1185 var arr = ['a', 'b', 'c', 'd']; |
1155 var arr2 = ['alpha', 'beta']; | 1186 var arr2 = ['alpha', 'beta']; |
1156 var arr3 = ['hello']; | 1187 var arr3 = ['hello']; |
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1779 for (var n1 = 0; n1 < 3; ++n1) | 1810 for (var n1 = 0; n1 < 3; ++n1) |
1780 for (var n2 = 0; n2 < 3; ++n2) | 1811 for (var n2 = 0; n2 < 3; ++n2) |
1781 for (var i in mutation) | 1812 for (var i in mutation) |
1782 TestFastElementsLength(mutation[i], b1 != 0, b2 != 0, 20*n1, 20*n2); | 1813 TestFastElementsLength(mutation[i], b1 != 0, b2 != 0, 20*n1, 20*n2); |
1783 | 1814 |
1784 for (var b1 = 0; b1 < 2; ++b1) | 1815 for (var b1 = 0; b1 < 2; ++b1) |
1785 for (var b2 = 0; b2 < 2; ++b2) | 1816 for (var b2 = 0; b2 < 2; ++b2) |
1786 for (var n = 0; n < 3; ++n) | 1817 for (var n = 0; n < 3; ++n) |
1787 for (var i in mutationByIncr) | 1818 for (var i in mutationByIncr) |
1788 TestFastElementsLength(mutationByIncr[i], b1 != 0, b2 != 0, 7*n, 7*n+1); | 1819 TestFastElementsLength(mutationByIncr[i], b1 != 0, b2 != 0, 7*n, 7*n+1); |
OLD | NEW |