Changeset 30146 in webkit
- Timestamp:
- Feb 11, 2008 11:58:18 AM (16 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r30145 r30146 1 2008-02-11 Adam Roben <aroben@apple.com> 2 3 Fix Bug 14316: Inspector's Console truncates long strings 4 5 <http://bugs.webkit.org/show_bug.cgi?id=14316> 6 <rdar://5357695> 7 8 We no longer call Object.describe to format all the output of commands 9 enetered into the Console. The ConsolePanel object now has a set of 10 formatting functions that append a formatted representation of the 11 passed-in object to the passed-in container node. 12 13 Reviewed by Sam. 14 15 * page/inspector/ConsolePanel.js: 16 (WebInspector.ConsolePanel._onEnterPressed): Updated for rename of 17 _outputToNode to _format. 18 (WebInspector.ConsolePanel._format): Renamed from _outputToNode. Use 19 Object.type to get the type of the object, then call the appropriate 20 formatting function. 21 (WebInspector.ConsolePanel._formatvalue): Added. 22 (WebInspector.ConsolePanel._formatstring): Added. This function 23 contains the actual fix for the bug, since it doesn't truncate the 24 string no matter how long it is. 25 (WebInspector.ConsolePanel._formatregexp): Added. 26 (WebInspector.ConsolePanel._formatarray): Added. This is a bit more 27 functional than Object.describe for arrays, since it recursively 28 formats each item in the array. One advantage of this is that Nodes in 29 arrays will be linkified instead of just turning into "[Object 30 HTMLBodyElement]" or similar. 31 (WebInspector.ConsolePanel._formatnode): Added. 32 (WebInspector.ConsolePanel._formatobject): Added. 33 (WebInspector.ConsolePanel. 34 * page/inspector/utilities.js: 35 (Object.type): Added. Code was pulled out of Object.describe and 36 reorganized slightly. 37 (Object.describe): Call Object.type. There should be no change in 38 behavior of this function. 39 1 40 2008-02-11 Alp Toker <alp@atoker.com> 2 41 -
trunk/WebCore/page/inspector/ConsolePanel.js
r28918 r30146 184 184 var level = exception ? WebInspector.ConsoleMessage.MessageLevel.Error : WebInspector.ConsoleMessage.MessageLevel.Log; 185 185 186 this.addMessage(new WebInspector.ConsoleCommand(str, this._ outputToNode(result)));186 this.addMessage(new WebInspector.ConsoleCommand(str, this._format(result))); 187 187 }, 188 188 … … 224 224 }, 225 225 226 _outputToNode: function(output) 227 { 228 if (output instanceof Node) { 229 var anchor = document.createElement("a"); 230 anchor.innerHTML = output.titleInfo().title; 231 anchor.representedNode = output; 232 return anchor; 233 } 234 return document.createTextNode(Object.describe(output)); 235 } 226 _format: function(output) 227 { 228 var type = Object.type(output); 229 if (type === "object") { 230 if (output instanceof Node) 231 type = "node"; 232 } 233 234 // We don't perform any special formatting on these types, so we just 235 // pass them through the simple _formatvalue function. 236 var undecoratedTypes = { 237 "undefined": 1, 238 "null": 1, 239 "boolean": 1, 240 "number": 1, 241 "date": 1, 242 "function": 1, 243 }; 244 245 var formatter; 246 if (type in undecoratedTypes) 247 formatter = "_formatvalue"; 248 else { 249 formatter = "_format" + type; 250 if (!(formatter in this)) { 251 formatter = "_formatobject"; 252 type = "object"; 253 } 254 } 255 256 var span = document.createElement("span"); 257 span.addStyleClass("console-formatted-" + type); 258 this[formatter](output, span); 259 return span; 260 }, 261 262 _formatvalue: function(val, elem) 263 { 264 elem.appendChild(document.createTextNode(val)); 265 }, 266 267 _formatstring: function(str, elem) 268 { 269 elem.appendChild(document.createTextNode("\"" + str + "\"")); 270 }, 271 272 _formatregexp: function(re, elem) 273 { 274 var formatted = String(re).replace(/([\\\/])/g, "\\$1").replace(/\\(\/[gim]*)$/, "$1").substring(1); 275 elem.appendChild(document.createTextNode(formatted)); 276 }, 277 278 _formatarray: function(arr, elem) 279 { 280 elem.appendChild(document.createTextNode("[")); 281 for (var i = 0; i < arr.length; ++i) { 282 elem.appendChild(this._format(arr[i])); 283 if (i < arr.length - 1) 284 elem.appendChild(document.createTextNode(", ")); 285 } 286 elem.appendChild(document.createTextNode("]")); 287 }, 288 289 _formatnode: function(node, elem) 290 { 291 var anchor = document.createElement("a"); 292 anchor.innerHTML = node.titleInfo().title; 293 anchor.representedNode = node; 294 elem.appendChild(anchor); 295 }, 296 297 _formatobject: function(obj, elem) 298 { 299 elem.appendChild(document.createTextNode(Object.describe(obj))); 300 }, 236 301 } 237 302 -
trunk/WebCore/page/inspector/utilities.js
r28004 r30146 27 27 */ 28 28 29 Object.describe = function(obj, abbreviated) 30 { 31 if (obj === undefined) 32 return "undefined"; 29 Object.type = function(obj) 30 { 33 31 if (obj === null) 34 32 return "null"; 35 33 36 var type1 = typeof obj; 37 var type2 = ""; 38 if (type1 == "object" || type1 == "function") { 39 if (obj instanceof String) 40 type1 = "string"; 41 else if (obj instanceof Array) 42 type1 = "array"; 43 else if (obj instanceof Boolean) 44 type1 = "boolean"; 45 else if (obj instanceof Number) 46 type1 = "number"; 47 else if (obj instanceof Date) 48 type1 = "date"; 49 else if (obj instanceof RegExp) 50 type1 = "regexp"; 51 else if (obj instanceof Error) 52 type1 = "error"; 53 type2 = Object.prototype.toString.call(obj).replace(/^\[object (.*)\]$/i, "$1"); 54 } 55 56 switch (type1) { 34 var type = typeof obj; 35 if (type !== "object" && type !== "function") 36 return type; 37 38 if (obj instanceof String) 39 return "string"; 40 if (obj instanceof Array) 41 return "array"; 42 if (obj instanceof Boolean) 43 return "boolean"; 44 if (obj instanceof Number) 45 return "number"; 46 if (obj instanceof Date) 47 return "date"; 48 if (obj instanceof RegExp) 49 return "regexp"; 50 if (obj instanceof Error) 51 return "error"; 52 return type; 53 } 54 55 Object.describe = function(obj, abbreviated) 56 { 57 switch (Object.type(obj)) { 57 58 case "object": 58 return type2;59 return Object.prototype.toString.call(obj).replace(/^\[object (.*)\]$/i, "$1"); 59 60 case "array": 60 61 return "[" + obj.toString() + "]";
Note: See TracChangeset
for help on using the changeset viewer.