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

Side by Side Diff: Source/devtools/front_end/sdk/RemoteObject.js

Issue 512003003: DevTools: Show preview in console of ES6 Map, Set, WeakMap and WeakSet entries. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: fix LocalJSON object description Created 6 years, 3 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 WebInspector.LocalJSONObject.prototype = { 860 WebInspector.LocalJSONObject.prototype = {
861 /** 861 /**
862 * @return {string} 862 * @return {string}
863 */ 863 */
864 get description() 864 get description()
865 { 865 {
866 if (this._cachedDescription) 866 if (this._cachedDescription)
867 return this._cachedDescription; 867 return this._cachedDescription;
868 868
869 /** 869 /**
870 * @param {!WebInspector.RemoteObjectProperty} property 870 * @param {?WebInspector.RemoteObject} value
871 * @return {string}
871 */ 872 */
872 function formatArrayItem(property) 873 function formatValue(value)
873 { 874 {
874 return property.value.description; 875 if (!value)
876 return "undefined";
877 var description = value.description || "";
878 if (value.type === "string")
879 return "\"" + description.replace(/\n/g, "\u21B5") + "\"";
880 return description;
875 } 881 }
876 882
877 /** 883 /**
878 * @param {!WebInspector.RemoteObjectProperty} property 884 * @param {!WebInspector.RemoteObjectProperty} property
885 * @return {string}
886 */
887 function formatArrayItem(property)
888 {
889 return formatValue(property.value);
890 }
891
892 /**
893 * @param {!WebInspector.RemoteObjectProperty} property
894 * @return {string}
879 */ 895 */
880 function formatObjectItem(property) 896 function formatObjectItem(property)
881 { 897 {
882 return property.name + ":" + property.value.description; 898 var name = property.name;
899 if (/^\s|\s$|^$|\n/.test(name))
900 name = "\"" + name.replace(/\n/g, "\u21B5") + "\"";
yurys 2014/09/14 12:42:03 Shouldn't we always show the name quoted? It may b
aandrey 2014/09/15 06:51:57 There is quite a few places where we do this. The
901 return name + ": " + formatValue(property.value);
883 } 902 }
884 903
885 if (this.type === "object") { 904 var children = this._children();
905 if (children.length === 2 && children[0].name === "key" && children[1].n ame === "value") {
906 this._cachedDescription = "{" + formatValue(children[0].value) + " = > " + formatValue(children[1].value) + "}";
yurys 2014/09/14 12:42:03 Should this go under case "map" below?
aandrey 2014/09/15 06:51:57 This is a map entry, simulated by a local RemoteOb
907 } else if (this.type === "object") {
886 switch (this.subtype) { 908 switch (this.subtype) {
887 case "array": 909 case "array":
888 this._cachedDescription = this._concatenate("[", "]", formatArra yItem); 910 this._cachedDescription = this._concatenate("[", "]", formatArra yItem);
889 break; 911 break;
890 case "date": 912 case "date":
891 this._cachedDescription = "" + this._value; 913 this._cachedDescription = "" + this._value;
892 break; 914 break;
893 case "null": 915 case "null":
894 this._cachedDescription = "null"; 916 this._cachedDescription = "null";
895 break; 917 break;
896 default: 918 default:
897 this._cachedDescription = this._concatenate("{", "}", formatObje ctItem); 919 this._cachedDescription = this._concatenate("{", "}", formatObje ctItem);
898 } 920 }
899 } else 921 } else {
900 this._cachedDescription = String(this._value); 922 this._cachedDescription = String(this._value);
923 }
901 924
902 return this._cachedDescription; 925 return this._cachedDescription;
903 }, 926 },
904 927
905 /** 928 /**
906 * @param {string} prefix 929 * @param {string} prefix
907 * @param {string} suffix 930 * @param {string} suffix
908 * @param {function (!WebInspector.RemoteObjectProperty)} formatProperty 931 * @param {function (!WebInspector.RemoteObjectProperty)} formatProperty
909 * @return {string} 932 * @return {string}
910 */ 933 */
911 _concatenate: function(prefix, suffix, formatProperty) 934 _concatenate: function(prefix, suffix, formatProperty)
912 { 935 {
913 const previewChars = 100; 936 var previewChars = 100;
914 937
915 var buffer = prefix; 938 var buffer = prefix;
916 var children = this._children(); 939 var children = this._children();
917 for (var i = 0; i < children.length; ++i) { 940 for (var i = 0; i < children.length; ++i) {
918 var itemDescription = formatProperty(children[i]); 941 var itemDescription = formatProperty(children[i]);
919 if (buffer.length + itemDescription.length > previewChars) { 942 if (buffer.length + itemDescription.length > previewChars) {
920 buffer += ",\u2026"; 943 buffer += ",\u2026";
921 break; 944 break;
922 } 945 }
923 if (i) 946 if (i)
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1062 result = functionDeclaration.apply(target, rawArgs); 1085 result = functionDeclaration.apply(target, rawArgs);
1063 } catch (e) { 1086 } catch (e) {
1064 result = null; 1087 result = null;
1065 } 1088 }
1066 1089
1067 callback(result); 1090 callback(result);
1068 }, 1091 },
1069 1092
1070 __proto__: WebInspector.RemoteObject.prototype 1093 __proto__: WebInspector.RemoteObject.prototype
1071 } 1094 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698