Changeset 96487 in webkit
- Timestamp:
- Oct 3, 2011 2:54:27 AM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r96485 r96487 1 2011-10-03 Pavel Feldman <pfeldman@google.com> 2 3 Web Inspector: move console message formatting from ConsoleView.js into ConsoleMessage.js 4 https://bugs.webkit.org/show_bug.cgi?id=69244 5 6 Reviewed by Yury Semikhatsky. 7 8 * inspector/front-end/ConsoleMessage.js: 9 (WebInspector.ConsoleMessage): 10 (WebInspector.ConsoleMessage.prototype._formatMessage.else.else.linkifier): 11 (WebInspector.ConsoleMessage.prototype._formatMessage): 12 (WebInspector.ConsoleMessage.prototype._format): 13 (WebInspector.ConsoleMessage.prototype._formatParameter): 14 (WebInspector.ConsoleMessage.prototype._formatParameterAsValue): 15 (WebInspector.ConsoleMessage.prototype._formatParameterAsObject): 16 (WebInspector.ConsoleMessage.prototype._formatParameterAsNode): 17 (WebInspector.ConsoleMessage.prototype._formatParameterAsArray): 18 (WebInspector.ConsoleMessage.prototype._formatParameterAsString): 19 (WebInspector.ConsoleMessage.prototype._printArray): 20 (WebInspector.ConsoleMessage.prototype._formatAsArrayEntry): 21 (WebInspector.ConsoleMessage.prototype._formatWithSubstitutionString): 22 * inspector/front-end/ConsoleView.js: 23 1 24 2011-10-03 Pavel Feldman <pfeldman@chromium.org> 2 25 -
trunk/Source/WebCore/inspector/front-end/ConsoleMessage.js
r95984 r96487 42 42 /** 43 43 * @constructor 44 * @param {Array.<WebInspector.ConsoleStackFrame>=} stackTrace 45 * @param {number=} request 44 * @param {Array.<RuntimeAgent.RemoteObject>=} parameters 45 * @param {ConsoleAgent.StackTrace=} stackTrace 46 * @param {WebInspector.Resource=} request 46 47 */ 47 48 WebInspector.ConsoleMessage = function(source, type, level, line, url, repeatCount, message, parameters, stackTrace, request) … … 67 68 this.line = topCallFrame.lineNumber; 68 69 } 70 71 this._customFormatters = { 72 "object": this._formatParameterAsObject, 73 "array": this._formatParameterAsArray, 74 "node": this._formatParameterAsNode, 75 "string": this._formatParameterAsString 76 }; 69 77 70 78 this._formatMessage(); … … 124 132 { 125 133 var isExternal = !this._request; 126 var anchor = WebInspector.linkifyURLAsNode(url, title, null, isExternal);134 var anchor = WebInspector.linkifyURLAsNode(url, title, undefined, isExternal); 127 135 if (this._request) { 128 136 anchor.setAttribute("request_id", this._request.requestId); … … 131 139 return anchor; 132 140 } 133 141 134 142 var fragment = WebInspector.linkifyStringAsFragmentWithCustomLinkifier(this._messageText, linkifier.bind(this)); 135 143 messageText.appendChild(fragment); … … 236 244 formattedResult.appendChild(document.createTextNode(parameters[i].description)); 237 245 else 238 formattedResult.appendChild( WebInspector.consoleView._format(parameters[i]));246 formattedResult.appendChild(this._formatParameter(parameters[i])); 239 247 if (i < parameters.length - 1) 240 248 formattedResult.appendChild(document.createTextNode(" ")); … … 243 251 }, 244 252 253 /** 254 * @param {boolean=} forceObjectFormat 255 */ 256 _formatParameter: function(output, forceObjectFormat) 257 { 258 var type; 259 if (forceObjectFormat) 260 type = "object"; 261 else if (output instanceof WebInspector.RemoteObject) 262 type = output.subtype || output.type; 263 else 264 type = typeof output; 265 266 var formatter = this._customFormatters[type]; 267 if (!formatter) { 268 formatter = this._formatParameterAsValue; 269 output = output.description; 270 } 271 272 var span = document.createElement("span"); 273 span.className = "console-formatted-" + type + " source-code"; 274 formatter.call(this, output, span); 275 return span; 276 }, 277 278 _formatParameterAsValue: function(val, elem) 279 { 280 elem.appendChild(document.createTextNode(val)); 281 }, 282 283 _formatParameterAsObject: function(obj, elem) 284 { 285 elem.appendChild(new WebInspector.ObjectPropertiesSection(obj, obj.description).element); 286 }, 287 288 _formatParameterAsNode: function(object, elem) 289 { 290 function printNode(nodeId) 291 { 292 if (!nodeId) { 293 // Sometimes DOM is loaded after the sync message is being formatted, so we get no 294 // nodeId here. So we fall back to object formatting here. 295 this._formatParameterAsObject(object, elem); 296 return; 297 } 298 var treeOutline = new WebInspector.ElementsTreeOutline(); 299 treeOutline.showInElementsPanelEnabled = true; 300 treeOutline.rootDOMNode = WebInspector.domAgent.nodeForId(nodeId); 301 treeOutline.element.addStyleClass("outline-disclosure"); 302 if (!treeOutline.children[0].hasChildren) 303 treeOutline.element.addStyleClass("single-node"); 304 elem.appendChild(treeOutline.element); 305 } 306 object.pushNodeToFrontend(printNode.bind(this)); 307 }, 308 309 _formatParameterAsArray: function(arr, elem) 310 { 311 arr.getOwnProperties(this._printArray.bind(this, elem)); 312 }, 313 314 _formatParameterAsString: function(output, elem) 315 { 316 var span = document.createElement("span"); 317 span.className = "console-formatted-string source-code"; 318 span.appendChild(WebInspector.linkifyStringAsFragment(output.description)); 319 320 // Make black quotes. 321 elem.removeStyleClass("console-formatted-string"); 322 elem.appendChild(document.createTextNode("\"")); 323 elem.appendChild(span); 324 elem.appendChild(document.createTextNode("\"")); 325 }, 326 327 _printArray: function(elem, properties) 328 { 329 if (!properties) 330 return; 331 332 var elements = []; 333 for (var i = 0; i < properties.length; ++i) { 334 var name = properties[i].name; 335 if (name == parseInt(name, 10)) 336 elements[name] = this._formatAsArrayEntry(properties[i].value); 337 } 338 339 elem.appendChild(document.createTextNode("[")); 340 for (var i = 0; i < elements.length; ++i) { 341 var element = elements[i]; 342 if (element) 343 elem.appendChild(element); 344 else 345 elem.appendChild(document.createTextNode("undefined")) 346 if (i < elements.length - 1) 347 elem.appendChild(document.createTextNode(", ")); 348 } 349 elem.appendChild(document.createTextNode("]")); 350 }, 351 352 _formatAsArrayEntry: function(output) 353 { 354 // Prevent infinite expansion of cross-referencing arrays. 355 return this._formatParameter(output, output.subtype && output.subtype === "array"); 356 }, 357 245 358 _formatWithSubstitutionString: function(parameters, formattedResult) 246 359 { 247 360 var formatters = {} 248 361 249 function consoleFormatWrapper(force)362 function parameterFormatter(force, obj) 250 363 { 251 return function(obj) { 252 return WebInspector.consoleView._format(obj, force); 253 }; 364 return this._formatParameter(obj, force); 254 365 } 255 366 … … 260 371 261 372 // Firebug uses %o for formatting objects. 262 formatters.o = consoleFormatWrapper(false);373 formatters.o = parameterFormatter.bind(this, false); 263 374 formatters.s = valueFormatter; 264 375 formatters.f = valueFormatter; … … 268 379 269 380 // Support %O to force object formatting, instead of the type-based %o formatting. 270 formatters.O = consoleFormatWrapper(true);381 formatters.O = parameterFormatter.bind(this, true); 271 382 272 383 function append(a, b) -
trunk/Source/WebCore/inspector/front-end/ConsoleView.js
r95716 r96487 30 30 const ExpressionStopCharacters = " =:[({;,!+-*/&|^<>"; 31 31 32 /** 33 * @extends {WebInspector.View} 34 * @constructor 35 */ 32 36 WebInspector.ConsoleView = function() 33 37 { … … 101 105 102 106 this.messagesElement.addEventListener("contextmenu", this._handleContextMenuEvent.bind(this), false); 103 104 this._customFormatters = {105 "object": this._formatobject,106 "array": this._formatarray,107 "node": this._formatnode,108 "string": this._formatstring109 };110 107 111 108 WebInspector.settings.monitoringXHREnabled.addChangeListener(this._monitoringXHREnabledSettingChanged.bind(this)); … … 638 635 }, 639 636 640 _format: function(output, forceObjectFormat)641 {642 var type;643 if (forceObjectFormat)644 type = "object";645 else if (output instanceof WebInspector.RemoteObject)646 type = output.subtype || output.type;647 else648 type = typeof output;649 650 var formatter = this._customFormatters[type];651 if (!formatter) {652 formatter = this._formatvalue;653 output = output.description;654 }655 656 var span = document.createElement("span");657 span.className = "console-formatted-" + type + " source-code";658 formatter.call(this, output, span);659 return span;660 },661 662 _formatvalue: function(val, elem)663 {664 elem.appendChild(document.createTextNode(val));665 },666 667 _formatobject: function(obj, elem)668 {669 elem.appendChild(new WebInspector.ObjectPropertiesSection(obj, obj.description).element);670 },671 672 _formatnode: function(object, elem)673 {674 function printNode(nodeId)675 {676 if (!nodeId) {677 // Sometimes DOM is loaded after the sync message is being formatted, so we get no678 // nodeId here. So we fall back to object formatting here.679 this._formatobject(object, elem);680 return;681 }682 var treeOutline = new WebInspector.ElementsTreeOutline();683 treeOutline.showInElementsPanelEnabled = true;684 treeOutline.rootDOMNode = WebInspector.domAgent.nodeForId(nodeId);685 treeOutline.element.addStyleClass("outline-disclosure");686 if (!treeOutline.children[0].hasChildren)687 treeOutline.element.addStyleClass("single-node");688 elem.appendChild(treeOutline.element);689 }690 object.pushNodeToFrontend(printNode.bind(this));691 },692 693 _formatarray: function(arr, elem)694 {695 arr.getOwnProperties(this._printArray.bind(this, elem));696 },697 698 _formatstring: function(output, elem)699 {700 var span = document.createElement("span");701 span.className = "console-formatted-string source-code";702 span.appendChild(WebInspector.linkifyStringAsFragment(output.description));703 704 // Make black quotes.705 elem.removeStyleClass("console-formatted-string");706 elem.appendChild(document.createTextNode("\""));707 elem.appendChild(span);708 elem.appendChild(document.createTextNode("\""));709 },710 711 _printArray: function(elem, properties)712 {713 if (!properties)714 return;715 716 var elements = [];717 for (var i = 0; i < properties.length; ++i) {718 var name = properties[i].name;719 if (name == parseInt(name))720 elements[name] = this._formatAsArrayEntry(properties[i].value);721 }722 723 elem.appendChild(document.createTextNode("["));724 for (var i = 0; i < elements.length; ++i) {725 var element = elements[i];726 if (element)727 elem.appendChild(element);728 else729 elem.appendChild(document.createTextNode("undefined"))730 if (i < elements.length - 1)731 elem.appendChild(document.createTextNode(", "));732 }733 elem.appendChild(document.createTextNode("]"));734 },735 736 _formatAsArrayEntry: function(output)737 {738 // Prevent infinite expansion of cross-referencing arrays.739 return this._format(output, output.subtype && output.subtype === "array");740 },741 742 637 elementsToRestoreScrollPositionsFor: function() 743 638 { … … 877 772 } 878 773 } 774 775 /** 776 * @type {?WebInspector.ConsoleView} 777 */ 778 WebInspector.consoleView = null;
Note: See TracChangeset
for help on using the changeset viewer.