Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2013 Google Inc. All rights reserved. | 3 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * | 8 * |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 1073 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1084 var injectedScript = new InjectedScript(); | 1084 var injectedScript = new InjectedScript(); |
| 1085 | 1085 |
| 1086 /** | 1086 /** |
| 1087 * @constructor | 1087 * @constructor |
| 1088 * @param {*} object | 1088 * @param {*} object |
| 1089 * @param {string=} objectGroupName | 1089 * @param {string=} objectGroupName |
| 1090 * @param {boolean=} forceValueType | 1090 * @param {boolean=} forceValueType |
| 1091 * @param {boolean=} generatePreview | 1091 * @param {boolean=} generatePreview |
| 1092 * @param {?Array.<string>=} columnNames | 1092 * @param {?Array.<string>=} columnNames |
| 1093 * @param {boolean=} isTable | 1093 * @param {boolean=} isTable |
| 1094 * @param {boolean=} skipEntriesPreview | |
| 1094 */ | 1095 */ |
| 1095 InjectedScript.RemoteObject = function(object, objectGroupName, forceValueType, generatePreview, columnNames, isTable) | 1096 InjectedScript.RemoteObject = function(object, objectGroupName, forceValueType, generatePreview, columnNames, isTable, skipEntriesPreview) |
| 1096 { | 1097 { |
| 1097 this.type = typeof object; | 1098 this.type = typeof object; |
| 1098 if (injectedScript.isPrimitiveValue(object) || object === null || forceValue Type) { | 1099 if (injectedScript.isPrimitiveValue(object) || object === null || forceValue Type) { |
| 1099 // We don't send undefined values over JSON. | 1100 // We don't send undefined values over JSON. |
| 1100 if (this.type !== "undefined") | 1101 if (this.type !== "undefined") |
| 1101 this.value = object; | 1102 this.value = object; |
| 1102 | 1103 |
| 1103 // Null object is object with 'null' subtype. | 1104 // Null object is object with 'null' subtype. |
| 1104 if (object === null) | 1105 if (object === null) |
| 1105 this.subtype = "null"; | 1106 this.subtype = "null"; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 1126 this.objectId = injectedScript._bind(object, objectGroupName); | 1127 this.objectId = injectedScript._bind(object, objectGroupName); |
| 1127 var subtype = injectedScript._subtype(object); | 1128 var subtype = injectedScript._subtype(object); |
| 1128 if (subtype) | 1129 if (subtype) |
| 1129 this.subtype = subtype; | 1130 this.subtype = subtype; |
| 1130 var className = InjectedScriptHost.internalConstructorName(object); | 1131 var className = InjectedScriptHost.internalConstructorName(object); |
| 1131 if (className) | 1132 if (className) |
| 1132 this.className = className; | 1133 this.className = className; |
| 1133 this.description = injectedScript._describe(object); | 1134 this.description = injectedScript._describe(object); |
| 1134 | 1135 |
| 1135 if (generatePreview && (this.type === "object" || injectedScript._isHTMLAllC ollection(object))) | 1136 if (generatePreview && (this.type === "object" || injectedScript._isHTMLAllC ollection(object))) |
| 1136 this.preview = this._generatePreview(object, undefined, columnNames, isT able); | 1137 this.preview = this._generatePreview(object, undefined, columnNames, isT able, skipEntriesPreview); |
| 1137 } | 1138 } |
| 1138 | 1139 |
| 1139 InjectedScript.RemoteObject.prototype = { | 1140 InjectedScript.RemoteObject.prototype = { |
| 1140 /** | 1141 /** |
| 1141 * @param {!Object} object | 1142 * @param {!Object} object |
| 1142 * @param {?Array.<string>=} firstLevelKeys | 1143 * @param {?Array.<string>=} firstLevelKeys |
| 1143 * @param {?Array.<string>=} secondLevelKeys | 1144 * @param {?Array.<string>=} secondLevelKeys |
| 1144 * @param {boolean=} isTable | 1145 * @param {boolean=} isTable |
| 1146 * @param {boolean=} skipEntriesPreview | |
| 1145 * @return {!RuntimeAgent.ObjectPreview} preview | 1147 * @return {!RuntimeAgent.ObjectPreview} preview |
| 1146 */ | 1148 */ |
| 1147 _generatePreview: function(object, firstLevelKeys, secondLevelKeys, isTable) | 1149 _generatePreview: function(object, firstLevelKeys, secondLevelKeys, isTable, skipEntriesPreview) |
| 1148 { | 1150 { |
| 1149 var preview = { __proto__: null }; | 1151 var preview = { |
| 1150 preview.lossless = true; | 1152 type: /** @type {!RuntimeAgent.ObjectPreviewType.<string>} */ (this. type), |
| 1151 preview.overflow = false; | 1153 description: this.description || toStringDescription(this.value), |
| 1152 preview.properties = []; | 1154 lossless: true, |
| 1155 overflow: false, | |
| 1156 properties: [], | |
| 1157 __proto__: null | |
| 1158 }; | |
| 1159 if (this.subtype) | |
| 1160 preview.subtype = /** @type {!RuntimeAgent.ObjectPreviewSubtype.<str ing>} */ (this.subtype); | |
| 1153 | 1161 |
| 1154 var firstLevelKeysCount = firstLevelKeys ? firstLevelKeys.length : 0; | 1162 var firstLevelKeysCount = firstLevelKeys ? firstLevelKeys.length : 0; |
| 1155 | 1163 |
| 1156 var propertiesThreshold = { | 1164 var propertiesThreshold = { |
| 1157 properties: isTable ? 1000 : max(5, firstLevelKeysCount), | 1165 properties: isTable ? 1000 : max(5, firstLevelKeysCount), |
| 1158 indexes: isTable ? 1000 : max(100, firstLevelKeysCount) | 1166 indexes: isTable ? 1000 : max(100, firstLevelKeysCount), |
| 1167 __proto__: null | |
| 1159 }; | 1168 }; |
| 1160 | 1169 |
| 1161 try { | 1170 try { |
| 1162 var descriptors = injectedScript._propertyDescriptors(object); | 1171 var descriptors = injectedScript._propertyDescriptors(object); |
| 1163 | 1172 |
| 1164 if (firstLevelKeys) { | 1173 if (firstLevelKeys) { |
| 1165 var nameToDescriptors = { __proto__: null }; | 1174 var nameToDescriptors = { __proto__: null }; |
| 1166 for (var i = 0; i < descriptors.length; ++i) { | 1175 for (var i = 0; i < descriptors.length; ++i) { |
| 1167 var descriptor = descriptors[i]; | 1176 var descriptor = descriptors[i]; |
| 1168 nameToDescriptors["#" + descriptor.name] = descriptor; | 1177 nameToDescriptors["#" + descriptor.name] = descriptor; |
| 1169 } | 1178 } |
| 1170 descriptors = []; | 1179 descriptors = []; |
| 1171 for (var i = 0; i < firstLevelKeys.length; ++i) | 1180 for (var i = 0; i < firstLevelKeys.length; ++i) |
| 1172 descriptors[i] = nameToDescriptors["#" + firstLevelKeys[i]]; | 1181 descriptors[i] = nameToDescriptors["#" + firstLevelKeys[i]]; |
| 1173 } | 1182 } |
| 1174 | 1183 |
| 1175 this._appendPropertyDescriptors(preview, descriptors, propertiesThre shold, secondLevelKeys, isTable); | 1184 this._appendPropertyDescriptors(preview, descriptors, propertiesThre shold, secondLevelKeys, isTable); |
| 1176 if (propertiesThreshold.indexes < 0 || propertiesThreshold.propertie s < 0) | 1185 if (propertiesThreshold.indexes < 0 || propertiesThreshold.propertie s < 0) |
| 1177 return preview; | 1186 return preview; |
| 1178 | 1187 |
| 1179 // Add internal properties to preview. | 1188 // Add internal properties to preview. |
| 1180 var internalProperties = InjectedScriptHost.getInternalProperties(ob ject) || []; | 1189 var internalProperties = InjectedScriptHost.getInternalProperties(ob ject) || []; |
| 1181 for (var i = 0; i < internalProperties.length; ++i) { | 1190 for (var i = 0; i < internalProperties.length; ++i) { |
| 1182 internalProperties[i] = nullifyObjectProto(internalProperties[i] ); | 1191 internalProperties[i] = nullifyObjectProto(internalProperties[i] ); |
| 1183 internalProperties[i].enumerable = true; | 1192 internalProperties[i].enumerable = true; |
| 1184 } | 1193 } |
| 1185 this._appendPropertyDescriptors(preview, internalProperties, propert iesThreshold, secondLevelKeys, isTable); | 1194 this._appendPropertyDescriptors(preview, internalProperties, propert iesThreshold, secondLevelKeys, isTable); |
| 1186 | 1195 |
| 1196 if (this.subtype === "map" || this.subtype === "set") | |
| 1197 this._appendEntriesPreview(object, preview, skipEntriesPreview); | |
| 1198 | |
| 1187 } catch (e) { | 1199 } catch (e) { |
| 1188 preview.lossless = false; | 1200 preview.lossless = false; |
| 1189 } | 1201 } |
| 1190 | 1202 |
| 1191 return preview; | 1203 return preview; |
| 1192 }, | 1204 }, |
| 1193 | 1205 |
| 1194 /** | 1206 /** |
| 1195 * @param {!RuntimeAgent.ObjectPreview} preview | 1207 * @param {!RuntimeAgent.ObjectPreview} preview |
| 1196 * @param {!Array.<!Object>} descriptors | 1208 * @param {!Array.<!Object>} descriptors |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1284 propertiesThreshold.properties--; | 1296 propertiesThreshold.properties--; |
| 1285 if (propertiesThreshold.indexes < 0 || propertiesThreshold.properties < 0) { | 1297 if (propertiesThreshold.indexes < 0 || propertiesThreshold.properties < 0) { |
| 1286 preview.overflow = true; | 1298 preview.overflow = true; |
| 1287 preview.lossless = false; | 1299 preview.lossless = false; |
| 1288 } else { | 1300 } else { |
| 1289 push(preview.properties, property); | 1301 push(preview.properties, property); |
| 1290 } | 1302 } |
| 1291 }, | 1303 }, |
| 1292 | 1304 |
| 1293 /** | 1305 /** |
| 1306 * @param {!Object} object | |
| 1307 * @param {!RuntimeAgent.ObjectPreview} preview | |
| 1308 * @param {boolean=} skipEntriesPreview | |
| 1309 */ | |
| 1310 _appendEntriesPreview: function(object, preview, skipEntriesPreview) | |
| 1311 { | |
| 1312 var entries = InjectedScriptHost.collectionEntries(object); | |
| 1313 if (!entries) | |
| 1314 return; | |
| 1315 if (skipEntriesPreview) { | |
| 1316 if (entries.length) { | |
| 1317 preview.overflow = true; | |
| 1318 preview.lossless = false; | |
| 1319 } | |
| 1320 return; | |
| 1321 } | |
| 1322 preview.entries = []; | |
| 1323 var entriesThreshold = 5; | |
| 1324 for (var i = 0; i < entries.length; ++i) { | |
| 1325 if (preview.entries.length >= entriesThreshold) { | |
| 1326 preview.overflow = true; | |
| 1327 preview.lossless = false; | |
| 1328 break; | |
| 1329 } | |
| 1330 var entry = nullifyObjectProto(entries[i]); | |
| 1331 var previewEntry = { | |
| 1332 value: generateValuePreview(entry.value), | |
| 1333 __proto__: null | |
| 1334 }; | |
| 1335 if ("key" in entry) | |
| 1336 previewEntry.key = generateValuePreview(entry.key); | |
| 1337 push(preview.entries, previewEntry); | |
|
yurys
2014/09/14 12:42:03
Is it to avoid calling overwritten Array.prototype
aandrey
2014/09/15 06:51:57
Yep. We also have a presubmit check to catch this.
| |
| 1338 } | |
| 1339 | |
| 1340 /** | |
| 1341 * @param {*} value | |
| 1342 * @return {!RuntimeAgent.ObjectPreview} | |
| 1343 */ | |
| 1344 function generateValuePreview(value) | |
| 1345 { | |
| 1346 var remoteObject = new InjectedScript.RemoteObject(value, undefined, undefined, true, undefined, undefined, true); | |
| 1347 var valuePreview = remoteObject.preview || { | |
| 1348 type: remoteObject.type, | |
| 1349 subtype: remoteObject.subtype, | |
| 1350 description: remoteObject.description || toStringDescription(rem oteObject.value), | |
| 1351 lossless: true, | |
| 1352 overflow: false, | |
| 1353 properties: [], | |
| 1354 __proto__: null | |
| 1355 }; | |
| 1356 if (remoteObject.objectId) | |
| 1357 injectedScript.releaseObject(remoteObject.objectId); | |
| 1358 if (!valuePreview.lossless) | |
| 1359 preview.lossless = false; | |
| 1360 return valuePreview; | |
| 1361 } | |
| 1362 }, | |
| 1363 | |
| 1364 /** | |
| 1294 * @param {string} string | 1365 * @param {string} string |
| 1295 * @param {number} maxLength | 1366 * @param {number} maxLength |
| 1296 * @param {boolean=} middle | 1367 * @param {boolean=} middle |
| 1297 * @return {string} | 1368 * @return {string} |
| 1298 */ | 1369 */ |
| 1299 _abbreviateString: function(string, maxLength, middle) | 1370 _abbreviateString: function(string, maxLength, middle) |
| 1300 { | 1371 { |
| 1301 if (string.length <= maxLength) | 1372 if (string.length <= maxLength) |
| 1302 return string; | 1373 return string; |
| 1303 if (middle) { | 1374 if (middle) { |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1722 */ | 1793 */ |
| 1723 _logEvent: function(event) | 1794 _logEvent: function(event) |
| 1724 { | 1795 { |
| 1725 inspectedWindow.console.log(event.type, event); | 1796 inspectedWindow.console.log(event.type, event); |
| 1726 } | 1797 } |
| 1727 } | 1798 } |
| 1728 | 1799 |
| 1729 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl(); | 1800 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl(); |
| 1730 return injectedScript; | 1801 return injectedScript; |
| 1731 }) | 1802 }) |
| OLD | NEW |