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

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

Issue 2012033002: DevTools: more previews when formatting logged arrays/objects (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code cleanup Created 4 years, 6 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/front_end/sources/ScopeChainSidebarPane.js ('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 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 getProperties: function(object, objectGroupName, ownProperties, accessorProp ertiesOnly, generatePreview) 339 getProperties: function(object, objectGroupName, ownProperties, accessorProp ertiesOnly, generatePreview)
340 { 340 {
341 var descriptors = []; 341 var descriptors = [];
342 var iter = this._propertyDescriptors(object, ownProperties, accessorProp ertiesOnly, undefined); 342 var iter = this._propertyDescriptors(object, ownProperties, accessorProp ertiesOnly, undefined);
343 // Go over properties, wrap object values. 343 // Go over properties, wrap object values.
344 for (var descriptor of iter) { 344 for (var descriptor of iter) {
345 if ("get" in descriptor) 345 if ("get" in descriptor)
346 descriptor.get = this._wrapObject(descriptor.get, objectGroupNam e); 346 descriptor.get = this._wrapObject(descriptor.get, objectGroupNam e);
347 if ("set" in descriptor) 347 if ("set" in descriptor)
348 descriptor.set = this._wrapObject(descriptor.set, objectGroupNam e); 348 descriptor.set = this._wrapObject(descriptor.set, objectGroupNam e);
349 if ("value" in descriptor) 349 if ("value" in descriptor) {
350 generatePreview = descriptor.name !== "__proto__";
dgozman 2016/06/14 09:08:30 I don't get this change.
luoe 2016/06/14 17:49:29 In another place, I changed a call to getPropertie
350 descriptor.value = this._wrapObject(descriptor.value, objectGrou pName, false, generatePreview); 351 descriptor.value = this._wrapObject(descriptor.value, objectGrou pName, false, generatePreview);
352 }
351 if (!("configurable" in descriptor)) 353 if (!("configurable" in descriptor))
352 descriptor.configurable = false; 354 descriptor.configurable = false;
353 if (!("enumerable" in descriptor)) 355 if (!("enumerable" in descriptor))
354 descriptor.enumerable = false; 356 descriptor.enumerable = false;
355 if ("symbol" in descriptor) 357 if ("symbol" in descriptor)
356 descriptor.symbol = this._wrapObject(descriptor.symbol, objectGr oupName); 358 descriptor.symbol = this._wrapObject(descriptor.symbol, objectGr oupName);
357 push(descriptors, descriptor); 359 push(descriptors, descriptor);
358 } 360 }
359 return descriptors; 361 return descriptors;
360 }, 362 },
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 * @return {!RuntimeAgent.ObjectPreview} preview 804 * @return {!RuntimeAgent.ObjectPreview} preview
803 */ 805 */
804 _generatePreview: function(object, firstLevelKeys, secondLevelKeys, isTable, skipEntriesPreview) 806 _generatePreview: function(object, firstLevelKeys, secondLevelKeys, isTable, skipEntriesPreview)
805 { 807 {
806 var preview = this._createEmptyPreview(); 808 var preview = this._createEmptyPreview();
807 var firstLevelKeysCount = firstLevelKeys ? firstLevelKeys.length : 0; 809 var firstLevelKeysCount = firstLevelKeys ? firstLevelKeys.length : 0;
808 810
809 var propertiesThreshold = { 811 var propertiesThreshold = {
810 properties: isTable ? 1000 : max(5, firstLevelKeysCount), 812 properties: isTable ? 1000 : max(5, firstLevelKeysCount),
811 indexes: isTable ? 1000 : max(100, firstLevelKeysCount), 813 indexes: isTable ? 1000 : max(100, firstLevelKeysCount),
814 characters: isTable ? Infinity : 120,
815 abbreviatedTextLength: isTable ? Infinity : 40,
812 __proto__: null 816 __proto__: null
813 }; 817 };
814 818
815 try { 819 try {
816 var descriptors = injectedScript._propertyDescriptors(object, undefi ned, undefined, firstLevelKeys); 820 var descriptors = injectedScript._propertyDescriptors(object, undefi ned, undefined, firstLevelKeys);
817 821
818 this._appendPropertyDescriptors(preview, descriptors, propertiesThre shold, secondLevelKeys, isTable); 822 this._appendPropertyDescriptors(preview, descriptors, propertiesThre shold, secondLevelKeys, isTable);
819 if (propertiesThreshold.indexes < 0 || propertiesThreshold.propertie s < 0) 823 if (propertiesThreshold.indexes < 0 || propertiesThreshold.propertie s < 0 || propertiesThreshold.characters < 0)
820 return preview; 824 return preview;
821 825
822 // Add internal properties to preview. 826 // Add internal properties to preview.
823 var rawInternalProperties = InjectedScriptHost.getInternalProperties (object) || []; 827 var rawInternalProperties = InjectedScriptHost.getInternalProperties (object) || [];
824 var internalProperties = []; 828 var internalProperties = [];
825 for (var i = 0; i < rawInternalProperties.length; i += 2) { 829 for (var i = 0; i < rawInternalProperties.length; i += 2) {
826 push(internalProperties, { 830 push(internalProperties, {
827 name: rawInternalProperties[i], 831 name: rawInternalProperties[i],
828 value: rawInternalProperties[i + 1], 832 value: rawInternalProperties[i + 1],
829 isOwn: true, 833 isOwn: true,
830 enumerable: true, 834 enumerable: true,
831 __proto__: null 835 __proto__: null
832 }); 836 });
833 } 837 }
834 this._appendPropertyDescriptors(preview, internalProperties, propert iesThreshold, secondLevelKeys, isTable); 838 this._appendPropertyDescriptors(preview, internalProperties, propert iesThreshold, secondLevelKeys, isTable);
835 839
836 if (this.subtype === "map" || this.subtype === "set" || this.subtype === "iterator") 840 if (this.subtype === "map" || this.subtype === "set" || this.subtype === "iterator")
837 this._appendEntriesPreview(object, preview, skipEntriesPreview); 841 this._appendEntriesPreview(object, preview, skipEntriesPreview);
838 842
839 } catch (e) {} 843 } catch (e) {}
840 844
841 return preview; 845 return preview;
842 }, 846 },
843 847
844 /** 848 /**
849 * @param {*} value
850 * @return {!RuntimeAgent.ObjectPreview}
851 */
852 _generateSubPreview: function(value)
853 {
854 var remoteObject = new InjectedScript.RemoteObject(value, undefined, tru e, undefined, true, undefined, undefined, true);
855 var valuePreview = remoteObject.preview || remoteObject._createEmptyPrev iew();
856 return valuePreview;
857 },
858
859 /**
845 * @param {!RuntimeAgent.ObjectPreview} preview 860 * @param {!RuntimeAgent.ObjectPreview} preview
846 * @param {!Array.<*>|!Iterable.<*>} descriptors 861 * @param {!Array.<*>|!Iterable.<*>} descriptors
847 * @param {!Object} propertiesThreshold 862 * @param {!Object} propertiesThreshold
848 * @param {?Array.<string>=} secondLevelKeys 863 * @param {?Array.<string>=} secondLevelKeys
849 * @param {boolean=} isTable 864 * @param {boolean=} isTable
850 */ 865 */
851 _appendPropertyDescriptors: function(preview, descriptors, propertiesThresho ld, secondLevelKeys, isTable) 866 _appendPropertyDescriptors: function(preview, descriptors, propertiesThresho ld, secondLevelKeys, isTable)
852 { 867 {
853 for (var descriptor of descriptors) { 868 for (var descriptor of descriptors) {
854 if (propertiesThreshold.indexes < 0 || propertiesThreshold.propertie s < 0) 869 if (propertiesThreshold.indexes < 0 || propertiesThreshold.propertie s < 0)
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 // Special-case HTMLAll. 903 // Special-case HTMLAll.
889 if (type === "undefined" && injectedScript._isHTMLAllCollection(valu e)) 904 if (type === "undefined" && injectedScript._isHTMLAllCollection(valu e))
890 type = "object"; 905 type = "object";
891 906
892 // Render own properties. 907 // Render own properties.
893 if (value === null) { 908 if (value === null) {
894 this._appendPropertyPreview(preview, { name: name, type: "object ", subtype: "null", value: "null", __proto__: null }, propertiesThreshold); 909 this._appendPropertyPreview(preview, { name: name, type: "object ", subtype: "null", value: "null", __proto__: null }, propertiesThreshold);
895 continue; 910 continue;
896 } 911 }
897 912
898 var maxLength = 100;
899 if (InjectedScript.primitiveTypes[type]) { 913 if (InjectedScript.primitiveTypes[type]) {
900 if (type === "string" && value.length > maxLength) 914 if (type === "string" && value.length > propertiesThreshold.abbr eviatedTextLength)
901 value = this._abbreviateString(value, maxLength, true); 915 value = this._abbreviateString(value, Math.min(propertiesThr eshold.characters, propertiesThreshold.abbreviatedTextLength), true);
902 this._appendPropertyPreview(preview, { name: name, type: type, v alue: toStringDescription(value), __proto__: null }, propertiesThreshold); 916 this._appendPropertyPreview(preview, { name: name, type: type, v alue: toStringDescription(value), __proto__: null }, propertiesThreshold);
903 continue; 917 continue;
904 } 918 }
905 919
906 var property = { name: name, type: type, __proto__: null }; 920 var property = { name: name, type: type, __proto__: null };
907 var subtype = injectedScript._subtype(value); 921 var subtype = injectedScript._subtype(value);
908 if (subtype) 922 if (subtype)
909 property.subtype = subtype; 923 property.subtype = subtype;
910 924
911 if (secondLevelKeys === null || secondLevelKeys) { 925 if (secondLevelKeys === null || secondLevelKeys) {
912 var subPreview = this._generatePreview(value, secondLevelKeys || undefined, undefined, isTable); 926 var subPreview = this._generatePreview(value, secondLevelKeys || undefined, undefined, isTable);
913 property.valuePreview = subPreview; 927 property.valuePreview = subPreview;
914 if (subPreview.overflow) 928 } else if ((preview.subtype === "array" || subtype === "array") && s ubtype !== "node") {
915 preview.overflow = true; 929 var subPreview = this._generateSubPreview(value);
930 property.valuePreview = subPreview;
916 } else { 931 } else {
917 var description = ""; 932 var description = "";
918 if (type !== "function") 933 if (type !== "function")
919 description = this._abbreviateString(/** @type {string} */ ( injectedScript._describe(value)), maxLength, subtype === "regexp"); 934 description = this._abbreviateString(/** @type {string} */ ( injectedScript._describe(value)), propertiesThreshold.characters, subtype === "r egexp");
920 property.value = description; 935 property.value = description;
921 } 936 }
922 this._appendPropertyPreview(preview, property, propertiesThreshold); 937 this._appendPropertyPreview(preview, property, propertiesThreshold);
923 } 938 }
924 }, 939 },
925 940
926 /** 941 /**
927 * @param {!RuntimeAgent.ObjectPreview} preview 942 * @param {!RuntimeAgent.ObjectPreview} preview
928 * @param {!Object} property 943 * @param {!Object} property
929 * @param {!Object} propertiesThreshold 944 * @param {!Object} propertiesThreshold
930 */ 945 */
931 _appendPropertyPreview: function(preview, property, propertiesThreshold) 946 _appendPropertyPreview: function(preview, property, propertiesThreshold)
932 { 947 {
948 // Before updating indexes or properties, make sure we have enough chara cters to continue appending
949 if (propertiesThreshold.characters <= 0) {
950 preview.overflow = true;
951 return;
952 }
953
954 // If the property name is a number
933 if (toString(property.name >>> 0) === property.name) 955 if (toString(property.name >>> 0) === property.name)
934 propertiesThreshold.indexes--; 956 propertiesThreshold.indexes--;
935 else 957 else {
936 propertiesThreshold.properties--; 958 propertiesThreshold.properties--;
959 // Only objects have keynames displayed in previews
960 propertiesThreshold.characters -= property.name.length;
961 }
962 if (property.value)
963 propertiesThreshold.characters -= property.value.length;
964 else if (property.valuePreview) {
965 var minLength = property.description ? property.description.length : 0;
966 if (property.valuePreview.description && property.valuePreview.descr iption.length < minLength)
967 minLength = property.valuePreview.description.length;
968 if (preview.subtype === "array")
969 minLength = estimatePropertyPreviewLength(property);
970
971 propertiesThreshold.characters -= minLength;
972 }
973
974
975 // if (propertiesThreshold.indexes < 0 || propertiesThreshold.properties < 0 || propertiesThreshold.characters < 0) {
937 if (propertiesThreshold.indexes < 0 || propertiesThreshold.properties < 0) { 976 if (propertiesThreshold.indexes < 0 || propertiesThreshold.properties < 0) {
938 preview.overflow = true; 977 preview.overflow = true;
978 push(preview.properties, property);
939 } else { 979 } else {
940 push(preview.properties, property); 980 push(preview.properties, property);
941 } 981 }
982
983 function estimatePropertyPreviewLength(property)
984 {
985 if (!property) {
986 return 0;
987 } else if (property.value) {
988 return property.name.length + property.value.length;
989 } else if (property.valuePreview && property.valuePreview.properties .length) {
990 var valuePreviewPropertyLengths = property.valuePreview.properti es.map((prop) => estimatePropertyPreviewLength(prop));
991 var valuePreviewLength = valuePreviewPropertyLengths.reduce((a, b) => a + b, 0);
992 return property.name.length + ": ".length + valuePreviewLength + 2;
993 } else if (property.description) {
994 return property.description.length;
995 } else {
996 return 0;
997 }
998 }
942 }, 999 },
943 1000
944 /** 1001 /**
945 * @param {!Object} object 1002 * @param {!Object} object
946 * @param {!RuntimeAgent.ObjectPreview} preview 1003 * @param {!RuntimeAgent.ObjectPreview} preview
947 * @param {boolean=} skipEntriesPreview 1004 * @param {boolean=} skipEntriesPreview
948 */ 1005 */
949 _appendEntriesPreview: function(object, preview, skipEntriesPreview) 1006 _appendEntriesPreview: function(object, preview, skipEntriesPreview)
950 { 1007 {
951 var entries = InjectedScriptHost.collectionEntries(object); 1008 var entries = InjectedScriptHost.collectionEntries(object);
952 if (!entries) 1009 if (!entries)
953 return; 1010 return;
954 if (skipEntriesPreview) { 1011 if (skipEntriesPreview) {
955 if (entries.length) 1012 if (entries.length)
956 preview.overflow = true; 1013 preview.overflow = true;
957 return; 1014 return;
958 } 1015 }
959 preview.entries = []; 1016 preview.entries = [];
960 var entriesThreshold = 5; 1017 var entriesThreshold = 5;
961 for (var i = 0; i < entries.length; ++i) { 1018 for (var i = 0; i < entries.length; ++i) {
962 if (preview.entries.length >= entriesThreshold) { 1019 if (preview.entries.length >= entriesThreshold) {
963 preview.overflow = true; 1020 preview.overflow = true;
964 break; 1021 break;
965 } 1022 }
966 var entry = nullifyObjectProto(entries[i]); 1023 var entry = nullifyObjectProto(entries[i]);
967 var previewEntry = { 1024 var previewEntry = {
968 value: generateValuePreview(entry.value), 1025 value: this._generateSubPreview(entry.value),
969 __proto__: null 1026 __proto__: null
970 }; 1027 };
971 if ("key" in entry) 1028 if ("key" in entry)
972 previewEntry.key = generateValuePreview(entry.key); 1029 previewEntry.key = this._generateSubPreview(entry.key);
973 push(preview.entries, previewEntry); 1030 push(preview.entries, previewEntry);
974 } 1031 }
975
976 /**
977 * @param {*} value
978 * @return {!RuntimeAgent.ObjectPreview}
979 */
980 function generateValuePreview(value)
981 {
982 var remoteObject = new InjectedScript.RemoteObject(value, undefined, true, undefined, true, undefined, undefined, true);
983 var valuePreview = remoteObject.preview || remoteObject._createEmpty Preview();
984 return valuePreview;
985 }
986 }, 1032 },
987 1033
988 /** 1034 /**
989 * @param {string} string 1035 * @param {string} string
990 * @param {number} maxLength 1036 * @param {number} maxLength
991 * @param {boolean=} middle 1037 * @param {boolean=} middle
992 * @return {string} 1038 * @return {string}
993 */ 1039 */
994 _abbreviateString: function(string, maxLength, middle) 1040 _abbreviateString: function(string, maxLength, middle)
995 { 1041 {
996 if (string.length <= maxLength) 1042 if (string.length <= maxLength)
997 return string; 1043 return string;
998 if (middle) { 1044 if (middle) {
999 var leftHalf = maxLength >> 1; 1045 var leftHalf = maxLength >> 1;
1000 var rightHalf = maxLength - leftHalf - 1; 1046 var rightHalf = maxLength - leftHalf - 1;
1001 return string.substr(0, leftHalf) + "\u2026" + string.substr(string. length - rightHalf, rightHalf); 1047 return string.substr(0, leftHalf) + "\u2026" + string.substr(string. length - rightHalf, rightHalf);
1002 } 1048 }
1003 return string.substr(0, maxLength) + "\u2026"; 1049 return string.substr(0, maxLength) + "\u2026";
1004 }, 1050 },
1005 1051
1006 __proto__: null 1052 __proto__: null
1007 } 1053 }
1008 1054
1009 return injectedScript; 1055 return injectedScript;
1010 }) 1056 })
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/sources/ScopeChainSidebarPane.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698