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; |
| 1099 if (this.type === "undefined" && injectedScript._isHTMLAllCollection(object)
) |
| 1100 this.type = "object"; |
| 1101 |
1098 if (injectedScript.isPrimitiveValue(object) || object === null || forceValue
Type) { | 1102 if (injectedScript.isPrimitiveValue(object) || object === null || forceValue
Type) { |
1099 // We don't send undefined values over JSON. | 1103 // We don't send undefined values over JSON. |
1100 if (this.type !== "undefined") | 1104 if (this.type !== "undefined") |
1101 this.value = object; | 1105 this.value = object; |
1102 | 1106 |
1103 // Null object is object with 'null' subtype. | 1107 // Null object is object with 'null' subtype. |
1104 if (object === null) | 1108 if (object === null) |
1105 this.subtype = "null"; | 1109 this.subtype = "null"; |
1106 | 1110 |
1107 // Provide user-friendly number values. | 1111 // Provide user-friendly number values. |
(...skipping 17 matching lines...) Expand all Loading... |
1125 | 1129 |
1126 this.objectId = injectedScript._bind(object, objectGroupName); | 1130 this.objectId = injectedScript._bind(object, objectGroupName); |
1127 var subtype = injectedScript._subtype(object); | 1131 var subtype = injectedScript._subtype(object); |
1128 if (subtype) | 1132 if (subtype) |
1129 this.subtype = subtype; | 1133 this.subtype = subtype; |
1130 var className = InjectedScriptHost.internalConstructorName(object); | 1134 var className = InjectedScriptHost.internalConstructorName(object); |
1131 if (className) | 1135 if (className) |
1132 this.className = className; | 1136 this.className = className; |
1133 this.description = injectedScript._describe(object); | 1137 this.description = injectedScript._describe(object); |
1134 | 1138 |
1135 if (generatePreview && (this.type === "object" || injectedScript._isHTMLAllC
ollection(object))) | 1139 if (generatePreview && this.type === "object") |
1136 this.preview = this._generatePreview(object, undefined, columnNames, isT
able); | 1140 this.preview = this._generatePreview(object, undefined, columnNames, isT
able, skipEntriesPreview); |
1137 } | 1141 } |
1138 | 1142 |
1139 InjectedScript.RemoteObject.prototype = { | 1143 InjectedScript.RemoteObject.prototype = { |
1140 /** | 1144 /** |
| 1145 * @return {!RuntimeAgent.ObjectPreview} preview |
| 1146 */ |
| 1147 _createEmptyPreview: function() |
| 1148 { |
| 1149 var preview = { |
| 1150 type: /** @type {!RuntimeAgent.ObjectPreviewType.<string>} */ (this.
type), |
| 1151 description: this.description || toStringDescription(this.value), |
| 1152 lossless: true, |
| 1153 overflow: false, |
| 1154 properties: [], |
| 1155 __proto__: null |
| 1156 }; |
| 1157 if (this.subtype) |
| 1158 preview.subtype = /** @type {!RuntimeAgent.ObjectPreviewSubtype.<str
ing>} */ (this.subtype); |
| 1159 return preview; |
| 1160 }, |
| 1161 |
| 1162 /** |
1141 * @param {!Object} object | 1163 * @param {!Object} object |
1142 * @param {?Array.<string>=} firstLevelKeys | 1164 * @param {?Array.<string>=} firstLevelKeys |
1143 * @param {?Array.<string>=} secondLevelKeys | 1165 * @param {?Array.<string>=} secondLevelKeys |
1144 * @param {boolean=} isTable | 1166 * @param {boolean=} isTable |
| 1167 * @param {boolean=} skipEntriesPreview |
1145 * @return {!RuntimeAgent.ObjectPreview} preview | 1168 * @return {!RuntimeAgent.ObjectPreview} preview |
1146 */ | 1169 */ |
1147 _generatePreview: function(object, firstLevelKeys, secondLevelKeys, isTable) | 1170 _generatePreview: function(object, firstLevelKeys, secondLevelKeys, isTable,
skipEntriesPreview) |
1148 { | 1171 { |
1149 var preview = { __proto__: null }; | 1172 var preview = this._createEmptyPreview(); |
1150 preview.lossless = true; | |
1151 preview.overflow = false; | |
1152 preview.properties = []; | |
1153 | |
1154 var firstLevelKeysCount = firstLevelKeys ? firstLevelKeys.length : 0; | 1173 var firstLevelKeysCount = firstLevelKeys ? firstLevelKeys.length : 0; |
1155 | 1174 |
1156 var propertiesThreshold = { | 1175 var propertiesThreshold = { |
1157 properties: isTable ? 1000 : max(5, firstLevelKeysCount), | 1176 properties: isTable ? 1000 : max(5, firstLevelKeysCount), |
1158 indexes: isTable ? 1000 : max(100, firstLevelKeysCount) | 1177 indexes: isTable ? 1000 : max(100, firstLevelKeysCount), |
| 1178 __proto__: null |
1159 }; | 1179 }; |
1160 | 1180 |
1161 try { | 1181 try { |
1162 var descriptors = injectedScript._propertyDescriptors(object); | 1182 var descriptors = injectedScript._propertyDescriptors(object); |
1163 | 1183 |
1164 if (firstLevelKeys) { | 1184 if (firstLevelKeys) { |
1165 var nameToDescriptors = { __proto__: null }; | 1185 var nameToDescriptors = { __proto__: null }; |
1166 for (var i = 0; i < descriptors.length; ++i) { | 1186 for (var i = 0; i < descriptors.length; ++i) { |
1167 var descriptor = descriptors[i]; | 1187 var descriptor = descriptors[i]; |
1168 nameToDescriptors["#" + descriptor.name] = descriptor; | 1188 nameToDescriptors["#" + descriptor.name] = descriptor; |
1169 } | 1189 } |
1170 descriptors = []; | 1190 descriptors = []; |
1171 for (var i = 0; i < firstLevelKeys.length; ++i) | 1191 for (var i = 0; i < firstLevelKeys.length; ++i) |
1172 descriptors[i] = nameToDescriptors["#" + firstLevelKeys[i]]; | 1192 descriptors[i] = nameToDescriptors["#" + firstLevelKeys[i]]; |
1173 } | 1193 } |
1174 | 1194 |
1175 this._appendPropertyDescriptors(preview, descriptors, propertiesThre
shold, secondLevelKeys, isTable); | 1195 this._appendPropertyDescriptors(preview, descriptors, propertiesThre
shold, secondLevelKeys, isTable); |
1176 if (propertiesThreshold.indexes < 0 || propertiesThreshold.propertie
s < 0) | 1196 if (propertiesThreshold.indexes < 0 || propertiesThreshold.propertie
s < 0) |
1177 return preview; | 1197 return preview; |
1178 | 1198 |
1179 // Add internal properties to preview. | 1199 // Add internal properties to preview. |
1180 var internalProperties = InjectedScriptHost.getInternalProperties(ob
ject) || []; | 1200 var internalProperties = InjectedScriptHost.getInternalProperties(ob
ject) || []; |
1181 for (var i = 0; i < internalProperties.length; ++i) { | 1201 for (var i = 0; i < internalProperties.length; ++i) { |
1182 internalProperties[i] = nullifyObjectProto(internalProperties[i]
); | 1202 internalProperties[i] = nullifyObjectProto(internalProperties[i]
); |
1183 internalProperties[i].enumerable = true; | 1203 internalProperties[i].enumerable = true; |
1184 } | 1204 } |
1185 this._appendPropertyDescriptors(preview, internalProperties, propert
iesThreshold, secondLevelKeys, isTable); | 1205 this._appendPropertyDescriptors(preview, internalProperties, propert
iesThreshold, secondLevelKeys, isTable); |
1186 | 1206 |
| 1207 if (this.subtype === "map" || this.subtype === "set") |
| 1208 this._appendEntriesPreview(object, preview, skipEntriesPreview); |
| 1209 |
1187 } catch (e) { | 1210 } catch (e) { |
1188 preview.lossless = false; | 1211 preview.lossless = false; |
1189 } | 1212 } |
1190 | 1213 |
1191 return preview; | 1214 return preview; |
1192 }, | 1215 }, |
1193 | 1216 |
1194 /** | 1217 /** |
1195 * @param {!RuntimeAgent.ObjectPreview} preview | 1218 * @param {!RuntimeAgent.ObjectPreview} preview |
1196 * @param {!Array.<!Object>} descriptors | 1219 * @param {!Array.<!Object>} descriptors |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1284 propertiesThreshold.properties--; | 1307 propertiesThreshold.properties--; |
1285 if (propertiesThreshold.indexes < 0 || propertiesThreshold.properties <
0) { | 1308 if (propertiesThreshold.indexes < 0 || propertiesThreshold.properties <
0) { |
1286 preview.overflow = true; | 1309 preview.overflow = true; |
1287 preview.lossless = false; | 1310 preview.lossless = false; |
1288 } else { | 1311 } else { |
1289 push(preview.properties, property); | 1312 push(preview.properties, property); |
1290 } | 1313 } |
1291 }, | 1314 }, |
1292 | 1315 |
1293 /** | 1316 /** |
| 1317 * @param {!Object} object |
| 1318 * @param {!RuntimeAgent.ObjectPreview} preview |
| 1319 * @param {boolean=} skipEntriesPreview |
| 1320 */ |
| 1321 _appendEntriesPreview: function(object, preview, skipEntriesPreview) |
| 1322 { |
| 1323 var entries = InjectedScriptHost.collectionEntries(object); |
| 1324 if (!entries) |
| 1325 return; |
| 1326 if (skipEntriesPreview) { |
| 1327 if (entries.length) { |
| 1328 preview.overflow = true; |
| 1329 preview.lossless = false; |
| 1330 } |
| 1331 return; |
| 1332 } |
| 1333 preview.entries = []; |
| 1334 var entriesThreshold = 5; |
| 1335 for (var i = 0; i < entries.length; ++i) { |
| 1336 if (preview.entries.length >= entriesThreshold) { |
| 1337 preview.overflow = true; |
| 1338 preview.lossless = false; |
| 1339 break; |
| 1340 } |
| 1341 var entry = nullifyObjectProto(entries[i]); |
| 1342 var previewEntry = { |
| 1343 value: generateValuePreview(entry.value), |
| 1344 __proto__: null |
| 1345 }; |
| 1346 if ("key" in entry) |
| 1347 previewEntry.key = generateValuePreview(entry.key); |
| 1348 push(preview.entries, previewEntry); |
| 1349 } |
| 1350 |
| 1351 /** |
| 1352 * @param {*} value |
| 1353 * @return {!RuntimeAgent.ObjectPreview} |
| 1354 */ |
| 1355 function generateValuePreview(value) |
| 1356 { |
| 1357 var remoteObject = new InjectedScript.RemoteObject(value, undefined,
undefined, true, undefined, undefined, true); |
| 1358 var valuePreview = remoteObject.preview || remoteObject._createEmpty
Preview(); |
| 1359 if (remoteObject.objectId) |
| 1360 injectedScript.releaseObject(remoteObject.objectId); |
| 1361 if (!valuePreview.lossless) |
| 1362 preview.lossless = false; |
| 1363 return valuePreview; |
| 1364 } |
| 1365 }, |
| 1366 |
| 1367 /** |
1294 * @param {string} string | 1368 * @param {string} string |
1295 * @param {number} maxLength | 1369 * @param {number} maxLength |
1296 * @param {boolean=} middle | 1370 * @param {boolean=} middle |
1297 * @return {string} | 1371 * @return {string} |
1298 */ | 1372 */ |
1299 _abbreviateString: function(string, maxLength, middle) | 1373 _abbreviateString: function(string, maxLength, middle) |
1300 { | 1374 { |
1301 if (string.length <= maxLength) | 1375 if (string.length <= maxLength) |
1302 return string; | 1376 return string; |
1303 if (middle) { | 1377 if (middle) { |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1722 */ | 1796 */ |
1723 _logEvent: function(event) | 1797 _logEvent: function(event) |
1724 { | 1798 { |
1725 inspectedWindow.console.log(event.type, event); | 1799 inspectedWindow.console.log(event.type, event); |
1726 } | 1800 } |
1727 } | 1801 } |
1728 | 1802 |
1729 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl(); | 1803 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl(); |
1730 return injectedScript; | 1804 return injectedScript; |
1731 }) | 1805 }) |
OLD | NEW |