| 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 1090 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1101 this.objectId = injectedScript._bind(object, objectGroupName); | 1101 this.objectId = injectedScript._bind(object, objectGroupName); |
| 1102 var subtype = injectedScript._subtype(object); | 1102 var subtype = injectedScript._subtype(object); |
| 1103 if (subtype) | 1103 if (subtype) |
| 1104 this.subtype = subtype; | 1104 this.subtype = subtype; |
| 1105 var className = InjectedScriptHost.internalConstructorName(object); | 1105 var className = InjectedScriptHost.internalConstructorName(object); |
| 1106 if (className) | 1106 if (className) |
| 1107 this.className = className; | 1107 this.className = className; |
| 1108 this.description = injectedScript._describe(object); | 1108 this.description = injectedScript._describe(object); |
| 1109 | 1109 |
| 1110 if (generatePreview && (this.type === "object" || injectedScript._isHTMLAllC
ollection(object))) | 1110 if (generatePreview && (this.type === "object" || injectedScript._isHTMLAllC
ollection(object))) |
| 1111 this.preview = this._generatePreview(object, undefined, columnNames, isT
able, false); | 1111 this.preview = this._generatePreview(object, undefined, columnNames, isT
able); |
| 1112 } | 1112 } |
| 1113 | 1113 |
| 1114 InjectedScript.RemoteObject.prototype = { | 1114 InjectedScript.RemoteObject.prototype = { |
| 1115 /** | 1115 /** |
| 1116 * @param {!Object} object | 1116 * @param {!Object} object |
| 1117 * @param {?Array.<string>=} firstLevelKeys | 1117 * @param {?Array.<string>=} firstLevelKeys |
| 1118 * @param {?Array.<string>=} secondLevelKeys | 1118 * @param {?Array.<string>=} secondLevelKeys |
| 1119 * @param {boolean=} isTable | 1119 * @param {boolean=} isTable |
| 1120 * @param {boolean=} isTableRow | |
| 1121 * @return {!RuntimeAgent.ObjectPreview} preview | 1120 * @return {!RuntimeAgent.ObjectPreview} preview |
| 1122 */ | 1121 */ |
| 1123 _generatePreview: function(object, firstLevelKeys, secondLevelKeys, isTable,
isTableRow) | 1122 _generatePreview: function(object, firstLevelKeys, secondLevelKeys, isTable) |
| 1124 { | 1123 { |
| 1125 var preview = { __proto__: null }; | 1124 var preview = { __proto__: null }; |
| 1126 preview.lossless = true; | 1125 preview.lossless = true; |
| 1127 preview.overflow = false; | 1126 preview.overflow = false; |
| 1128 preview.properties = []; | 1127 preview.properties = []; |
| 1129 | 1128 |
| 1130 var firstLevelKeysCount = firstLevelKeys ? firstLevelKeys.length : 0; | 1129 var firstLevelKeysCount = firstLevelKeys ? firstLevelKeys.length : 0; |
| 1131 | 1130 |
| 1132 var propertiesThreshold = { | 1131 var propertiesThreshold = { |
| 1133 properties: (isTable || isTableRow) ? 1000 : max(5, firstLevelKeysCo
unt), | 1132 properties: isTable ? 1000 : max(5, firstLevelKeysCount), |
| 1134 indexes: (isTable || isTableRow) ? 1000 : max(100, firstLevelKeysCou
nt) | 1133 indexes: isTable ? 1000 : max(100, firstLevelKeysCount) |
| 1135 }; | 1134 }; |
| 1136 | 1135 |
| 1137 try { | 1136 try { |
| 1138 var descriptors = injectedScript._propertyDescriptors(object); | 1137 var descriptors = injectedScript._propertyDescriptors(object); |
| 1139 | 1138 |
| 1140 if (firstLevelKeys) { | 1139 if (firstLevelKeys) { |
| 1141 var nameToDescriptors = { __proto__: null }; | 1140 var nameToDescriptors = { __proto__: null }; |
| 1142 for (var i = 0; i < descriptors.length; ++i) { | 1141 for (var i = 0; i < descriptors.length; ++i) { |
| 1143 var descriptor = descriptors[i]; | 1142 var descriptor = descriptors[i]; |
| 1144 nameToDescriptors["#" + descriptor.name] = descriptor; | 1143 nameToDescriptors["#" + descriptor.name] = descriptor; |
| 1145 } | 1144 } |
| 1146 descriptors = []; | 1145 descriptors = []; |
| 1147 for (var i = 0; i < firstLevelKeys.length; ++i) | 1146 for (var i = 0; i < firstLevelKeys.length; ++i) |
| 1148 descriptors[i] = nameToDescriptors["#" + firstLevelKeys[i]]; | 1147 descriptors[i] = nameToDescriptors["#" + firstLevelKeys[i]]; |
| 1149 } | 1148 } |
| 1150 | 1149 |
| 1151 for (var i = 0; i < descriptors.length; ++i) { | 1150 this._appendPropertyDescriptors(preview, descriptors, propertiesThre
shold, secondLevelKeys, isTable); |
| 1152 if (propertiesThreshold.indexes < 0 || propertiesThreshold.prope
rties < 0) | 1151 if (propertiesThreshold.indexes < 0 || propertiesThreshold.propertie
s < 0) |
| 1153 break; | 1152 return preview; |
| 1154 | 1153 |
| 1155 var descriptor = descriptors[i]; | 1154 // Add internal properties to preview. |
| 1156 if (!descriptor) | 1155 var internalProperties = InjectedScriptHost.getInternalProperties(ob
ject) || []; |
| 1157 continue; | 1156 for (var i = 0; i < internalProperties.length; ++i) { |
| 1158 if (descriptor.wasThrown) { | 1157 internalProperties[i] = nullifyObjectProto(internalProperties[i]
); |
| 1159 preview.lossless = false; | 1158 internalProperties[i].enumerable = true; |
| 1160 continue; | 1159 } |
| 1161 } | 1160 this._appendPropertyDescriptors(preview, internalProperties, propert
iesThreshold, secondLevelKeys, isTable); |
| 1162 if (!descriptor.enumerable && !descriptor.isOwn) | |
| 1163 continue; | |
| 1164 | 1161 |
| 1165 var name = descriptor.name; | |
| 1166 if (name === "__proto__") | |
| 1167 continue; | |
| 1168 if (this.subtype === "array" && name === "length") | |
| 1169 continue; | |
| 1170 | |
| 1171 if (!("value" in descriptor)) { | |
| 1172 preview.lossless = false; | |
| 1173 this._appendPropertyPreview(preview, { name: name, type: "ac
cessor", __proto__: null }, propertiesThreshold); | |
| 1174 continue; | |
| 1175 } | |
| 1176 | |
| 1177 var value = descriptor.value; | |
| 1178 if (value === null) { | |
| 1179 this._appendPropertyPreview(preview, { name: name, type: "ob
ject", value: "null", __proto__: null }, propertiesThreshold); | |
| 1180 continue; | |
| 1181 } | |
| 1182 | |
| 1183 const maxLength = 100; | |
| 1184 var type = typeof value; | |
| 1185 if (!descriptor.enumerable && type === "function") | |
| 1186 continue; | |
| 1187 if (type === "undefined" && injectedScript._isHTMLAllCollection(
value)) | |
| 1188 type = "object"; | |
| 1189 | |
| 1190 if (InjectedScript.primitiveTypes[type]) { | |
| 1191 if (type === "string" && value.length > maxLength) { | |
| 1192 value = this._abbreviateString(value, maxLength, true); | |
| 1193 preview.lossless = false; | |
| 1194 } | |
| 1195 this._appendPropertyPreview(preview, { name: name, type: typ
e, value: toStringDescription(value), __proto__: null }, propertiesThreshold); | |
| 1196 continue; | |
| 1197 } | |
| 1198 | |
| 1199 if (secondLevelKeys === null || secondLevelKeys) { | |
| 1200 var subPreview = this._generatePreview(value, secondLevelKey
s || undefined, undefined, false, isTable); | |
| 1201 var property = { name: name, type: type, valuePreview: subPr
eview, __proto__: null }; | |
| 1202 this._appendPropertyPreview(preview, property, propertiesThr
eshold); | |
| 1203 if (!subPreview.lossless) | |
| 1204 preview.lossless = false; | |
| 1205 if (subPreview.overflow) | |
| 1206 preview.overflow = true; | |
| 1207 continue; | |
| 1208 } | |
| 1209 | |
| 1210 preview.lossless = false; | |
| 1211 | |
| 1212 var subtype = injectedScript._subtype(value); | |
| 1213 var description = ""; | |
| 1214 if (type !== "function") | |
| 1215 description = this._abbreviateString(/** @type {string} */ (
injectedScript._describe(value)), maxLength, subtype === "regexp"); | |
| 1216 | |
| 1217 var property = { name: name, type: type, value: description, __p
roto__: null }; | |
| 1218 if (subtype) | |
| 1219 property.subtype = subtype; | |
| 1220 this._appendPropertyPreview(preview, property, propertiesThresho
ld); | |
| 1221 } | |
| 1222 } catch (e) { | 1162 } catch (e) { |
| 1223 preview.lossless = false; | 1163 preview.lossless = false; |
| 1224 } | 1164 } |
| 1225 | 1165 |
| 1226 return preview; | 1166 return preview; |
| 1227 }, | 1167 }, |
| 1228 | 1168 |
| 1229 /** | 1169 /** |
| 1170 * @param {!RuntimeAgent.ObjectPreview} preview |
| 1171 * @param {!Array.<Object>} descriptors |
| 1172 * @param {!Object} propertiesThreshold |
| 1173 * @param {?Array.<string>=} secondLevelKeys |
| 1174 * @param {boolean=} isTable |
| 1175 */ |
| 1176 _appendPropertyDescriptors: function(preview, descriptors, propertiesThresho
ld, secondLevelKeys, isTable) |
| 1177 { |
| 1178 for (var i = 0; i < descriptors.length; ++i) { |
| 1179 if (propertiesThreshold.indexes < 0 || propertiesThreshold.propertie
s < 0) |
| 1180 break; |
| 1181 |
| 1182 var descriptor = descriptors[i]; |
| 1183 if (!descriptor) |
| 1184 continue; |
| 1185 if (descriptor.wasThrown) { |
| 1186 preview.lossless = false; |
| 1187 continue; |
| 1188 } |
| 1189 if (!descriptor.enumerable && !descriptor.isOwn) |
| 1190 continue; |
| 1191 |
| 1192 var name = descriptor.name; |
| 1193 if (name === "__proto__") |
| 1194 continue; |
| 1195 if (this.subtype === "array" && name === "length") |
| 1196 continue; |
| 1197 |
| 1198 if (!("value" in descriptor)) { |
| 1199 preview.lossless = false; |
| 1200 this._appendPropertyPreview(preview, { name: name, type: "access
or", __proto__: null }, propertiesThreshold); |
| 1201 continue; |
| 1202 } |
| 1203 |
| 1204 var value = descriptor.value; |
| 1205 if (value === null) { |
| 1206 this._appendPropertyPreview(preview, { name: name, type: "object
", value: "null", __proto__: null }, propertiesThreshold); |
| 1207 continue; |
| 1208 } |
| 1209 |
| 1210 const maxLength = 100; |
| 1211 var type = typeof value; |
| 1212 if (!descriptor.enumerable && type === "function") |
| 1213 continue; |
| 1214 if (type === "undefined" && injectedScript._isHTMLAllCollection(valu
e)) |
| 1215 type = "object"; |
| 1216 |
| 1217 if (InjectedScript.primitiveTypes[type]) { |
| 1218 if (type === "string" && value.length > maxLength) { |
| 1219 value = this._abbreviateString(value, maxLength, true); |
| 1220 preview.lossless = false; |
| 1221 } |
| 1222 this._appendPropertyPreview(preview, { name: name, type: type, v
alue: toStringDescription(value), __proto__: null }, propertiesThreshold); |
| 1223 continue; |
| 1224 } |
| 1225 |
| 1226 if (secondLevelKeys === null || secondLevelKeys) { |
| 1227 var subPreview = this._generatePreview(value, secondLevelKeys ||
undefined, undefined, isTable); |
| 1228 var property = { name: name, type: type, valuePreview: subPrevie
w, __proto__: null }; |
| 1229 this._appendPropertyPreview(preview, property, propertiesThresho
ld); |
| 1230 if (!subPreview.lossless) |
| 1231 preview.lossless = false; |
| 1232 if (subPreview.overflow) |
| 1233 preview.overflow = true; |
| 1234 continue; |
| 1235 } |
| 1236 |
| 1237 preview.lossless = false; |
| 1238 |
| 1239 var subtype = injectedScript._subtype(value); |
| 1240 var description = ""; |
| 1241 if (type !== "function") |
| 1242 description = this._abbreviateString(/** @type {string} */ (inje
ctedScript._describe(value)), maxLength, subtype === "regexp"); |
| 1243 |
| 1244 var property = { name: name, type: type, value: description, __proto
__: null }; |
| 1245 if (subtype) |
| 1246 property.subtype = subtype; |
| 1247 this._appendPropertyPreview(preview, property, propertiesThreshold); |
| 1248 } |
| 1249 }, |
| 1250 |
| 1251 /** |
| 1230 * @param {!RuntimeAgent.ObjectPreview} preview | 1252 * @param {!RuntimeAgent.ObjectPreview} preview |
| 1231 * @param {!Object} property | 1253 * @param {!Object} property |
| 1232 * @param {!Object} propertiesThreshold | 1254 * @param {!Object} propertiesThreshold |
| 1233 */ | 1255 */ |
| 1234 _appendPropertyPreview: function(preview, property, propertiesThreshold) | 1256 _appendPropertyPreview: function(preview, property, propertiesThreshold) |
| 1235 { | 1257 { |
| 1236 if (toString(property.name >>> 0) === property.name) | 1258 if (toString(property.name >>> 0) === property.name) |
| 1237 propertiesThreshold.indexes--; | 1259 propertiesThreshold.indexes--; |
| 1238 else | 1260 else |
| 1239 propertiesThreshold.properties--; | 1261 propertiesThreshold.properties--; |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1677 */ | 1699 */ |
| 1678 _logEvent: function(event) | 1700 _logEvent: function(event) |
| 1679 { | 1701 { |
| 1680 inspectedWindow.console.log(event.type, event); | 1702 inspectedWindow.console.log(event.type, event); |
| 1681 } | 1703 } |
| 1682 } | 1704 } |
| 1683 | 1705 |
| 1684 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl(); | 1706 injectedScript._commandLineAPIImpl = new CommandLineAPIImpl(); |
| 1685 return injectedScript; | 1707 return injectedScript; |
| 1686 }) | 1708 }) |
| OLD | NEW |