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

Side by Side Diff: third_party/WebKit/Source/platform/v8_inspector/InjectedScriptSource.js

Issue 1963753003: DevTools: default all console object previews to lossy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added missing return Created 4 years, 7 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 | « third_party/WebKit/Source/devtools/protocol.json ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 824 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 this.objectId = injectedScript._bind(object, objectGroupName); 835 this.objectId = injectedScript._bind(object, objectGroupName);
836 var subtype = injectedScript._subtype(object); 836 var subtype = injectedScript._subtype(object);
837 if (subtype) 837 if (subtype)
838 this.subtype = subtype; 838 this.subtype = subtype;
839 var className = InjectedScriptHost.internalConstructorName(object); 839 var className = InjectedScriptHost.internalConstructorName(object);
840 if (className) 840 if (className)
841 this.className = className; 841 this.className = className;
842 this.description = injectedScript._describe(object); 842 this.description = injectedScript._describe(object);
843 843
844 if (generatePreview && this.type === "object") { 844 if (generatePreview && this.type === "object") {
845 if (this.subtype === "proxy") { 845 if (this.subtype === "proxy")
846 this.preview = this._generatePreview(InjectedScriptHost.proxyTargetV alue(object), undefined, columnNames, isTable, skipEntriesPreview); 846 this.preview = this._generatePreview(InjectedScriptHost.proxyTargetV alue(object), undefined, columnNames, isTable, skipEntriesPreview);
847 this.preview.lossless = false; 847 else if (this.subtype !== "node")
848 } else if (this.subtype !== "node") {
849 this.preview = this._generatePreview(object, undefined, columnNames, isTable, skipEntriesPreview); 848 this.preview = this._generatePreview(object, undefined, columnNames, isTable, skipEntriesPreview);
850 }
851 } 849 }
852 850
853 if (injectedScript._customObjectFormatterEnabled) { 851 if (injectedScript._customObjectFormatterEnabled) {
854 var customPreview = this._customPreview(object, objectGroupName, customO bjectConfig); 852 var customPreview = this._customPreview(object, objectGroupName, customO bjectConfig);
855 if (customPreview) 853 if (customPreview)
856 this.customPreview = customPreview; 854 this.customPreview = customPreview;
857 } 855 }
858 } 856 }
859 857
860 InjectedScript.RemoteObject.prototype = { 858 InjectedScript.RemoteObject.prototype = {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 }, 902 },
905 903
906 /** 904 /**
907 * @return {!RuntimeAgent.ObjectPreview} preview 905 * @return {!RuntimeAgent.ObjectPreview} preview
908 */ 906 */
909 _createEmptyPreview: function() 907 _createEmptyPreview: function()
910 { 908 {
911 var preview = { 909 var preview = {
912 type: /** @type {!RuntimeAgent.ObjectPreviewType.<string>} */ (this. type), 910 type: /** @type {!RuntimeAgent.ObjectPreviewType.<string>} */ (this. type),
913 description: this.description || toStringDescription(this.value), 911 description: this.description || toStringDescription(this.value),
914 lossless: true,
915 overflow: false, 912 overflow: false,
916 properties: [], 913 properties: [],
917 __proto__: null 914 __proto__: null
918 }; 915 };
919 if (this.subtype) 916 if (this.subtype)
920 preview.subtype = /** @type {!RuntimeAgent.ObjectPreviewSubtype.<str ing>} */ (this.subtype); 917 preview.subtype = /** @type {!RuntimeAgent.ObjectPreviewSubtype.<str ing>} */ (this.subtype);
921 return preview; 918 return preview;
922 }, 919 },
923 920
924 /** 921 /**
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
957 isOwn: true, 954 isOwn: true,
958 enumerable: true, 955 enumerable: true,
959 __proto__: null 956 __proto__: null
960 }); 957 });
961 } 958 }
962 this._appendPropertyDescriptors(preview, internalProperties, propert iesThreshold, secondLevelKeys, isTable); 959 this._appendPropertyDescriptors(preview, internalProperties, propert iesThreshold, secondLevelKeys, isTable);
963 960
964 if (this.subtype === "map" || this.subtype === "set" || this.subtype === "iterator") 961 if (this.subtype === "map" || this.subtype === "set" || this.subtype === "iterator")
965 this._appendEntriesPreview(object, preview, skipEntriesPreview); 962 this._appendEntriesPreview(object, preview, skipEntriesPreview);
966 963
967 } catch (e) { 964 } catch (e) {}
968 preview.lossless = false;
969 }
970 965
971 return preview; 966 return preview;
972 }, 967 },
973 968
974 /** 969 /**
975 * @param {!RuntimeAgent.ObjectPreview} preview 970 * @param {!RuntimeAgent.ObjectPreview} preview
976 * @param {!Array.<*>|!Iterable.<*>} descriptors 971 * @param {!Array.<*>|!Iterable.<*>} descriptors
977 * @param {!Object} propertiesThreshold 972 * @param {!Object} propertiesThreshold
978 * @param {?Array.<string>=} secondLevelKeys 973 * @param {?Array.<string>=} secondLevelKeys
979 * @param {boolean=} isTable 974 * @param {boolean=} isTable
980 */ 975 */
981 _appendPropertyDescriptors: function(preview, descriptors, propertiesThresho ld, secondLevelKeys, isTable) 976 _appendPropertyDescriptors: function(preview, descriptors, propertiesThresho ld, secondLevelKeys, isTable)
982 { 977 {
983 for (var descriptor of descriptors) { 978 for (var descriptor of descriptors) {
984 if (propertiesThreshold.indexes < 0 || propertiesThreshold.propertie s < 0) 979 if (propertiesThreshold.indexes < 0 || propertiesThreshold.propertie s < 0)
985 break; 980 break;
986 if (!descriptor) 981 if (!descriptor || descriptor.wasThrown)
987 continue; 982 continue;
988 if (descriptor.wasThrown) {
989 preview.lossless = false;
990 continue;
991 }
992 983
993 var name = descriptor.name; 984 var name = descriptor.name;
994 985
995 // Ignore __proto__ property, stay lossless. 986 // Ignore __proto__ property.
996 if (name === "__proto__") 987 if (name === "__proto__")
997 continue; 988 continue;
998 989
999 // Ignore non-enumerable members on prototype, stay lossless. 990 // Ignore length property of array.
1000 if (!descriptor.isOwn && !descriptor.enumerable)
1001 continue;
1002
1003 // Ignore length property of array, stay lossless.
1004 if (this.subtype === "array" && name === "length") 991 if (this.subtype === "array" && name === "length")
1005 continue; 992 continue;
1006 993
1007 // Ignore size property of map, set, stay lossless. 994 // Ignore size property of map, set.
1008 if ((this.subtype === "map" || this.subtype === "set") && name === " size") 995 if ((this.subtype === "map" || this.subtype === "set") && name === " size")
1009 continue; 996 continue;
1010 997
1011 // Never preview prototype properties, turn lossy. 998 // Never preview prototype properties.
1012 if (!descriptor.isOwn) { 999 if (!descriptor.isOwn)
1013 preview.lossless = false;
1014 continue; 1000 continue;
1015 }
1016 1001
1017 // Ignore computed properties, turn lossy. 1002 // Ignore computed properties.
1018 if (!("value" in descriptor)) { 1003 if (!("value" in descriptor))
1019 preview.lossless = false;
1020 continue; 1004 continue;
1021 }
1022 1005
1023 var value = descriptor.value; 1006 var value = descriptor.value;
1024 var type = typeof value; 1007 var type = typeof value;
1025 1008
1026 // Never render functions in object preview, turn lossy 1009 // Never render functions in object preview.
1027 if (type === "function" && (this.subtype !== "array" || !isUInt32(na me))) { 1010 if (type === "function" && (this.subtype !== "array" || !isUInt32(na me)))
1028 preview.lossless = false;
1029 continue; 1011 continue;
1030 }
1031 1012
1032 // Special-case HTMLAll. 1013 // Special-case HTMLAll.
1033 if (type === "undefined" && injectedScript._isHTMLAllCollection(valu e)) 1014 if (type === "undefined" && injectedScript._isHTMLAllCollection(valu e))
1034 type = "object"; 1015 type = "object";
1035 1016
1036 // Render own properties. 1017 // Render own properties.
1037 if (value === null) { 1018 if (value === null) {
1038 this._appendPropertyPreview(preview, { name: name, type: "object ", subtype: "null", value: "null", __proto__: null }, propertiesThreshold); 1019 this._appendPropertyPreview(preview, { name: name, type: "object ", subtype: "null", value: "null", __proto__: null }, propertiesThreshold);
1039 continue; 1020 continue;
1040 } 1021 }
1041 1022
1042 var maxLength = 100; 1023 var maxLength = 100;
1043 if (InjectedScript.primitiveTypes[type]) { 1024 if (InjectedScript.primitiveTypes[type]) {
1044 if (type === "string" && value.length > maxLength) { 1025 if (type === "string" && value.length > maxLength)
1045 value = this._abbreviateString(value, maxLength, true); 1026 value = this._abbreviateString(value, maxLength, true);
1046 preview.lossless = false;
1047 }
1048 this._appendPropertyPreview(preview, { name: name, type: type, v alue: toStringDescription(value), __proto__: null }, propertiesThreshold); 1027 this._appendPropertyPreview(preview, { name: name, type: type, v alue: toStringDescription(value), __proto__: null }, propertiesThreshold);
1049 continue; 1028 continue;
1050 } 1029 }
1051 1030
1052 var property = { name: name, type: type, __proto__: null }; 1031 var property = { name: name, type: type, __proto__: null };
1053 var subtype = injectedScript._subtype(value); 1032 var subtype = injectedScript._subtype(value);
1054 if (subtype) 1033 if (subtype)
1055 property.subtype = subtype; 1034 property.subtype = subtype;
1056 1035
1057 if (secondLevelKeys === null || secondLevelKeys) { 1036 if (secondLevelKeys === null || secondLevelKeys) {
1058 var subPreview = this._generatePreview(value, secondLevelKeys || undefined, undefined, isTable); 1037 var subPreview = this._generatePreview(value, secondLevelKeys || undefined, undefined, isTable);
1059 property.valuePreview = subPreview; 1038 property.valuePreview = subPreview;
1060 if (!subPreview.lossless)
1061 preview.lossless = false;
1062 if (subPreview.overflow) 1039 if (subPreview.overflow)
1063 preview.overflow = true; 1040 preview.overflow = true;
1064 } else { 1041 } else {
1065 var description = ""; 1042 var description = "";
1066 if (type !== "function") 1043 if (type !== "function")
1067 description = this._abbreviateString(/** @type {string} */ ( injectedScript._describe(value)), maxLength, subtype === "regexp"); 1044 description = this._abbreviateString(/** @type {string} */ ( injectedScript._describe(value)), maxLength, subtype === "regexp");
1068 property.value = description; 1045 property.value = description;
1069 preview.lossless = false;
1070 } 1046 }
1071 this._appendPropertyPreview(preview, property, propertiesThreshold); 1047 this._appendPropertyPreview(preview, property, propertiesThreshold);
1072 } 1048 }
1073 }, 1049 },
1074 1050
1075 /** 1051 /**
1076 * @param {!RuntimeAgent.ObjectPreview} preview 1052 * @param {!RuntimeAgent.ObjectPreview} preview
1077 * @param {!Object} property 1053 * @param {!Object} property
1078 * @param {!Object} propertiesThreshold 1054 * @param {!Object} propertiesThreshold
1079 */ 1055 */
1080 _appendPropertyPreview: function(preview, property, propertiesThreshold) 1056 _appendPropertyPreview: function(preview, property, propertiesThreshold)
1081 { 1057 {
1082 if (toString(property.name >>> 0) === property.name) 1058 if (toString(property.name >>> 0) === property.name)
1083 propertiesThreshold.indexes--; 1059 propertiesThreshold.indexes--;
1084 else 1060 else
1085 propertiesThreshold.properties--; 1061 propertiesThreshold.properties--;
1086 if (propertiesThreshold.indexes < 0 || propertiesThreshold.properties < 0) { 1062 if (propertiesThreshold.indexes < 0 || propertiesThreshold.properties < 0) {
1087 preview.overflow = true; 1063 preview.overflow = true;
1088 preview.lossless = false;
1089 } else { 1064 } else {
1090 push(preview.properties, property); 1065 push(preview.properties, property);
1091 } 1066 }
1092 }, 1067 },
1093 1068
1094 /** 1069 /**
1095 * @param {!Object} object 1070 * @param {!Object} object
1096 * @param {!RuntimeAgent.ObjectPreview} preview 1071 * @param {!RuntimeAgent.ObjectPreview} preview
1097 * @param {boolean=} skipEntriesPreview 1072 * @param {boolean=} skipEntriesPreview
1098 */ 1073 */
1099 _appendEntriesPreview: function(object, preview, skipEntriesPreview) 1074 _appendEntriesPreview: function(object, preview, skipEntriesPreview)
1100 { 1075 {
1101 var entries = InjectedScriptHost.collectionEntries(object); 1076 var entries = InjectedScriptHost.collectionEntries(object);
1102 if (!entries) 1077 if (!entries)
1103 return; 1078 return;
1104 if (skipEntriesPreview) { 1079 if (skipEntriesPreview) {
1105 if (entries.length) { 1080 if (entries.length)
1106 preview.overflow = true; 1081 preview.overflow = true;
1107 preview.lossless = false;
1108 }
1109 return; 1082 return;
1110 } 1083 }
1111 preview.entries = []; 1084 preview.entries = [];
1112 var entriesThreshold = 5; 1085 var entriesThreshold = 5;
1113 for (var i = 0; i < entries.length; ++i) { 1086 for (var i = 0; i < entries.length; ++i) {
1114 if (preview.entries.length >= entriesThreshold) { 1087 if (preview.entries.length >= entriesThreshold) {
1115 preview.overflow = true; 1088 preview.overflow = true;
1116 preview.lossless = false;
1117 break; 1089 break;
1118 } 1090 }
1119 var entry = nullifyObjectProto(entries[i]); 1091 var entry = nullifyObjectProto(entries[i]);
1120 var previewEntry = { 1092 var previewEntry = {
1121 value: generateValuePreview(entry.value), 1093 value: generateValuePreview(entry.value),
1122 __proto__: null 1094 __proto__: null
1123 }; 1095 };
1124 if ("key" in entry) 1096 if ("key" in entry)
1125 previewEntry.key = generateValuePreview(entry.key); 1097 previewEntry.key = generateValuePreview(entry.key);
1126 push(preview.entries, previewEntry); 1098 push(preview.entries, previewEntry);
1127 } 1099 }
1128 1100
1129 /** 1101 /**
1130 * @param {*} value 1102 * @param {*} value
1131 * @return {!RuntimeAgent.ObjectPreview} 1103 * @return {!RuntimeAgent.ObjectPreview}
1132 */ 1104 */
1133 function generateValuePreview(value) 1105 function generateValuePreview(value)
1134 { 1106 {
1135 var remoteObject = new InjectedScript.RemoteObject(value, undefined, true, undefined, true, undefined, undefined, true); 1107 var remoteObject = new InjectedScript.RemoteObject(value, undefined, true, undefined, true, undefined, undefined, true);
1136 var valuePreview = remoteObject.preview || remoteObject._createEmpty Preview(); 1108 var valuePreview = remoteObject.preview || remoteObject._createEmpty Preview();
1137 if (!valuePreview.lossless)
1138 preview.lossless = false;
1139 return valuePreview; 1109 return valuePreview;
1140 } 1110 }
1141 }, 1111 },
1142 1112
1143 /** 1113 /**
1144 * @param {string} string 1114 * @param {string} string
1145 * @param {number} maxLength 1115 * @param {number} maxLength
1146 * @param {boolean=} middle 1116 * @param {boolean=} middle
1147 * @return {string} 1117 * @return {string}
1148 */ 1118 */
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
1330 /** 1300 /**
1331 * @param {!Event} event 1301 * @param {!Event} event
1332 */ 1302 */
1333 CommandLineAPIImpl._logEvent = function(event) 1303 CommandLineAPIImpl._logEvent = function(event)
1334 { 1304 {
1335 inspectedGlobalObject.console.log(event.type, event); 1305 inspectedGlobalObject.console.log(event.type, event);
1336 } 1306 }
1337 1307
1338 return injectedScript; 1308 return injectedScript;
1339 }) 1309 })
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/devtools/protocol.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698