| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 /** | 4 /** |
| 5 * @unrestricted | 5 * @unrestricted |
| 6 */ | 6 */ |
| 7 Components.RemoteObjectPreviewFormatter = class { | 7 Components.RemoteObjectPreviewFormatter = class { |
| 8 /** | 8 /** |
| 9 * @param {!Protocol.Runtime.PropertyPreview} a |
| 10 * @param {!Protocol.Runtime.PropertyPreview} b |
| 11 * @return {number} |
| 12 */ |
| 13 static _objectPropertyComparator(a, b) { |
| 14 if (a.type !== 'function' && b.type === 'function') |
| 15 return -1; |
| 16 if (a.type === 'function' && b.type !== 'function') |
| 17 return 1; |
| 18 return 0; |
| 19 } |
| 20 |
| 21 /** |
| 9 * @param {!Element} parentElement | 22 * @param {!Element} parentElement |
| 10 * @param {!Protocol.Runtime.ObjectPreview} preview | 23 * @param {!Protocol.Runtime.ObjectPreview} preview |
| 11 */ | 24 */ |
| 12 appendObjectPreview(parentElement, preview) { | 25 appendObjectPreview(parentElement, preview) { |
| 13 var description = preview.description; | 26 var description = preview.description; |
| 14 if (preview.type !== 'object' || preview.subtype === 'null') { | 27 if (preview.type !== 'object' || preview.subtype === 'null') { |
| 15 parentElement.appendChild(this.renderPropertyPreview(preview.type, preview
.subtype, description)); | 28 parentElement.appendChild(this.renderPropertyPreview(preview.type, preview
.subtype, description)); |
| 16 return; | 29 return; |
| 17 } | 30 } |
| 18 if (description && preview.subtype !== 'array') | 31 if (description && preview.subtype !== 'array') |
| (...skipping 21 matching lines...) Expand all Loading... |
| 40 for (var i = 0; i < abbreviatedDescription.length - 1; ++i) | 53 for (var i = 0; i < abbreviatedDescription.length - 1; ++i) |
| 41 abbreviatedDescription[i] = abbreviatedDescription[i].trimMiddle(3); | 54 abbreviatedDescription[i] = abbreviatedDescription[i].trimMiddle(3); |
| 42 return abbreviatedDescription.join('.'); | 55 return abbreviatedDescription.join('.'); |
| 43 } | 56 } |
| 44 | 57 |
| 45 /** | 58 /** |
| 46 * @param {!Element} parentElement | 59 * @param {!Element} parentElement |
| 47 * @param {!Protocol.Runtime.ObjectPreview} preview | 60 * @param {!Protocol.Runtime.ObjectPreview} preview |
| 48 */ | 61 */ |
| 49 _appendObjectPropertiesPreview(parentElement, preview) { | 62 _appendObjectPropertiesPreview(parentElement, preview) { |
| 50 var properties = preview.properties.filter(p => p.type !== 'accessor').stabl
eSort(compareFunctionsLast); | 63 var properties = preview.properties.filter(p => p.type !== 'accessor') |
| 51 | 64 .stableSort(Components.RemoteObjectPreviewFormatter._ob
jectPropertyComparator); |
| 52 /** | |
| 53 * @param {!Protocol.Runtime.PropertyPreview} a | |
| 54 * @param {!Protocol.Runtime.PropertyPreview} b | |
| 55 */ | |
| 56 function compareFunctionsLast(a, b) { | |
| 57 if (a.type !== 'function' && b.type === 'function') | |
| 58 return -1; | |
| 59 if (a.type === 'function' && b.type !== 'function') | |
| 60 return 1; | |
| 61 return 0; | |
| 62 } | |
| 63 | |
| 64 for (var i = 0; i < properties.length; ++i) { | 65 for (var i = 0; i < properties.length; ++i) { |
| 65 if (i > 0) | 66 if (i > 0) |
| 66 parentElement.createTextChild(', '); | 67 parentElement.createTextChild(', '); |
| 67 | 68 |
| 68 var property = properties[i]; | 69 var property = properties[i]; |
| 69 parentElement.appendChild(this._renderDisplayName(property.name)); | 70 parentElement.appendChild(this._renderDisplayName(property.name)); |
| 70 parentElement.createTextChild(': '); | 71 parentElement.createTextChild(': '); |
| 71 parentElement.appendChild(this._renderPropertyPreviewOrAccessor([property]
)); | 72 parentElement.appendChild(this._renderPropertyPreviewOrAccessor([property]
)); |
| 72 } | 73 } |
| 73 } | 74 } |
| 74 | 75 |
| 75 /** | 76 /** |
| 76 * @param {!Element} parentElement | 77 * @param {!Element} parentElement |
| 77 * @param {!Protocol.Runtime.ObjectPreview} preview | 78 * @param {!Protocol.Runtime.ObjectPreview} preview |
| 78 */ | 79 */ |
| 79 _appendArrayPropertiesPreview(parentElement, preview) { | 80 _appendArrayPropertiesPreview(parentElement, preview) { |
| 80 var arrayLength = SDK.RemoteObject.arrayLength(preview); | 81 var arrayLength = SDK.RemoteObject.arrayLength(preview); |
| 81 var properties = preview.properties; | 82 var indexProperties = preview.properties.filter(p => toArrayIndex(p.name) !=
= -1).stableSort(arrayEntryComparator); |
| 82 properties = properties.slice().stableSort(compareIndexesFirst); | 83 var otherProperties = preview.properties.filter(p => toArrayIndex(p.name) ==
= -1) |
| 84 .stableSort(Components.RemoteObjectPreviewFormatte
r._objectPropertyComparator); |
| 83 | 85 |
| 84 /** | 86 /** |
| 85 * @param {!Protocol.Runtime.PropertyPreview} a | 87 * @param {!Protocol.Runtime.PropertyPreview} a |
| 86 * @param {!Protocol.Runtime.PropertyPreview} b | 88 * @param {!Protocol.Runtime.PropertyPreview} b |
| 89 * @return {number} |
| 87 */ | 90 */ |
| 88 function compareIndexesFirst(a, b) { | 91 function arrayEntryComparator(a, b) { |
| 89 var index1 = toArrayIndex(a.name); | 92 return toArrayIndex(a.name) - toArrayIndex(b.name); |
| 90 var index2 = toArrayIndex(b.name); | |
| 91 if (index1 < 0) | |
| 92 return index2 < 0 ? 0 : 1; | |
| 93 return index2 < 0 ? -1 : index1 - index2; | |
| 94 } | 93 } |
| 95 | 94 |
| 96 /** | 95 /** |
| 97 * @param {string} name | 96 * @param {string} name |
| 98 * @return {number} | 97 * @return {number} |
| 99 */ | 98 */ |
| 100 function toArrayIndex(name) { | 99 function toArrayIndex(name) { |
| 101 var index = name >>> 0; | 100 var index = name >>> 0; |
| 102 if (String(index) === name && index < arrayLength) | 101 if (String(index) === name && index < arrayLength) |
| 103 return index; | 102 return index; |
| 104 return -1; | 103 return -1; |
| 105 } | 104 } |
| 106 | 105 |
| 107 for (var i = 0; i < properties.length; ++i) { | 106 // Gaps can be shown when all properties are guaranteed to be in the preview
. |
| 108 if (i > 0) | 107 var canShowGaps = !preview.overflow; |
| 108 var lastNonEmptyArrayIndex = -1; |
| 109 var elementsAdded = false; |
| 110 for (var i = 0; i < indexProperties.length; ++i) { |
| 111 if (elementsAdded) |
| 109 parentElement.createTextChild(', '); | 112 parentElement.createTextChild(', '); |
| 110 | 113 |
| 111 var property = properties[i]; | 114 var property = indexProperties[i]; |
| 112 if (property.name !== String(i) || i >= arrayLength) { | 115 var index = toArrayIndex(property.name); |
| 116 if (canShowGaps && index - lastNonEmptyArrayIndex > 1) { |
| 117 appendUndefined(index); |
| 118 parentElement.createTextChild(', '); |
| 119 } |
| 120 if (!canShowGaps && i !== index) { |
| 113 parentElement.appendChild(this._renderDisplayName(property.name)); | 121 parentElement.appendChild(this._renderDisplayName(property.name)); |
| 114 parentElement.createTextChild(': '); | 122 parentElement.createTextChild(': '); |
| 115 } | 123 } |
| 116 parentElement.appendChild(this._renderPropertyPreviewOrAccessor([property]
)); | 124 parentElement.appendChild(this._renderPropertyPreviewOrAccessor([property]
)); |
| 125 lastNonEmptyArrayIndex = index; |
| 126 elementsAdded = true; |
| 127 } |
| 128 |
| 129 if (canShowGaps && arrayLength - lastNonEmptyArrayIndex > 1) { |
| 130 if (elementsAdded) |
| 131 parentElement.createTextChild(', '); |
| 132 appendUndefined(arrayLength); |
| 133 } |
| 134 |
| 135 for (var i = 0; i < otherProperties.length; ++i) { |
| 136 if (elementsAdded) |
| 137 parentElement.createTextChild(', '); |
| 138 |
| 139 var property = otherProperties[i]; |
| 140 parentElement.appendChild(this._renderDisplayName(property.name)); |
| 141 parentElement.createTextChild(': '); |
| 142 parentElement.appendChild(this._renderPropertyPreviewOrAccessor([property]
)); |
| 143 elementsAdded = true; |
| 144 } |
| 145 |
| 146 /** |
| 147 * @param {number} index |
| 148 */ |
| 149 function appendUndefined(index) { |
| 150 var span = parentElement.createChild('span', 'object-value-undefined'); |
| 151 span.textContent = Common.UIString('undefined × %d', index - lastNonEmptyA
rrayIndex - 1); |
| 152 elementsAdded = true; |
| 117 } | 153 } |
| 118 } | 154 } |
| 119 | 155 |
| 120 /** | 156 /** |
| 121 * @param {!Element} parentElement | 157 * @param {!Element} parentElement |
| 122 * @param {!Protocol.Runtime.ObjectPreview} preview | 158 * @param {!Protocol.Runtime.ObjectPreview} preview |
| 123 */ | 159 */ |
| 124 _appendEntriesPreview(parentElement, preview) { | 160 _appendEntriesPreview(parentElement, preview) { |
| 125 for (var i = 0; i < preview.entries.length; ++i) { | 161 for (var i = 0; i < preview.entries.length; ++i) { |
| 126 if (i > 0) | 162 if (i > 0) |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 if (type === 'object' && !subtype) { | 225 if (type === 'object' && !subtype) { |
| 190 span.textContent = this._abbreviateFullQualifiedClassName(description); | 226 span.textContent = this._abbreviateFullQualifiedClassName(description); |
| 191 span.title = description; | 227 span.title = description; |
| 192 return span; | 228 return span; |
| 193 } | 229 } |
| 194 | 230 |
| 195 span.textContent = description; | 231 span.textContent = description; |
| 196 return span; | 232 return span; |
| 197 } | 233 } |
| 198 }; | 234 }; |
| OLD | NEW |