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

Side by Side Diff: test/mjsunit/harmony/object-observe.js

Issue 116083006: Make Function.length and Function.name configurable properties. (Closed) Base URL: git://github.com/v8/v8.git@bleeding_edge
Patch Set: Improve test changes somewhat Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/cctest/test-accessors.cc ('k') | test/mjsunit/regress/regress-1530.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 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
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 has compatible attributes.
rossberg 2014/01/09 14:59:35 This comment seems misleading. You never update th
990 // If not, create an own property with the descriptor that [[Put]]
991 // mandates for a new property (ES-5.1, 8.12.5.6)
992 var createOwnProperty = false;
993 for (var o = Object.getPrototypeOf(obj); o; o = Object.getPrototypeOf(o)) {
994 var desc = Object.getOwnPropertyDescriptor(o, prop);
995 if (desc) {
996 // Have to be able to re-configure and update the property.
997 if (!desc.configurable || !desc.writable || desc.set)
rossberg 2014/01/09 14:59:35 I think this should be more like if (!desc.writ
998 createOwnProperty = true;
999 break;
1000 }
1001 }
1002 if (createOwnProperty)
1003 Object.defineProperty(obj, prop, {
1004 value: 4,
1005 writable: true,
1006 enumerable: true,
1007 configurable: true
1008 });
1009 else
1010 obj[prop] = 4;
988 obj[prop] = 4; // ignored 1011 obj[prop] = 4; // ignored
989 obj[prop] = 5; 1012 obj[prop] = 5;
990 Object.defineProperty(obj, prop, {value: 6}); 1013 Object.defineProperty(obj, prop, {value: 6});
991 Object.defineProperty(obj, prop, {writable: false}); 1014 Object.defineProperty(obj, prop, {writable: false});
992 obj[prop] = 7; // ignored 1015 obj[prop] = 7; // ignored
993 Object.defineProperty(obj, prop, {value: 8}); 1016 Object.defineProperty(obj, prop, {value: 8});
994 Object.defineProperty(obj, prop, {value: 7, writable: true}); 1017 Object.defineProperty(obj, prop, {value: 7, writable: true});
995 Object.defineProperty(obj, prop, {get: function() {}}); 1018 Object.defineProperty(obj, prop, {get: function() {}});
996 Object.defineProperty(obj, prop, {get: frozenFunction}); 1019 Object.defineProperty(obj, prop, {get: frozenFunction});
997 Object.defineProperty(obj, prop, {get: frozenFunction}); // ignored 1020 Object.defineProperty(obj, prop, {get: frozenFunction}); // ignored
998 Object.defineProperty(obj, prop, {get: frozenFunction, set: frozenFunction}); 1021 Object.defineProperty(obj, prop, {get: frozenFunction, set: frozenFunction});
999 Object.defineProperty(obj, prop, {set: frozenFunction}); // ignored 1022 Object.defineProperty(obj, prop, {set: frozenFunction}); // ignored
1000 Object.defineProperty(obj, prop, {get: undefined, set: frozenFunction}); 1023 Object.defineProperty(obj, prop, {get: undefined, set: frozenFunction});
1001 obj.__defineSetter__(prop, frozenFunction); // ignored 1024 obj.__defineSetter__(prop, frozenFunction); // ignored
1002 obj.__defineSetter__(prop, function() {}); 1025 obj.__defineSetter__(prop, function() {});
1003 obj.__defineGetter__(prop, function() {}); 1026 obj.__defineGetter__(prop, function() {});
1004 delete obj[prop]; 1027 delete obj[prop];
1005 delete obj[prop]; // ignored 1028 delete obj[prop]; // ignored
1006 obj.__defineGetter__(prop, function() {}); 1029 obj.__defineGetter__(prop, function() {});
1007 delete obj[prop]; 1030 delete obj[prop];
1008 Object.defineProperty(obj, prop, {get: function() {}, configurable: true}); 1031 Object.defineProperty(obj, prop, {get: function() {}, configurable: true});
1009 Object.defineProperty(obj, prop, {value: 9, writable: true}); 1032 Object.defineProperty(obj, prop, {value: 9, writable: true});
1010 obj[prop] = 10; 1033 obj[prop] = 10;
1011 ++obj[prop]; 1034 ++obj[prop];
1012 obj[prop]++; 1035 obj[prop]++;
1013 obj[prop] *= 3; 1036 obj[prop] *= 3;
1014 delete obj[prop]; 1037 delete obj[prop];
1015 Object.defineProperty(obj, prop, {value: 11, configurable: true}); 1038 Object.defineProperty(obj, prop, {value: 11, configurable: true});
1016 Object.deliverChangeRecords(observer.callback); 1039 Object.deliverChangeRecords(observer.callback);
1017 observer.assertCallbackRecords([ 1040
1018 { object: obj, name: prop, type: "update", oldValue: 1 }, 1041 var expected = [
1019 { object: obj, name: prop, type: "update", oldValue: 2 }, 1042 { object: obj, name: prop, type: "delete", oldValue: valueWhenDeleted },
1020 { object: obj, name: prop, type: "delete", oldValue: 3 },
1021 { object: obj, name: prop, type: "add" }, 1043 { object: obj, name: prop, type: "add" },
1022 { object: obj, name: prop, type: "update", oldValue: 4 }, 1044 { object: obj, name: prop, type: "update", oldValue: 4 },
1023 { object: obj, name: prop, type: "update", oldValue: 5 }, 1045 { object: obj, name: prop, type: "update", oldValue: 5 },
1024 { object: obj, name: prop, type: "reconfigure" }, 1046 { object: obj, name: prop, type: "reconfigure" },
1025 { object: obj, name: prop, type: "update", oldValue: 6 }, 1047 { object: obj, name: prop, type: "update", oldValue: 6 },
1026 { object: obj, name: prop, type: "reconfigure", oldValue: 8 }, 1048 { object: obj, name: prop, type: "reconfigure", oldValue: 8 },
1027 { object: obj, name: prop, type: "reconfigure", oldValue: 7 }, 1049 { object: obj, name: prop, type: "reconfigure", oldValue: 7 },
1028 { object: obj, name: prop, type: "reconfigure" }, 1050 { object: obj, name: prop, type: "reconfigure" },
1029 { object: obj, name: prop, type: "reconfigure" }, 1051 { object: obj, name: prop, type: "reconfigure" },
1030 { object: obj, name: prop, type: "reconfigure" }, 1052 { object: obj, name: prop, type: "reconfigure" },
1031 { object: obj, name: prop, type: "reconfigure" }, 1053 { object: obj, name: prop, type: "reconfigure" },
1032 { object: obj, name: prop, type: "reconfigure" }, 1054 { object: obj, name: prop, type: "reconfigure" },
1033 { object: obj, name: prop, type: "delete" }, 1055 { object: obj, name: prop, type: "delete" },
1034 { object: obj, name: prop, type: "add" }, 1056 { object: obj, name: prop, type: "add" },
1035 { object: obj, name: prop, type: "delete" }, 1057 { object: obj, name: prop, type: "delete" },
1036 { object: obj, name: prop, type: "add" }, 1058 { object: obj, name: prop, type: "add" },
1037 { object: obj, name: prop, type: "reconfigure" }, 1059 { object: obj, name: prop, type: "reconfigure" },
1038 { object: obj, name: prop, type: "update", oldValue: 9 }, 1060 { object: obj, name: prop, type: "update", oldValue: 9 },
1039 { object: obj, name: prop, type: "update", oldValue: 10 }, 1061 { object: obj, name: prop, type: "update", oldValue: 10 },
1040 { object: obj, name: prop, type: "update", oldValue: 11 }, 1062 { object: obj, name: prop, type: "update", oldValue: 11 },
1041 { object: obj, name: prop, type: "update", oldValue: 12 }, 1063 { object: obj, name: prop, type: "update", oldValue: 12 },
1042 { object: obj, name: prop, type: "delete", oldValue: 36 }, 1064 { object: obj, name: prop, type: "delete", oldValue: 36 },
1043 { object: obj, name: prop, type: "add" }, 1065 { object: obj, name: prop, type: "add" },
1044 ]); 1066 ];
1067
1068 if (is_writable) {
1069 expected.unshift(
1070 { object: obj, name: prop, type: "update", oldValue: 1 },
1071 { object: obj, name: prop, type: "update", oldValue: 2 });
1072 }
1073
1074 observer.assertCallbackRecords(expected);
1045 Object.unobserve(obj, observer.callback); 1075 Object.unobserve(obj, observer.callback);
1046 delete obj[prop]; 1076 delete obj[prop];
1047 } 1077 }
1048 1078
1049 function TestObserveNonConfigurable(obj, prop, desc) { 1079 function TestObserveNonConfigurable(obj, prop, desc) {
1050 reset(); 1080 reset();
1051 Object.observe(obj, observer.callback); 1081 Object.observe(obj, observer.callback);
1052 Object.unobserve(obj, observer.callback); 1082 Object.unobserve(obj, observer.callback);
1053 obj[prop] = 1; 1083 obj[prop] = 1;
1054 Object.observe(obj, observer.callback); 1084 Object.observe(obj, observer.callback);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1136 (obj instanceof ArrayBuffer && prop == 1) 1166 (obj instanceof ArrayBuffer && prop == 1)
1137 } 1167 }
1138 1168
1139 for (var i in objects) for (var j in properties) { 1169 for (var i in objects) for (var j in properties) {
1140 var obj = objects[i]; 1170 var obj = objects[i];
1141 var prop = properties[j]; 1171 var prop = properties[j];
1142 if (blacklisted(obj, prop)) continue; 1172 if (blacklisted(obj, prop)) continue;
1143 var desc = Object.getOwnPropertyDescriptor(obj, prop); 1173 var desc = Object.getOwnPropertyDescriptor(obj, prop);
1144 print("***", typeof obj, stringifyNoThrow(obj), prop); 1174 print("***", typeof obj, stringifyNoThrow(obj), prop);
1145 if (!desc || desc.configurable) 1175 if (!desc || desc.configurable)
1146 TestObserveConfigurable(obj, prop); 1176 TestObserveConfigurable(obj, prop, !desc || desc.writable);
1147 else if (desc.writable) 1177 else if (desc.writable)
1148 TestObserveNonConfigurable(obj, prop, desc); 1178 TestObserveNonConfigurable(obj, prop, desc);
1149 } 1179 }
1150 1180
1151 1181
1152 // Observing array length (including truncation) 1182 // Observing array length (including truncation)
1153 reset(); 1183 reset();
1154 var arr = ['a', 'b', 'c', 'd']; 1184 var arr = ['a', 'b', 'c', 'd'];
1155 var arr2 = ['alpha', 'beta']; 1185 var arr2 = ['alpha', 'beta'];
1156 var arr3 = ['hello']; 1186 var arr3 = ['hello'];
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after
1779 for (var n1 = 0; n1 < 3; ++n1) 1809 for (var n1 = 0; n1 < 3; ++n1)
1780 for (var n2 = 0; n2 < 3; ++n2) 1810 for (var n2 = 0; n2 < 3; ++n2)
1781 for (var i in mutation) 1811 for (var i in mutation)
1782 TestFastElementsLength(mutation[i], b1 != 0, b2 != 0, 20*n1, 20*n2); 1812 TestFastElementsLength(mutation[i], b1 != 0, b2 != 0, 20*n1, 20*n2);
1783 1813
1784 for (var b1 = 0; b1 < 2; ++b1) 1814 for (var b1 = 0; b1 < 2; ++b1)
1785 for (var b2 = 0; b2 < 2; ++b2) 1815 for (var b2 = 0; b2 < 2; ++b2)
1786 for (var n = 0; n < 3; ++n) 1816 for (var n = 0; n < 3; ++n)
1787 for (var i in mutationByIncr) 1817 for (var i in mutationByIncr)
1788 TestFastElementsLength(mutationByIncr[i], b1 != 0, b2 != 0, 7*n, 7*n+1); 1818 TestFastElementsLength(mutationByIncr[i], b1 != 0, b2 != 0, 7*n, 7*n+1);
OLDNEW
« no previous file with comments | « test/cctest/test-accessors.cc ('k') | test/mjsunit/regress/regress-1530.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698