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 794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 805 this.objectId = injectedScript._bind(object, objectGroupName); | 805 this.objectId = injectedScript._bind(object, objectGroupName); |
| 806 var subtype = injectedScript._subtype(object); | 806 var subtype = injectedScript._subtype(object); |
| 807 if (subtype) | 807 if (subtype) |
| 808 this.subtype = subtype; | 808 this.subtype = subtype; |
| 809 var className = InjectedScriptHost.internalConstructorName(object); | 809 var className = InjectedScriptHost.internalConstructorName(object); |
| 810 if (className) | 810 if (className) |
| 811 this.className = className; | 811 this.className = className; |
| 812 this.description = injectedScript._describe(object); | 812 this.description = injectedScript._describe(object); |
| 813 | 813 |
| 814 if (generatePreview && this.type === "object") { | 814 if (generatePreview && this.type === "object") { |
| 815 if (this.subtype === "proxy") { | 815 if (this.subtype === "proxy") { |
|
kozy
2016/05/10 00:04:42
please remove brackets
luoe
2016/05/10 17:27:45
Done.
| |
| 816 this.preview = this._generatePreview(InjectedScriptHost.proxyTargetV alue(object), undefined, columnNames, isTable, skipEntriesPreview); | 816 this.preview = this._generatePreview(InjectedScriptHost.proxyTargetV alue(object), undefined, columnNames, isTable, skipEntriesPreview); |
| 817 this.preview.lossless = false; | |
| 818 } else if (this.subtype !== "node") { | 817 } else if (this.subtype !== "node") { |
| 819 this.preview = this._generatePreview(object, undefined, columnNames, isTable, skipEntriesPreview); | 818 this.preview = this._generatePreview(object, undefined, columnNames, isTable, skipEntriesPreview); |
| 820 } | 819 } |
| 821 } | 820 } |
| 822 | 821 |
| 823 if (injectedScript._customObjectFormatterEnabled) { | 822 if (injectedScript._customObjectFormatterEnabled) { |
| 824 var customPreview = this._customPreview(object, objectGroupName, customO bjectConfig); | 823 var customPreview = this._customPreview(object, objectGroupName, customO bjectConfig); |
| 825 if (customPreview) | 824 if (customPreview) |
| 826 this.customPreview = customPreview; | 825 this.customPreview = customPreview; |
| 827 } | 826 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 874 }, | 873 }, |
| 875 | 874 |
| 876 /** | 875 /** |
| 877 * @return {!RuntimeAgent.ObjectPreview} preview | 876 * @return {!RuntimeAgent.ObjectPreview} preview |
| 878 */ | 877 */ |
| 879 _createEmptyPreview: function() | 878 _createEmptyPreview: function() |
| 880 { | 879 { |
| 881 var preview = { | 880 var preview = { |
| 882 type: /** @type {!RuntimeAgent.ObjectPreviewType.<string>} */ (this. type), | 881 type: /** @type {!RuntimeAgent.ObjectPreviewType.<string>} */ (this. type), |
| 883 description: this.description || toStringDescription(this.value), | 882 description: this.description || toStringDescription(this.value), |
| 884 lossless: true, | |
| 885 overflow: false, | 883 overflow: false, |
| 886 properties: [], | 884 properties: [], |
| 887 __proto__: null | 885 __proto__: null |
| 888 }; | 886 }; |
| 889 if (this.subtype) | 887 if (this.subtype) |
| 890 preview.subtype = /** @type {!RuntimeAgent.ObjectPreviewSubtype.<str ing>} */ (this.subtype); | 888 preview.subtype = /** @type {!RuntimeAgent.ObjectPreviewSubtype.<str ing>} */ (this.subtype); |
| 891 return preview; | 889 return preview; |
| 892 }, | 890 }, |
| 893 | 891 |
| 894 /** | 892 /** |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 927 isOwn: true, | 925 isOwn: true, |
| 928 enumerable: true, | 926 enumerable: true, |
| 929 __proto__: null | 927 __proto__: null |
| 930 }); | 928 }); |
| 931 } | 929 } |
| 932 this._appendPropertyDescriptors(preview, internalProperties, propert iesThreshold, secondLevelKeys, isTable); | 930 this._appendPropertyDescriptors(preview, internalProperties, propert iesThreshold, secondLevelKeys, isTable); |
| 933 | 931 |
| 934 if (this.subtype === "map" || this.subtype === "set" || this.subtype === "iterator") | 932 if (this.subtype === "map" || this.subtype === "set" || this.subtype === "iterator") |
| 935 this._appendEntriesPreview(object, preview, skipEntriesPreview); | 933 this._appendEntriesPreview(object, preview, skipEntriesPreview); |
| 936 | 934 |
| 937 } catch (e) { | 935 } catch (e) {} |
| 938 preview.lossless = false; | |
| 939 } | |
| 940 | 936 |
| 941 return preview; | 937 return preview; |
| 942 }, | 938 }, |
| 943 | 939 |
| 944 /** | 940 /** |
| 945 * @param {!RuntimeAgent.ObjectPreview} preview | 941 * @param {!RuntimeAgent.ObjectPreview} preview |
| 946 * @param {!Array.<*>|!Iterable.<*>} descriptors | 942 * @param {!Array.<*>|!Iterable.<*>} descriptors |
| 947 * @param {!Object} propertiesThreshold | 943 * @param {!Object} propertiesThreshold |
| 948 * @param {?Array.<string>=} secondLevelKeys | 944 * @param {?Array.<string>=} secondLevelKeys |
| 949 * @param {boolean=} isTable | 945 * @param {boolean=} isTable |
| 950 */ | 946 */ |
| 951 _appendPropertyDescriptors: function(preview, descriptors, propertiesThresho ld, secondLevelKeys, isTable) | 947 _appendPropertyDescriptors: function(preview, descriptors, propertiesThresho ld, secondLevelKeys, isTable) |
| 952 { | 948 { |
| 953 for (var descriptor of descriptors) { | 949 for (var descriptor of descriptors) { |
| 954 if (propertiesThreshold.indexes < 0 || propertiesThreshold.propertie s < 0) | 950 if (propertiesThreshold.indexes < 0 || propertiesThreshold.propertie s < 0) |
| 955 break; | 951 break; |
| 956 if (!descriptor) | 952 if (!descriptor || descriptor.wasThrown) { |
|
kozy
2016/05/10 00:04:42
ditto
luoe
2016/05/10 17:27:45
Done.
| |
| 957 continue; | |
| 958 if (descriptor.wasThrown) { | |
| 959 preview.lossless = false; | |
| 960 continue; | 953 continue; |
| 961 } | 954 } |
| 962 | 955 |
| 963 var name = descriptor.name; | 956 var name = descriptor.name; |
| 964 | 957 |
| 965 // Ignore __proto__ property, stay lossless. | 958 // Ignore __proto__ property. |
| 966 if (name === "__proto__") | 959 if (name === "__proto__") |
| 967 continue; | 960 continue; |
| 968 | 961 |
| 969 // Ignore non-enumerable members on prototype, stay lossless. | 962 // Ignore length property of array. |
| 970 if (!descriptor.isOwn && !descriptor.enumerable) | |
|
kozy
2016/05/10 00:04:42
Bring it back and remove following descriptor.isOw
luoe
2016/05/10 17:27:45
That would allow enumerable props on the prototype
kozy
2016/05/11 00:54:18
Yep, it's right. It's my fault.
| |
| 971 continue; | |
| 972 | |
| 973 // Ignore length property of array, stay lossless. | |
| 974 if (this.subtype === "array" && name === "length") | 963 if (this.subtype === "array" && name === "length") |
| 975 continue; | 964 continue; |
| 976 | 965 |
| 977 // Ignore size property of map, set, stay lossless. | 966 // Ignore size property of map, set. |
| 978 if ((this.subtype === "map" || this.subtype === "set") && name === " size") | 967 if ((this.subtype === "map" || this.subtype === "set") && name === " size") |
| 979 continue; | 968 continue; |
| 980 | 969 |
| 981 // Never preview prototype properties, turn lossy. | 970 // Never preview prototype properties. |
| 982 if (!descriptor.isOwn) { | 971 if (!descriptor.isOwn) |
| 983 preview.lossless = false; | |
| 984 continue; | 972 continue; |
| 985 } | |
| 986 | 973 |
| 987 // Ignore computed properties, turn lossy. | 974 // Ignore computed properties. |
| 988 if (!("value" in descriptor)) { | 975 if (!("value" in descriptor)) |
| 989 preview.lossless = false; | |
| 990 continue; | 976 continue; |
| 991 } | |
| 992 | 977 |
| 993 var value = descriptor.value; | 978 var value = descriptor.value; |
| 994 var type = typeof value; | 979 var type = typeof value; |
| 995 | 980 |
| 996 // Never render functions in object preview, turn lossy | 981 // Never render functions in object preview. |
| 997 if (type === "function" && (this.subtype !== "array" || !isUInt32(na me))) { | 982 if (type === "function" && (this.subtype !== "array" || !isUInt32(na me))) |
| 998 preview.lossless = false; | |
| 999 continue; | 983 continue; |
| 1000 } | |
| 1001 | 984 |
| 1002 // Special-case HTMLAll. | 985 // Special-case HTMLAll. |
| 1003 if (type === "undefined" && injectedScript._isHTMLAllCollection(valu e)) | 986 if (type === "undefined" && injectedScript._isHTMLAllCollection(valu e)) |
| 1004 type = "object"; | 987 type = "object"; |
| 1005 | 988 |
| 1006 // Render own properties. | 989 // Render own properties. |
| 1007 if (value === null) { | 990 if (value === null) { |
| 1008 this._appendPropertyPreview(preview, { name: name, type: "object ", subtype: "null", value: "null", __proto__: null }, propertiesThreshold); | 991 this._appendPropertyPreview(preview, { name: name, type: "object ", subtype: "null", value: "null", __proto__: null }, propertiesThreshold); |
| 1009 continue; | 992 continue; |
| 1010 } | 993 } |
| 1011 | 994 |
| 1012 var maxLength = 100; | 995 var maxLength = 100; |
| 1013 if (InjectedScript.primitiveTypes[type]) { | 996 if (InjectedScript.primitiveTypes[type]) { |
| 1014 if (type === "string" && value.length > maxLength) { | 997 if (type === "string" && value.length > maxLength) |
| 1015 value = this._abbreviateString(value, maxLength, true); | 998 value = this._abbreviateString(value, maxLength, true); |
| 1016 preview.lossless = false; | |
| 1017 } | |
| 1018 this._appendPropertyPreview(preview, { name: name, type: type, v alue: toStringDescription(value), __proto__: null }, propertiesThreshold); | 999 this._appendPropertyPreview(preview, { name: name, type: type, v alue: toStringDescription(value), __proto__: null }, propertiesThreshold); |
| 1019 continue; | 1000 continue; |
| 1020 } | 1001 } |
| 1021 | 1002 |
| 1022 var property = { name: name, type: type, __proto__: null }; | 1003 var property = { name: name, type: type, __proto__: null }; |
| 1023 var subtype = injectedScript._subtype(value); | 1004 var subtype = injectedScript._subtype(value); |
| 1024 if (subtype) | 1005 if (subtype) |
| 1025 property.subtype = subtype; | 1006 property.subtype = subtype; |
| 1026 | 1007 |
| 1027 if (secondLevelKeys === null || secondLevelKeys) { | 1008 if (secondLevelKeys === null || secondLevelKeys) { |
| 1028 var subPreview = this._generatePreview(value, secondLevelKeys || undefined, undefined, isTable); | 1009 var subPreview = this._generatePreview(value, secondLevelKeys || undefined, undefined, isTable); |
| 1029 property.valuePreview = subPreview; | 1010 property.valuePreview = subPreview; |
| 1030 if (!subPreview.lossless) | |
| 1031 preview.lossless = false; | |
| 1032 if (subPreview.overflow) | 1011 if (subPreview.overflow) |
| 1033 preview.overflow = true; | 1012 preview.overflow = true; |
| 1034 } else { | 1013 } else { |
| 1035 var description = ""; | 1014 var description = ""; |
| 1036 if (type !== "function") | 1015 if (type !== "function") |
| 1037 description = this._abbreviateString(/** @type {string} */ ( injectedScript._describe(value)), maxLength, subtype === "regexp"); | 1016 description = this._abbreviateString(/** @type {string} */ ( injectedScript._describe(value)), maxLength, subtype === "regexp"); |
| 1038 property.value = description; | 1017 property.value = description; |
| 1039 preview.lossless = false; | |
| 1040 } | 1018 } |
| 1041 this._appendPropertyPreview(preview, property, propertiesThreshold); | 1019 this._appendPropertyPreview(preview, property, propertiesThreshold); |
| 1042 } | 1020 } |
| 1043 }, | 1021 }, |
| 1044 | 1022 |
| 1045 /** | 1023 /** |
| 1046 * @param {!RuntimeAgent.ObjectPreview} preview | 1024 * @param {!RuntimeAgent.ObjectPreview} preview |
| 1047 * @param {!Object} property | 1025 * @param {!Object} property |
| 1048 * @param {!Object} propertiesThreshold | 1026 * @param {!Object} propertiesThreshold |
| 1049 */ | 1027 */ |
| 1050 _appendPropertyPreview: function(preview, property, propertiesThreshold) | 1028 _appendPropertyPreview: function(preview, property, propertiesThreshold) |
| 1051 { | 1029 { |
| 1052 if (toString(property.name >>> 0) === property.name) | 1030 if (toString(property.name >>> 0) === property.name) |
| 1053 propertiesThreshold.indexes--; | 1031 propertiesThreshold.indexes--; |
| 1054 else | 1032 else |
| 1055 propertiesThreshold.properties--; | 1033 propertiesThreshold.properties--; |
| 1056 if (propertiesThreshold.indexes < 0 || propertiesThreshold.properties < 0) { | 1034 if (propertiesThreshold.indexes < 0 || propertiesThreshold.properties < 0) { |
| 1057 preview.overflow = true; | 1035 preview.overflow = true; |
| 1058 preview.lossless = false; | |
| 1059 } else { | 1036 } else { |
| 1060 push(preview.properties, property); | 1037 push(preview.properties, property); |
| 1061 } | 1038 } |
| 1062 }, | 1039 }, |
| 1063 | 1040 |
| 1064 /** | 1041 /** |
| 1065 * @param {!Object} object | 1042 * @param {!Object} object |
| 1066 * @param {!RuntimeAgent.ObjectPreview} preview | 1043 * @param {!RuntimeAgent.ObjectPreview} preview |
| 1067 * @param {boolean=} skipEntriesPreview | 1044 * @param {boolean=} skipEntriesPreview |
| 1068 */ | 1045 */ |
| 1069 _appendEntriesPreview: function(object, preview, skipEntriesPreview) | 1046 _appendEntriesPreview: function(object, preview, skipEntriesPreview) |
| 1070 { | 1047 { |
| 1071 var entries = InjectedScriptHost.collectionEntries(object); | 1048 var entries = InjectedScriptHost.collectionEntries(object); |
| 1072 if (!entries) | 1049 if (!entries) |
| 1073 return; | 1050 return; |
| 1074 if (skipEntriesPreview) { | 1051 if (skipEntriesPreview) { |
| 1075 if (entries.length) { | 1052 if (entries.length) { |
|
kozy
2016/05/10 00:04:42
please remove brackets
luoe
2016/05/10 17:27:45
Done.
| |
| 1076 preview.overflow = true; | 1053 preview.overflow = true; |
| 1077 preview.lossless = false; | |
| 1078 } | 1054 } |
| 1079 return; | 1055 return; |
| 1080 } | 1056 } |
| 1081 preview.entries = []; | 1057 preview.entries = []; |
| 1082 var entriesThreshold = 5; | 1058 var entriesThreshold = 5; |
| 1083 for (var i = 0; i < entries.length; ++i) { | 1059 for (var i = 0; i < entries.length; ++i) { |
| 1084 if (preview.entries.length >= entriesThreshold) { | 1060 if (preview.entries.length >= entriesThreshold) { |
| 1085 preview.overflow = true; | 1061 preview.overflow = true; |
| 1086 preview.lossless = false; | |
| 1087 break; | 1062 break; |
| 1088 } | 1063 } |
| 1089 var entry = nullifyObjectProto(entries[i]); | 1064 var entry = nullifyObjectProto(entries[i]); |
| 1090 var previewEntry = { | 1065 var previewEntry = { |
| 1091 value: generateValuePreview(entry.value), | 1066 value: generateValuePreview(entry.value), |
| 1092 __proto__: null | 1067 __proto__: null |
| 1093 }; | 1068 }; |
| 1094 if ("key" in entry) | 1069 if ("key" in entry) |
| 1095 previewEntry.key = generateValuePreview(entry.key); | 1070 previewEntry.key = generateValuePreview(entry.key); |
| 1096 push(preview.entries, previewEntry); | 1071 push(preview.entries, previewEntry); |
| 1097 } | 1072 } |
| 1098 | 1073 |
| 1099 /** | 1074 /** |
| 1100 * @param {*} value | 1075 * @param {*} value |
| 1101 * @return {!RuntimeAgent.ObjectPreview} | 1076 * @return {!RuntimeAgent.ObjectPreview} |
| 1102 */ | 1077 */ |
| 1103 function generateValuePreview(value) | 1078 function generateValuePreview(value) |
| 1104 { | 1079 { |
| 1105 var remoteObject = new InjectedScript.RemoteObject(value, undefined, true, undefined, true, undefined, undefined, true); | 1080 var remoteObject = new InjectedScript.RemoteObject(value, undefined, true, undefined, true, undefined, undefined, true); |
| 1106 var valuePreview = remoteObject.preview || remoteObject._createEmpty Preview(); | 1081 var valuePreview = remoteObject.preview || remoteObject._createEmpty Preview(); |
| 1107 if (!valuePreview.lossless) | |
| 1108 preview.lossless = false; | |
| 1109 return valuePreview; | 1082 return valuePreview; |
| 1110 } | 1083 } |
| 1111 }, | 1084 }, |
| 1112 | 1085 |
| 1113 /** | 1086 /** |
| 1114 * @param {string} string | 1087 * @param {string} string |
| 1115 * @param {number} maxLength | 1088 * @param {number} maxLength |
| 1116 * @param {boolean=} middle | 1089 * @param {boolean=} middle |
| 1117 * @return {string} | 1090 * @return {string} |
| 1118 */ | 1091 */ |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1300 /** | 1273 /** |
| 1301 * @param {!Event} event | 1274 * @param {!Event} event |
| 1302 */ | 1275 */ |
| 1303 CommandLineAPIImpl._logEvent = function(event) | 1276 CommandLineAPIImpl._logEvent = function(event) |
| 1304 { | 1277 { |
| 1305 inspectedGlobalObject.console.log(event.type, event); | 1278 inspectedGlobalObject.console.log(event.type, event); |
| 1306 } | 1279 } |
| 1307 | 1280 |
| 1308 return injectedScript; | 1281 return injectedScript; |
| 1309 }) | 1282 }) |
| OLD | NEW |