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

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

Powered by Google App Engine
This is Rietveld 408576698