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 |
989 // the prototype chain, do not update it, but create an | |
990 // own property with the descriptor that [[Put]] mandates | |
991 // for a new property (ES-5.1, 8.12.5.6) | |
992 // | |
993 // (Q: do this unconditionally?) | |
994 if (Object.getPrototypeOf(obj) && (prop in Object.getPrototypeOf(obj))) | |
rossberg
2014/01/09 12:26:39
Only do this fall-back when really necessary, i.e.
sof
2014/01/09 14:04:51
Done, I think (but it feels counterintuitive to "r
| |
995 Object.defineProperty(obj, prop, {value: 4, writable: true, enumerable: true , configurable: true}); | |
rossberg
2014/01/09 12:26:39
Nit: line length
| |
996 else | |
997 obj[prop] = 4; | |
988 obj[prop] = 4; // ignored | 998 obj[prop] = 4; // ignored |
989 obj[prop] = 5; | 999 obj[prop] = 5; |
990 Object.defineProperty(obj, prop, {value: 6}); | 1000 Object.defineProperty(obj, prop, {value: 6}); |
991 Object.defineProperty(obj, prop, {writable: false}); | 1001 Object.defineProperty(obj, prop, {writable: false}); |
992 obj[prop] = 7; // ignored | 1002 obj[prop] = 7; // ignored |
993 Object.defineProperty(obj, prop, {value: 8}); | 1003 Object.defineProperty(obj, prop, {value: 8}); |
994 Object.defineProperty(obj, prop, {value: 7, writable: true}); | 1004 Object.defineProperty(obj, prop, {value: 7, writable: true}); |
995 Object.defineProperty(obj, prop, {get: function() {}}); | 1005 Object.defineProperty(obj, prop, {get: function() {}}); |
996 Object.defineProperty(obj, prop, {get: frozenFunction}); | 1006 Object.defineProperty(obj, prop, {get: frozenFunction}); |
997 Object.defineProperty(obj, prop, {get: frozenFunction}); // ignored | 1007 Object.defineProperty(obj, prop, {get: frozenFunction}); // ignored |
998 Object.defineProperty(obj, prop, {get: frozenFunction, set: frozenFunction}); | 1008 Object.defineProperty(obj, prop, {get: frozenFunction, set: frozenFunction}); |
999 Object.defineProperty(obj, prop, {set: frozenFunction}); // ignored | 1009 Object.defineProperty(obj, prop, {set: frozenFunction}); // ignored |
1000 Object.defineProperty(obj, prop, {get: undefined, set: frozenFunction}); | 1010 Object.defineProperty(obj, prop, {get: undefined, set: frozenFunction}); |
1001 obj.__defineSetter__(prop, frozenFunction); // ignored | 1011 obj.__defineSetter__(prop, frozenFunction); // ignored |
1002 obj.__defineSetter__(prop, function() {}); | 1012 obj.__defineSetter__(prop, function() {}); |
1003 obj.__defineGetter__(prop, function() {}); | 1013 obj.__defineGetter__(prop, function() {}); |
1004 delete obj[prop]; | 1014 delete obj[prop]; |
1005 delete obj[prop]; // ignored | 1015 delete obj[prop]; // ignored |
1006 obj.__defineGetter__(prop, function() {}); | 1016 obj.__defineGetter__(prop, function() {}); |
1007 delete obj[prop]; | 1017 delete obj[prop]; |
1008 Object.defineProperty(obj, prop, {get: function() {}, configurable: true}); | 1018 Object.defineProperty(obj, prop, {get: function() {}, configurable: true}); |
1009 Object.defineProperty(obj, prop, {value: 9, writable: true}); | 1019 Object.defineProperty(obj, prop, {value: 9, writable: true}); |
1010 obj[prop] = 10; | 1020 obj[prop] = 10; |
1011 ++obj[prop]; | 1021 ++obj[prop]; |
1012 obj[prop]++; | 1022 obj[prop]++; |
1013 obj[prop] *= 3; | 1023 obj[prop] *= 3; |
1014 delete obj[prop]; | 1024 delete obj[prop]; |
1015 Object.defineProperty(obj, prop, {value: 11, configurable: true}); | 1025 Object.defineProperty(obj, prop, {value: 11, configurable: true}); |
1016 Object.deliverChangeRecords(observer.callback); | 1026 Object.deliverChangeRecords(observer.callback); |
1017 observer.assertCallbackRecords([ | 1027 |
1018 { object: obj, name: prop, type: "update", oldValue: 1 }, | 1028 var expected = [ |
1019 { object: obj, name: prop, type: "update", oldValue: 2 }, | 1029 { object: obj, name: prop, type: "delete", oldValue: valueWhenDeleted }, |
1020 { object: obj, name: prop, type: "delete", oldValue: 3 }, | 1030 { object: obj, name: prop, type: "add" }, |
1021 { object: obj, name: prop, type: "add" }, | 1031 { object: obj, name: prop, type: "update", oldValue: 4 }, |
1022 { object: obj, name: prop, type: "update", oldValue: 4 }, | 1032 { object: obj, name: prop, type: "update", oldValue: 5 }, |
1023 { object: obj, name: prop, type: "update", oldValue: 5 }, | 1033 { object: obj, name: prop, type: "reconfigure" }, |
1024 { object: obj, name: prop, type: "reconfigure" }, | 1034 { object: obj, name: prop, type: "update", oldValue: 6 }, |
1025 { object: obj, name: prop, type: "update", oldValue: 6 }, | 1035 { object: obj, name: prop, type: "reconfigure", oldValue: 8 }, |
1026 { object: obj, name: prop, type: "reconfigure", oldValue: 8 }, | 1036 { object: obj, name: prop, type: "reconfigure", oldValue: 7 }, |
1027 { object: obj, name: prop, type: "reconfigure", oldValue: 7 }, | 1037 { object: obj, name: prop, type: "reconfigure" }, |
1028 { object: obj, name: prop, type: "reconfigure" }, | 1038 { object: obj, name: prop, type: "reconfigure" }, |
1029 { object: obj, name: prop, type: "reconfigure" }, | 1039 { object: obj, name: prop, type: "reconfigure" }, |
1030 { object: obj, name: prop, type: "reconfigure" }, | 1040 { object: obj, name: prop, type: "reconfigure" }, |
1031 { object: obj, name: prop, type: "reconfigure" }, | 1041 { object: obj, name: prop, type: "reconfigure" }, |
1032 { object: obj, name: prop, type: "reconfigure" }, | 1042 { object: obj, name: prop, type: "delete" }, |
1033 { object: obj, name: prop, type: "delete" }, | 1043 { object: obj, name: prop, type: "add" }, |
1034 { object: obj, name: prop, type: "add" }, | 1044 { object: obj, name: prop, type: "delete" }, |
1035 { object: obj, name: prop, type: "delete" }, | 1045 { object: obj, name: prop, type: "add" }, |
1036 { object: obj, name: prop, type: "add" }, | 1046 { object: obj, name: prop, type: "reconfigure" }, |
1037 { object: obj, name: prop, type: "reconfigure" }, | 1047 { object: obj, name: prop, type: "update", oldValue: 9 }, |
1038 { object: obj, name: prop, type: "update", oldValue: 9 }, | 1048 { object: obj, name: prop, type: "update", oldValue: 10 }, |
1039 { object: obj, name: prop, type: "update", oldValue: 10 }, | 1049 { object: obj, name: prop, type: "update", oldValue: 11 }, |
1040 { object: obj, name: prop, type: "update", oldValue: 11 }, | 1050 { object: obj, name: prop, type: "update", oldValue: 12 }, |
1041 { object: obj, name: prop, type: "update", oldValue: 12 }, | 1051 { object: obj, name: prop, type: "delete", oldValue: 36 }, |
1042 { object: obj, name: prop, type: "delete", oldValue: 36 }, | 1052 { object: obj, name: prop, type: "add" }, |
1043 { object: obj, name: prop, type: "add" }, | 1053 ]; |
1044 ]); | 1054 |
1055 if (is_writable) { | |
1056 expected.unshift({ object: obj, name: prop, type: "update", oldValue: 1 }, | |
1057 { object: obj, name: prop, type: "update", oldValue: 2 }) ; | |
1058 } | |
1059 | |
1060 observer.assertCallbackRecords(expected); | |
1045 Object.unobserve(obj, observer.callback); | 1061 Object.unobserve(obj, observer.callback); |
1046 delete obj[prop]; | 1062 delete obj[prop]; |
1047 } | 1063 } |
1048 | 1064 |
1049 function TestObserveNonConfigurable(obj, prop, desc) { | 1065 function TestObserveNonConfigurable(obj, prop, desc) { |
1050 reset(); | 1066 reset(); |
1051 Object.observe(obj, observer.callback); | 1067 Object.observe(obj, observer.callback); |
1052 Object.unobserve(obj, observer.callback); | 1068 Object.unobserve(obj, observer.callback); |
1053 obj[prop] = 1; | 1069 obj[prop] = 1; |
1054 Object.observe(obj, observer.callback); | 1070 Object.observe(obj, observer.callback); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1136 (obj instanceof ArrayBuffer && prop == 1) | 1152 (obj instanceof ArrayBuffer && prop == 1) |
1137 } | 1153 } |
1138 | 1154 |
1139 for (var i in objects) for (var j in properties) { | 1155 for (var i in objects) for (var j in properties) { |
1140 var obj = objects[i]; | 1156 var obj = objects[i]; |
1141 var prop = properties[j]; | 1157 var prop = properties[j]; |
1142 if (blacklisted(obj, prop)) continue; | 1158 if (blacklisted(obj, prop)) continue; |
1143 var desc = Object.getOwnPropertyDescriptor(obj, prop); | 1159 var desc = Object.getOwnPropertyDescriptor(obj, prop); |
1144 print("***", typeof obj, stringifyNoThrow(obj), prop); | 1160 print("***", typeof obj, stringifyNoThrow(obj), prop); |
1145 if (!desc || desc.configurable) | 1161 if (!desc || desc.configurable) |
1146 TestObserveConfigurable(obj, prop); | 1162 TestObserveConfigurable(obj, prop, !desc || desc.writable); |
1147 else if (desc.writable) | 1163 else if (desc.writable) |
1148 TestObserveNonConfigurable(obj, prop, desc); | 1164 TestObserveNonConfigurable(obj, prop, desc); |
1149 } | 1165 } |
1150 | 1166 |
1151 | 1167 |
1152 // Observing array length (including truncation) | 1168 // Observing array length (including truncation) |
1153 reset(); | 1169 reset(); |
1154 var arr = ['a', 'b', 'c', 'd']; | 1170 var arr = ['a', 'b', 'c', 'd']; |
1155 var arr2 = ['alpha', 'beta']; | 1171 var arr2 = ['alpha', 'beta']; |
1156 var arr3 = ['hello']; | 1172 var arr3 = ['hello']; |
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1779 for (var n1 = 0; n1 < 3; ++n1) | 1795 for (var n1 = 0; n1 < 3; ++n1) |
1780 for (var n2 = 0; n2 < 3; ++n2) | 1796 for (var n2 = 0; n2 < 3; ++n2) |
1781 for (var i in mutation) | 1797 for (var i in mutation) |
1782 TestFastElementsLength(mutation[i], b1 != 0, b2 != 0, 20*n1, 20*n2); | 1798 TestFastElementsLength(mutation[i], b1 != 0, b2 != 0, 20*n1, 20*n2); |
1783 | 1799 |
1784 for (var b1 = 0; b1 < 2; ++b1) | 1800 for (var b1 = 0; b1 < 2; ++b1) |
1785 for (var b2 = 0; b2 < 2; ++b2) | 1801 for (var b2 = 0; b2 < 2; ++b2) |
1786 for (var n = 0; n < 3; ++n) | 1802 for (var n = 0; n < 3; ++n) |
1787 for (var i in mutationByIncr) | 1803 for (var i in mutationByIncr) |
1788 TestFastElementsLength(mutationByIncr[i], b1 != 0, b2 != 0, 7*n, 7*n+1); | 1804 TestFastElementsLength(mutationByIncr[i], b1 != 0, b2 != 0, 7*n, 7*n+1); |
OLD | NEW |