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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/console/ConsoleViewMessage.js

Issue 2596133002: Reland of DevTools: merge array formatting logic (Closed)
Patch Set: test Created 3 years, 11 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/components/RemoteObjectPreviewFormatter.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) 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 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 */ 456 */
457 _formatParameter(output, forceObjectFormat, includePreview) { 457 _formatParameter(output, forceObjectFormat, includePreview) {
458 if (output.customPreview()) 458 if (output.customPreview())
459 return (new Components.CustomPreviewComponent(output)).element; 459 return (new Components.CustomPreviewComponent(output)).element;
460 460
461 var type = forceObjectFormat ? 'object' : (output.subtype || output.type); 461 var type = forceObjectFormat ? 'object' : (output.subtype || output.type);
462 var element; 462 var element;
463 switch (type) { 463 switch (type) {
464 case 'array': 464 case 'array':
465 case 'typedarray': 465 case 'typedarray':
466 element = this._formatParameterAsArray(output); 466 element = this._formatParameterAsObject(output, includePreview);
467 break; 467 break;
468 case 'error': 468 case 'error':
469 element = this._formatParameterAsError(output); 469 element = this._formatParameterAsError(output);
470 break; 470 break;
471 case 'function': 471 case 'function':
472 case 'generator': 472 case 'generator':
473 element = this._formatParameterAsFunction(output, includePreview); 473 element = this._formatParameterAsFunction(output, includePreview);
474 break; 474 break;
475 case 'iterator': 475 case 'iterator':
476 case 'map': 476 case 'map':
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 */ 611 */
612 function failedToRender() { 612 function failedToRender() {
613 result.appendChild(this._formatParameterAsObject(object, false)); 613 result.appendChild(this._formatParameterAsObject(object, false));
614 } 614 }
615 } 615 }
616 616
617 _formattedParameterAsNodeForTest() { 617 _formattedParameterAsNodeForTest() {
618 } 618 }
619 619
620 /** 620 /**
621 * @param {!SDK.RemoteObject} array
622 * @return {!Element}
623 */
624 _formatParameterAsArray(array) {
625 var usePrintedArrayFormat = this._message.type !== SDK.ConsoleMessage.Messag eType.DirXML &&
626 this._message.type !== SDK.ConsoleMessage.MessageType.Result;
627 var isLongArray = array.arrayLength() > 100;
628 if (usePrintedArrayFormat || isLongArray)
629 return this._formatParameterAsObject(array, usePrintedArrayFormat || !isLo ngArray);
630 var result = createElement('span');
631 array.getAllProperties(false, printArrayResult.bind(this));
632 return result;
633
634 /**
635 * @param {?Array.<!SDK.RemoteObjectProperty>} properties
636 * @this {!Console.ConsoleViewMessage}
637 */
638 function printArrayResult(properties) {
639 if (!properties) {
640 result.appendChild(this._formatParameterAsObject(array, false));
641 return;
642 }
643
644 var titleElement = createElementWithClass('span', 'console-object-preview' );
645 if (array.subtype === 'typedarray')
646 titleElement.createTextChild(array.description + ' ');
647 var elements = {};
648 for (var i = 0; i < properties.length; ++i) {
649 var property = properties[i];
650 var name = property.name;
651 if (isNaN(name))
652 continue;
653 if (property.getter)
654 elements[name] = this._formatAsAccessorProperty(array, [name], true);
655 else if (property.value)
656 elements[name] = this._formatAsArrayEntry(property.value);
657 }
658
659 titleElement.createTextChild('[');
660 var lastNonEmptyIndex = -1;
661
662 function appendUndefined(titleElement, index) {
663 if (index - lastNonEmptyIndex <= 1)
664 return;
665 var span = titleElement.createChild('span', 'object-value-undefined');
666 span.textContent = Common.UIString('undefined × %d', index - lastNonEmpt yIndex - 1);
667 }
668
669 var length = array.arrayLength();
670 for (var i = 0; i < length; ++i) {
671 var element = elements[i];
672 if (!element)
673 continue;
674
675 if (i - lastNonEmptyIndex > 1) {
676 appendUndefined(titleElement, i);
677 titleElement.createTextChild(', ');
678 }
679
680 titleElement.appendChild(element);
681 lastNonEmptyIndex = i;
682 if (i < length - 1)
683 titleElement.createTextChild(', ');
684 }
685 appendUndefined(titleElement, length);
686
687 titleElement.createTextChild(']');
688
689 var section = new Components.ObjectPropertiesSection(array, titleElement, this._linkifier);
690 section.element.classList.add('console-view-object-properties-section');
691 section.enableContextMenu();
692 result.appendChild(section.element);
693 }
694 }
695
696 /**
697 * @param {!SDK.RemoteObject} output 621 * @param {!SDK.RemoteObject} output
698 * @return {!Element} 622 * @return {!Element}
699 */ 623 */
700 _formatParameterAsString(output) { 624 _formatParameterAsString(output) {
701 var span = createElement('span'); 625 var span = createElement('span');
702 span.appendChild(Components.linkifyStringAsFragment(output.description || '' )); 626 span.appendChild(Components.linkifyStringAsFragment(output.description || '' ));
703 627
704 var result = createElement('span'); 628 var result = createElement('span');
705 result.createChild('span', 'object-value-string-quote').textContent = '"'; 629 result.createChild('span', 'object-value-string-quote').textContent = '"';
706 result.appendChild(span); 630 result.appendChild(span);
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
1265 toMessageElement() { 1189 toMessageElement() {
1266 if (!this._element) { 1190 if (!this._element) {
1267 super.toMessageElement(); 1191 super.toMessageElement();
1268 this._expandGroupIcon = UI.Icon.create('', 'expand-group-icon'); 1192 this._expandGroupIcon = UI.Icon.create('', 'expand-group-icon');
1269 this._contentElement.insertBefore(this._expandGroupIcon, this._contentElem ent.firstChild); 1193 this._contentElement.insertBefore(this._expandGroupIcon, this._contentElem ent.firstChild);
1270 this.setCollapsed(this._collapsed); 1194 this.setCollapsed(this._collapsed);
1271 } 1195 }
1272 return this._element; 1196 return this._element;
1273 } 1197 }
1274 }; 1198 };
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/components/RemoteObjectPreviewFormatter.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698