OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. | 3 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. |
4 * Copyright (C) 2009 Joseph Pecoraro | 4 * Copyright (C) 2009 Joseph Pecoraro |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
8 * are met: | 8 * are met: |
9 * | 9 * |
10 * 1. Redistributions of source code must retain the above copyright | 10 * 1. Redistributions of source code must retain the above copyright |
(...skipping 27 matching lines...) Expand all Loading... |
38 WebInspector.ConsoleViewMessage = function(consoleMessage, linkifier, nestingLev
el) | 38 WebInspector.ConsoleViewMessage = function(consoleMessage, linkifier, nestingLev
el) |
39 { | 39 { |
40 this._message = consoleMessage; | 40 this._message = consoleMessage; |
41 this._linkifier = linkifier; | 41 this._linkifier = linkifier; |
42 this._repeatCount = 1; | 42 this._repeatCount = 1; |
43 this._closeGroupDecorationCount = 0; | 43 this._closeGroupDecorationCount = 0; |
44 this._nestingLevel = nestingLevel; | 44 this._nestingLevel = nestingLevel; |
45 | 45 |
46 /** @type {?WebInspector.DataGrid} */ | 46 /** @type {?WebInspector.DataGrid} */ |
47 this._dataGrid = null; | 47 this._dataGrid = null; |
48 | |
49 /** @type {!Object.<string, function(!WebInspector.RemoteObject, !Element, b
oolean=)>} */ | |
50 this._customFormatters = { | |
51 "array": this._formatParameterAsArray, | |
52 "typedarray": this._formatParameterAsArray, | |
53 "error": this._formatParameterAsError, | |
54 "function": this._formatParameterAsFunction, | |
55 "generator": this._formatParameterAsObject, | |
56 "iterator": this._formatParameterAsObject, | |
57 "map": this._formatParameterAsObject, | |
58 "node": this._formatParameterAsNode, | |
59 "object": this._formatParameterAsObject, | |
60 "promise": this._formatParameterAsObject, | |
61 "proxy": this._formatParameterAsObject, | |
62 "set": this._formatParameterAsObject, | |
63 "string": this._formatParameterAsString | |
64 }; | |
65 this._previewFormatter = new WebInspector.RemoteObjectPreviewFormatter(); | 48 this._previewFormatter = new WebInspector.RemoteObjectPreviewFormatter(); |
66 this._searchRegex = null; | 49 this._searchRegex = null; |
67 } | 50 } |
68 | 51 |
69 WebInspector.ConsoleViewMessage.prototype = { | 52 WebInspector.ConsoleViewMessage.prototype = { |
70 /** | 53 /** |
71 * @return {?WebInspector.Target} | 54 * @return {?WebInspector.Target} |
72 */ | 55 */ |
73 _target: function() | 56 _target: function() |
74 { | 57 { |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 }, | 274 }, |
292 | 275 |
293 /** | 276 /** |
294 * @param {!WebInspector.ConsoleMessage} consoleMessage | 277 * @param {!WebInspector.ConsoleMessage} consoleMessage |
295 * @return {?Element} | 278 * @return {?Element} |
296 */ | 279 */ |
297 _buildMessageAnchor: function(consoleMessage) | 280 _buildMessageAnchor: function(consoleMessage) |
298 { | 281 { |
299 var anchorElement = null; | 282 var anchorElement = null; |
300 if (consoleMessage.source !== WebInspector.ConsoleMessage.MessageSource.
Network || consoleMessage.request) { | 283 if (consoleMessage.source !== WebInspector.ConsoleMessage.MessageSource.
Network || consoleMessage.request) { |
301 if (consoleMessage.scriptId) { | 284 if (consoleMessage.scriptId) |
302 anchorElement = this._linkifyScriptId(consoleMessage.scriptId, c
onsoleMessage.url || "", consoleMessage.line, consoleMessage.column); | 285 anchorElement = this._linkifyScriptId(consoleMessage.scriptId, c
onsoleMessage.url || "", consoleMessage.line, consoleMessage.column); |
303 } else { | 286 else if (consoleMessage.stackTrace && consoleMessage.stackTrace.call
Frames.length) |
304 if (consoleMessage.stackTrace && consoleMessage.stackTrace.callF
rames.length) | 287 anchorElement = this._linkifyStackTraceTopFrame(consoleMessage.s
tackTrace); |
305 anchorElement = this._linkifyStackTraceTopFrame(consoleMessa
ge.stackTrace); | 288 else if (consoleMessage.url && consoleMessage.url !== "undefined") |
306 else if (consoleMessage.url && consoleMessage.url !== "undefined
") | 289 anchorElement = this._linkifyLocation(consoleMessage.url, consol
eMessage.line, consoleMessage.column); |
307 anchorElement = this._linkifyLocation(consoleMessage.url, co
nsoleMessage.line, consoleMessage.column); | |
308 } | |
309 } else if (consoleMessage.url) { | 290 } else if (consoleMessage.url) { |
310 var url = consoleMessage.url; | 291 var url = consoleMessage.url; |
311 var isExternal = !WebInspector.resourceForURL(url) && !WebInspector.
networkMapping.uiSourceCodeForURLForAnyTarget(url); | 292 var isExternal = !WebInspector.resourceForURL(url) && !WebInspector.
networkMapping.uiSourceCodeForURLForAnyTarget(url); |
312 anchorElement = WebInspector.linkifyURLAsNode(url, url, "console-mes
sage-url", isExternal); | 293 anchorElement = WebInspector.linkifyURLAsNode(url, url, "console-mes
sage-url", isExternal); |
313 } | 294 } |
314 | 295 |
315 // Append a space to prevent the anchor text from being glued to the con
sole message when the user selects and copies the console messages. | 296 // Append a space to prevent the anchor text from being glued to the con
sole message when the user selects and copies the console messages. |
316 if (anchorElement) | 297 if (anchorElement) |
317 anchorElement.appendChild(createTextNode(" ")); | 298 anchorElement.appendChild(createTextNode(" ")); |
318 return anchorElement; | 299 return anchorElement; |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 }, | 447 }, |
467 | 448 |
468 /** | 449 /** |
469 * @param {!WebInspector.RemoteObject} output | 450 * @param {!WebInspector.RemoteObject} output |
470 * @param {boolean=} forceObjectFormat | 451 * @param {boolean=} forceObjectFormat |
471 * @param {boolean=} includePreview | 452 * @param {boolean=} includePreview |
472 * @return {!Element} | 453 * @return {!Element} |
473 */ | 454 */ |
474 _formatParameter: function(output, forceObjectFormat, includePreview) | 455 _formatParameter: function(output, forceObjectFormat, includePreview) |
475 { | 456 { |
476 if (output.customPreview()) { | 457 if (output.customPreview()) |
477 return (new WebInspector.CustomPreviewComponent(output)).element; | 458 return (new WebInspector.CustomPreviewComponent(output)).element; |
478 } | |
479 | 459 |
480 var type = forceObjectFormat ? "object" : (output.subtype || output.type
); | 460 var type = forceObjectFormat ? "object" : (output.subtype || output.type
); |
481 var formatter = this._customFormatters[type] || this._formatParameterAsV
alue; | |
482 var span = createElement("span"); | 461 var span = createElement("span"); |
483 span.className = "object-value-" + type + " source-code"; | 462 span.className = "object-value-" + type + " source-code"; |
484 formatter.call(this, output, span, includePreview); | 463 switch (type) { |
| 464 case "array": |
| 465 case "typedarray": |
| 466 this._formatParameterAsArray(output, span); |
| 467 break; |
| 468 case "error": |
| 469 this._formatParameterAsError(output, span); |
| 470 break; |
| 471 case "function": |
| 472 case "generator": |
| 473 this._formatParameterAsFunction(output, span, includePreview); |
| 474 break; |
| 475 case "iterator": |
| 476 case "map": |
| 477 case "object": |
| 478 case "promise": |
| 479 case "proxy": |
| 480 case "set": |
| 481 this._formatParameterAsObject(output, span, includePreview); |
| 482 break; |
| 483 case "node": |
| 484 this._formatParameterAsNode(output, span); |
| 485 break; |
| 486 case "string": |
| 487 this._formatParameterAsString(output, span); |
| 488 break; |
| 489 case "boolean": |
| 490 case "date": |
| 491 case "null": |
| 492 case "number": |
| 493 case "regexp": |
| 494 case "symbol": |
| 495 case "undefined": |
| 496 this._formatParameterAsValue(output, span); |
| 497 break; |
| 498 default: |
| 499 this._formatParameterAsValue(output, span); |
| 500 console.error("Tried to format remote object of unknown type."); |
| 501 } |
485 return span; | 502 return span; |
486 }, | 503 }, |
487 | 504 |
488 /** | 505 /** |
489 * @param {!WebInspector.RemoteObject} obj | 506 * @param {!WebInspector.RemoteObject} obj |
490 * @param {!Element} elem | 507 * @param {!Element} elem |
491 */ | 508 */ |
492 _formatParameterAsValue: function(obj, elem) | 509 _formatParameterAsValue: function(obj, elem) |
493 { | 510 { |
494 elem.createTextChild(obj.description || ""); | 511 elem.createTextChild(obj.description || ""); |
495 if (obj.objectId) | 512 if (obj.objectId) |
496 elem.addEventListener("contextmenu", this._contextMenuEventFired.bin
d(this, obj), false); | 513 elem.addEventListener("contextmenu", this._contextMenuEventFired.bin
d(this, obj), false); |
497 }, | 514 }, |
498 | 515 |
499 /** | 516 /** |
500 * @param {!WebInspector.RemoteObject} obj | 517 * @param {!WebInspector.RemoteObject} obj |
501 * @param {!Element} elem | 518 * @param {!Element} elem |
502 * @param {boolean=} includePreview | 519 * @param {boolean=} includePreview |
503 */ | 520 */ |
504 _formatParameterAsObject: function(obj, elem, includePreview) | 521 _formatParameterAsObject: function(obj, elem, includePreview) |
505 { | 522 { |
506 this._formatParameterAsArrayOrObject(obj, elem, includePreview); | |
507 }, | |
508 | |
509 /** | |
510 * @param {!WebInspector.RemoteObject} obj | |
511 * @param {!Element} elem | |
512 * @param {boolean=} includePreview | |
513 */ | |
514 _formatParameterAsArrayOrObject: function(obj, elem, includePreview) | |
515 { | |
516 var titleElement = createElement("span"); | 523 var titleElement = createElement("span"); |
517 if (includePreview && obj.preview) { | 524 if (includePreview && obj.preview) { |
518 titleElement.classList.add("console-object-preview"); | 525 titleElement.classList.add("console-object-preview"); |
519 this._previewFormatter.appendObjectPreview(titleElement, obj.preview
); | 526 this._previewFormatter.appendObjectPreview(titleElement, obj.preview
); |
| 527 } else if (obj.type === "function") { |
| 528 WebInspector.ObjectPropertiesSection.formatObjectAsFunction(obj, tit
leElement, false); |
| 529 titleElement.classList.add("object-value-function"); |
520 } else { | 530 } else { |
521 if (obj.type === "function") { | 531 titleElement.createTextChild(obj.description || ""); |
522 WebInspector.ObjectPropertiesSection.formatObjectAsFunction(obj,
titleElement, false); | |
523 titleElement.classList.add("object-value-function"); | |
524 } else { | |
525 titleElement.createTextChild(obj.description || ""); | |
526 } | |
527 } | 532 } |
528 | 533 |
529 var section = new WebInspector.ObjectPropertiesSection(obj, titleElement
, this._linkifier); | 534 var section = new WebInspector.ObjectPropertiesSection(obj, titleElement
, this._linkifier); |
530 section.element.classList.add("console-view-object-properties-section"); | 535 section.element.classList.add("console-view-object-properties-section"); |
531 section.enableContextMenu(); | 536 section.enableContextMenu(); |
532 elem.appendChild(section.element); | 537 elem.appendChild(section.element); |
533 }, | 538 }, |
534 | 539 |
535 /** | 540 /** |
536 * @param {!WebInspector.RemoteObject} func | 541 * @param {!WebInspector.RemoteObject} func |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 { | 611 { |
607 this._formatParameterAsObject(object, elem, false); | 612 this._formatParameterAsObject(object, elem, false); |
608 } | 613 } |
609 }, | 614 }, |
610 | 615 |
611 _formattedParameterAsNodeForTest: function() | 616 _formattedParameterAsNodeForTest: function() |
612 { | 617 { |
613 }, | 618 }, |
614 | 619 |
615 /** | 620 /** |
616 * @return {boolean} | |
617 */ | |
618 _usePrintedArrayFormatter: function() | |
619 { | |
620 return this._message.type !== WebInspector.ConsoleMessage.MessageType.Di
rXML && this._message.type !== WebInspector.ConsoleMessage.MessageType.Result; | |
621 }, | |
622 | |
623 /** | |
624 * @param {!WebInspector.RemoteObject} array | 621 * @param {!WebInspector.RemoteObject} array |
625 * @param {!Element} elem | 622 * @param {!Element} elem |
626 */ | 623 */ |
627 _formatParameterAsArray: function(array, elem) | 624 _formatParameterAsArray: function(array, elem) |
628 { | 625 { |
629 var maxFlatArrayLength = 100; | 626 var usePrintedArrayFormat = this._message.type !== WebInspector.ConsoleM
essage.MessageType.DirXML && this._message.type !== WebInspector.ConsoleMessage.
MessageType.Result; |
630 if (this._usePrintedArrayFormatter() || array.arrayLength() > maxFlatArr
ayLength) | 627 var isLongArray = array.arrayLength() > 100; |
631 this._formatParameterAsArrayOrObject(array, elem, this._usePrintedAr
rayFormatter() || array.arrayLength() <= maxFlatArrayLength); | 628 if (usePrintedArrayFormat || isLongArray) |
| 629 this._formatParameterAsObject(array, elem, usePrintedArrayFormat ||
!isLongArray); |
632 else | 630 else |
633 array.getAllProperties(false, this._printArrayResult.bind(this, arra
y, elem)); | 631 array.getAllProperties(false, printArrayResult.bind(this)); |
| 632 |
| 633 /** |
| 634 * @param {?Array.<!WebInspector.RemoteObjectProperty>} properties |
| 635 * @this {!WebInspector.ConsoleViewMessage} |
| 636 */ |
| 637 function printArrayResult(properties) |
| 638 { |
| 639 if (!properties) { |
| 640 this._formatParameterAsObject(array, elem, false); |
| 641 return; |
| 642 } |
| 643 |
| 644 var titleElement = createElement("span"); |
| 645 var elements = {}; |
| 646 for (var i = 0; i < properties.length; ++i) { |
| 647 var property = properties[i]; |
| 648 var name = property.name; |
| 649 if (isNaN(name)) |
| 650 continue; |
| 651 if (property.getter) |
| 652 elements[name] = this._formatAsAccessorProperty(array, [name
], true); |
| 653 else if (property.value) |
| 654 elements[name] = this._formatAsArrayEntry(property.value); |
| 655 } |
| 656 |
| 657 titleElement.createTextChild("["); |
| 658 var lastNonEmptyIndex = -1; |
| 659 |
| 660 function appendUndefined(titleElement, index) |
| 661 { |
| 662 if (index - lastNonEmptyIndex <= 1) |
| 663 return; |
| 664 var span = titleElement.createChild("span", "object-value-undefi
ned"); |
| 665 span.textContent = WebInspector.UIString("undefined × %d", index
- lastNonEmptyIndex - 1); |
| 666 } |
| 667 |
| 668 var length = array.arrayLength(); |
| 669 for (var i = 0; i < length; ++i) { |
| 670 var element = elements[i]; |
| 671 if (!element) |
| 672 continue; |
| 673 |
| 674 if (i - lastNonEmptyIndex > 1) { |
| 675 appendUndefined(titleElement, i); |
| 676 titleElement.createTextChild(", "); |
| 677 } |
| 678 |
| 679 titleElement.appendChild(element); |
| 680 lastNonEmptyIndex = i; |
| 681 if (i < length - 1) |
| 682 titleElement.createTextChild(", "); |
| 683 } |
| 684 appendUndefined(titleElement, length); |
| 685 |
| 686 titleElement.createTextChild("]"); |
| 687 |
| 688 var section = new WebInspector.ObjectPropertiesSection(array, titleE
lement, this._linkifier); |
| 689 section.element.classList.add("console-view-object-properties-sectio
n"); |
| 690 section.enableContextMenu(); |
| 691 elem.appendChild(section.element); |
| 692 } |
634 }, | 693 }, |
635 | 694 |
636 /** | 695 /** |
637 * @param {!WebInspector.RemoteObject} output | 696 * @param {!WebInspector.RemoteObject} output |
638 * @param {!Element} elem | 697 * @param {!Element} elem |
639 */ | 698 */ |
640 _formatParameterAsString: function(output, elem) | 699 _formatParameterAsString: function(output, elem) |
641 { | 700 { |
642 var span = createElement("span"); | 701 var span = createElement("span"); |
643 span.className = "object-value-string source-code"; | 702 span.className = "object-value-string source-code"; |
(...skipping 11 matching lines...) Expand all Loading... |
655 * @param {!Element} elem | 714 * @param {!Element} elem |
656 */ | 715 */ |
657 _formatParameterAsError: function(output, elem) | 716 _formatParameterAsError: function(output, elem) |
658 { | 717 { |
659 var span = elem.createChild("span", "object-value-error source-code"); | 718 var span = elem.createChild("span", "object-value-error source-code"); |
660 var errorSpan = this._tryFormatAsError(output.description || ""); | 719 var errorSpan = this._tryFormatAsError(output.description || ""); |
661 span.appendChild(errorSpan ? errorSpan : WebInspector.linkifyStringAsFra
gment(output.description || "")); | 720 span.appendChild(errorSpan ? errorSpan : WebInspector.linkifyStringAsFra
gment(output.description || "")); |
662 }, | 721 }, |
663 | 722 |
664 /** | 723 /** |
665 * @param {!WebInspector.RemoteObject} array | |
666 * @param {!Element} elem | |
667 * @param {?Array.<!WebInspector.RemoteObjectProperty>} properties | |
668 */ | |
669 _printArrayResult: function(array, elem, properties) | |
670 { | |
671 if (!properties) { | |
672 this._formatParameterAsObject(array, elem, false); | |
673 return; | |
674 } | |
675 | |
676 var titleElement = createElement("span"); | |
677 var elements = {}; | |
678 for (var i = 0; i < properties.length; ++i) { | |
679 var property = properties[i]; | |
680 var name = property.name; | |
681 if (isNaN(name)) | |
682 continue; | |
683 if (property.getter) | |
684 elements[name] = this._formatAsAccessorProperty(array, [name], t
rue); | |
685 else if (property.value) | |
686 elements[name] = this._formatAsArrayEntry(property.value); | |
687 } | |
688 | |
689 titleElement.createTextChild("["); | |
690 var lastNonEmptyIndex = -1; | |
691 | |
692 function appendUndefined(titleElement, index) | |
693 { | |
694 if (index - lastNonEmptyIndex <= 1) | |
695 return; | |
696 var span = titleElement.createChild("span", "object-value-undefined"
); | |
697 span.textContent = WebInspector.UIString("undefined × %d", index - l
astNonEmptyIndex - 1); | |
698 } | |
699 | |
700 var length = array.arrayLength(); | |
701 for (var i = 0; i < length; ++i) { | |
702 var element = elements[i]; | |
703 if (!element) | |
704 continue; | |
705 | |
706 if (i - lastNonEmptyIndex > 1) { | |
707 appendUndefined(titleElement, i); | |
708 titleElement.createTextChild(", "); | |
709 } | |
710 | |
711 titleElement.appendChild(element); | |
712 lastNonEmptyIndex = i; | |
713 if (i < length - 1) | |
714 titleElement.createTextChild(", "); | |
715 } | |
716 appendUndefined(titleElement, length); | |
717 | |
718 titleElement.createTextChild("]"); | |
719 | |
720 var section = new WebInspector.ObjectPropertiesSection(array, titleEleme
nt, this._linkifier); | |
721 section.element.classList.add("console-view-object-properties-section"); | |
722 section.enableContextMenu(); | |
723 elem.appendChild(section.element); | |
724 }, | |
725 | |
726 /** | |
727 * @param {!WebInspector.RemoteObject} output | 724 * @param {!WebInspector.RemoteObject} output |
728 * @return {!Element} | 725 * @return {!Element} |
729 */ | 726 */ |
730 _formatAsArrayEntry: function(output) | 727 _formatAsArrayEntry: function(output) |
731 { | 728 { |
732 return this._previewFormatter.renderPropertyPreview(output.type, output.
subtype, output.description); | 729 return this._previewFormatter.renderPropertyPreview(output.type, output.
subtype, output.description); |
733 }, | 730 }, |
734 | 731 |
735 /** | 732 /** |
736 * @param {?WebInspector.RemoteObject} object | 733 * @param {?WebInspector.RemoteObject} object |
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1262 { | 1259 { |
1263 if (!this._element) { | 1260 if (!this._element) { |
1264 WebInspector.ConsoleViewMessage.prototype.toMessageElement.call(this
); | 1261 WebInspector.ConsoleViewMessage.prototype.toMessageElement.call(this
); |
1265 this._element.classList.toggle("collapsed", this._collapsed); | 1262 this._element.classList.toggle("collapsed", this._collapsed); |
1266 } | 1263 } |
1267 return this._element; | 1264 return this._element; |
1268 }, | 1265 }, |
1269 | 1266 |
1270 __proto__: WebInspector.ConsoleViewMessage.prototype | 1267 __proto__: WebInspector.ConsoleViewMessage.prototype |
1271 } | 1268 } |
OLD | NEW |