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

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

Issue 2566443004: DevTools: merge array formatting logic (Closed)
Patch Set: Created 4 years 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
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 606 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 /** 617 /**
618 * @param {!SDK.RemoteObject} array 618 * @param {!SDK.RemoteObject} array
619 * @return {!Element} 619 * @return {!Element}
620 */ 620 */
621 _formatParameterAsArray(array) { 621 _formatParameterAsArray(array) {
622 var usePrintedArrayFormat = this._message.type !== SDK.ConsoleMessage.Messag eType.DirXML && 622 var usePrintedArrayFormat = this._message.type !== SDK.ConsoleMessage.Messag eType.DirXML &&
623 this._message.type !== SDK.ConsoleMessage.MessageType.Result; 623 this._message.type !== SDK.ConsoleMessage.MessageType.Result;
624 var isLongArray = array.arrayLength() > 100; 624 var isLongArray = array.arrayLength() > 100;
625 if (usePrintedArrayFormat || isLongArray) 625 if (usePrintedArrayFormat || isLongArray)
626 return this._formatParameterAsObject(array, usePrintedArrayFormat || !isLo ngArray); 626 return this._formatParameterAsObject(array, usePrintedArrayFormat || !isLo ngArray);
627 var result = createElement('span'); 627 var titleElement = createElementWithClass('span', 'console-object-preview');
628 array.getAllProperties(false, printArrayResult.bind(this)); 628 this._previewFormatter.appendObjectPreview(titleElement, array.preview, true );
629 return result; 629 var section = new Components.ObjectPropertiesSection(array, titleElement, th is._linkifier);
630 630 section.element.classList.add('console-view-object-properties-section');
631 /** 631 section.enableContextMenu();
632 * @param {?Array.<!SDK.RemoteObjectProperty>} properties 632 return section.element;
633 * @this {!Console.ConsoleViewMessage}
634 */
635 function printArrayResult(properties) {
636 if (!properties) {
637 result.appendChild(this._formatParameterAsObject(array, false));
638 return;
639 }
640
641 var titleElement = createElementWithClass('span', 'console-object-preview' );
642 if (array.subtype === 'typedarray')
643 titleElement.createTextChild(array.description + ' ');
644 var elements = {};
645 for (var i = 0; i < properties.length; ++i) {
646 var property = properties[i];
647 var name = property.name;
648 if (isNaN(name))
649 continue;
650 if (property.getter)
651 elements[name] = this._formatAsAccessorProperty(array, [name], true);
652 else if (property.value)
653 elements[name] = this._formatAsArrayEntry(property.value);
luoe 2016/12/08 22:36:45 this._formatAsAccessorProperty and this._formatAsA
654 }
655
656 titleElement.createTextChild('[');
657 var lastNonEmptyIndex = -1;
658
659 function appendUndefined(titleElement, index) {
660 if (index - lastNonEmptyIndex <= 1)
661 return;
662 var span = titleElement.createChild('span', 'object-value-undefined');
663 span.textContent = Common.UIString('undefined × %d', index - lastNonEmpt yIndex - 1);
664 }
665
666 var length = array.arrayLength();
667 for (var i = 0; i < length; ++i) {
668 var element = elements[i];
669 if (!element)
670 continue;
671
672 if (i - lastNonEmptyIndex > 1) {
673 appendUndefined(titleElement, i);
674 titleElement.createTextChild(', ');
675 }
676
677 titleElement.appendChild(element);
678 lastNonEmptyIndex = i;
679 if (i < length - 1)
680 titleElement.createTextChild(', ');
681 }
682 appendUndefined(titleElement, length);
683
684 titleElement.createTextChild(']');
685
686 var section = new Components.ObjectPropertiesSection(array, titleElement, this._linkifier);
687 section.element.classList.add('console-view-object-properties-section');
688 section.enableContextMenu();
689 result.appendChild(section.element);
690 }
691 } 633 }
692 634
693 /** 635 /**
694 * @param {!SDK.RemoteObject} output 636 * @param {!SDK.RemoteObject} output
695 * @return {!Element} 637 * @return {!Element}
696 */ 638 */
697 _formatParameterAsString(output) { 639 _formatParameterAsString(output) {
698 var span = createElement('span'); 640 var span = createElement('span');
699 span.appendChild(Components.linkifyStringAsFragment(output.description || '' )); 641 span.appendChild(Components.linkifyStringAsFragment(output.description || '' ));
700 642
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after
1262 toMessageElement() { 1204 toMessageElement() {
1263 if (!this._element) { 1205 if (!this._element) {
1264 super.toMessageElement(); 1206 super.toMessageElement();
1265 this._expandGroupIcon = UI.Icon.create('', 'expand-group-icon'); 1207 this._expandGroupIcon = UI.Icon.create('', 'expand-group-icon');
1266 this._contentElement.insertBefore(this._expandGroupIcon, this._contentElem ent.firstChild); 1208 this._contentElement.insertBefore(this._expandGroupIcon, this._contentElem ent.firstChild);
1267 this.setCollapsed(this._collapsed); 1209 this.setCollapsed(this._collapsed);
1268 } 1210 }
1269 return this._element; 1211 return this._element;
1270 } 1212 }
1271 }; 1213 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698