| 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 23 matching lines...) Expand all Loading... |
| 42 for (var i = 0; i < abbreviatedDescription.length - 1; ++i) | 55 for (var i = 0; i < abbreviatedDescription.length - 1; ++i) |
| 43 abbreviatedDescription[i] = abbreviatedDescription[i].trimMiddle(3); | 56 abbreviatedDescription[i] = abbreviatedDescription[i].trimMiddle(3); |
| 44 return abbreviatedDescription.join('.'); | 57 return abbreviatedDescription.join('.'); |
| 45 } | 58 } |
| 46 | 59 |
| 47 /** | 60 /** |
| 48 * @param {!Element} parentElement | 61 * @param {!Element} parentElement |
| 49 * @param {!Protocol.Runtime.ObjectPreview} preview | 62 * @param {!Protocol.Runtime.ObjectPreview} preview |
| 50 */ | 63 */ |
| 51 _appendObjectPropertiesPreview(parentElement, preview) { | 64 _appendObjectPropertiesPreview(parentElement, preview) { |
| 52 var properties = preview.properties.filter(p => p.type !== 'accessor').stabl
eSort(compareFunctionsLast); | 65 var properties = preview.properties.filter(p => p.type !== 'accessor') |
| 53 | 66 .stableSort(Components.RemoteObjectPreviewFormatter._ob
jectPropertyComparator); |
| 54 /** | |
| 55 * @param {!Protocol.Runtime.PropertyPreview} a | |
| 56 * @param {!Protocol.Runtime.PropertyPreview} b | |
| 57 */ | |
| 58 function compareFunctionsLast(a, b) { | |
| 59 if (a.type !== 'function' && b.type === 'function') | |
| 60 return -1; | |
| 61 if (a.type === 'function' && b.type !== 'function') | |
| 62 return 1; | |
| 63 return 0; | |
| 64 } | |
| 65 | |
| 66 for (var i = 0; i < properties.length; ++i) { | 67 for (var i = 0; i < properties.length; ++i) { |
| 67 if (i > 0) | 68 if (i > 0) |
| 68 parentElement.createTextChild(', '); | 69 parentElement.createTextChild(', '); |
| 69 | 70 |
| 70 var property = properties[i]; | 71 var property = properties[i]; |
| 71 parentElement.appendChild(this._renderDisplayName(property.name)); | 72 parentElement.appendChild(this._renderDisplayName(property.name)); |
| 72 parentElement.createTextChild(': '); | 73 parentElement.createTextChild(': '); |
| 73 parentElement.appendChild(this._renderPropertyPreviewOrAccessor([property]
)); | 74 parentElement.appendChild(this._renderPropertyPreviewOrAccessor([property]
)); |
| 74 } | 75 } |
| 75 } | 76 } |
| 76 | 77 |
| 77 /** | 78 /** |
| 78 * @param {!Element} parentElement | 79 * @param {!Element} parentElement |
| 79 * @param {!Protocol.Runtime.ObjectPreview} preview | 80 * @param {!Protocol.Runtime.ObjectPreview} preview |
| 80 */ | 81 */ |
| 81 _appendArrayPropertiesPreview(parentElement, preview) { | 82 _appendArrayPropertiesPreview(parentElement, preview) { |
| 82 var arrayLength = SDK.RemoteObject.arrayLength(preview); | 83 var arrayLength = SDK.RemoteObject.arrayLength(preview); |
| 83 var properties = preview.properties; | 84 var properties = preview.properties; |
| 84 properties = properties.slice().stableSort(compareIndexesFirst); | 85 var indexProperties = properties.filter(p => toArrayIndex(p.name) !== -1).st
ableSort(arrayPropertyComparator); |
| 86 var otherProperties = properties.filter(p => toArrayIndex(p.name) === -1) |
| 87 .stableSort(Components.RemoteObjectPreviewFormatte
r._objectPropertyComparator); |
| 85 | 88 |
| 86 /** | 89 /** |
| 87 * @param {!Protocol.Runtime.PropertyPreview} a | 90 * @param {!Protocol.Runtime.PropertyPreview} a |
| 88 * @param {!Protocol.Runtime.PropertyPreview} b | 91 * @param {!Protocol.Runtime.PropertyPreview} b |
| 92 * @return {number} |
| 89 */ | 93 */ |
| 90 function compareIndexesFirst(a, b) { | 94 function arrayPropertyComparator(a, b) { |
| 91 var index1 = toArrayIndex(a.name); | 95 return toArrayIndex(a.name) - toArrayIndex(b.name); |
| 92 var index2 = toArrayIndex(b.name); | |
| 93 if (index1 < 0) | |
| 94 return index2 < 0 ? 0 : 1; | |
| 95 return index2 < 0 ? -1 : index1 - index2; | |
| 96 } | 96 } |
| 97 | 97 |
| 98 /** | 98 /** |
| 99 * @param {string} name | 99 * @param {string} name |
| 100 * @return {number} | 100 * @return {number} |
| 101 */ | 101 */ |
| 102 function toArrayIndex(name) { | 102 function toArrayIndex(name) { |
| 103 var index = name >>> 0; | 103 var index = name >>> 0; |
| 104 if (String(index) === name && index < arrayLength) | 104 if (String(index) === name && index < arrayLength) |
| 105 return index; | 105 return index; |
| 106 return -1; | 106 return -1; |
| 107 } | 107 } |
| 108 | 108 |
| 109 for (var i = 0; i < properties.length; ++i) { | 109 var lastNonEmptyArrayIndex = -1; |
| 110 var property; |
| 111 for (var i = 0; i < indexProperties.length; ++i) { |
| 110 if (i > 0) | 112 if (i > 0) |
| 111 parentElement.createTextChild(', '); | 113 parentElement.createTextChild(', '); |
| 114 property = indexProperties[i]; |
| 115 var index = toArrayIndex(property.name); |
| 116 if (index - lastNonEmptyArrayIndex > 1) { |
| 117 appendUndefined(index); |
| 118 parentElement.createTextChild(', '); |
| 119 } |
| 120 lastNonEmptyArrayIndex = index; |
| 121 parentElement.appendChild(this._renderPropertyPreviewOrAccessor([property]
)); |
| 122 } |
| 112 | 123 |
| 113 var property = properties[i]; | 124 var elementsAdded = indexProperties.length > 0; |
| 114 if (property.name !== String(i) || i >= arrayLength) { | 125 if (arrayLength - lastNonEmptyArrayIndex > 1) { |
| 115 parentElement.appendChild(this._renderDisplayName(property.name)); | 126 if (lastNonEmptyArrayIndex > -1) |
| 116 parentElement.createTextChild(': '); | 127 parentElement.createTextChild(', '); |
| 117 } | 128 appendUndefined(arrayLength); |
| 129 elementsAdded = true; |
| 130 } |
| 131 |
| 132 for (var i = 0; i < otherProperties.length; ++i) { |
| 133 if (elementsAdded || i > 0) |
| 134 parentElement.createTextChild(', '); |
| 135 property = otherProperties[i]; |
| 136 parentElement.appendChild(this._renderDisplayName(property.name)); |
| 137 parentElement.createTextChild(': '); |
| 118 parentElement.appendChild(this._renderPropertyPreviewOrAccessor([property]
)); | 138 parentElement.appendChild(this._renderPropertyPreviewOrAccessor([property]
)); |
| 119 } | 139 } |
| 140 |
| 141 /** |
| 142 * @param {number} index |
| 143 */ |
| 144 function appendUndefined(index) { |
| 145 var span = parentElement.createChild('span', 'object-value-undefined'); |
| 146 span.textContent = Common.UIString('undefined × %d', index - lastNonEmptyA
rrayIndex - 1); |
| 147 } |
| 120 } | 148 } |
| 121 | 149 |
| 122 /** | 150 /** |
| 123 * @param {!Element} parentElement | 151 * @param {!Element} parentElement |
| 124 * @param {!Protocol.Runtime.ObjectPreview} preview | 152 * @param {!Protocol.Runtime.ObjectPreview} preview |
| 125 */ | 153 */ |
| 126 _appendEntriesPreview(parentElement, preview) { | 154 _appendEntriesPreview(parentElement, preview) { |
| 127 for (var i = 0; i < preview.entries.length; ++i) { | 155 for (var i = 0; i < preview.entries.length; ++i) { |
| 128 if (i > 0) | 156 if (i > 0) |
| 129 parentElement.createTextChild(', '); | 157 parentElement.createTextChild(', '); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 | 218 |
| 191 if (type === 'object' && !subtype) { | 219 if (type === 'object' && !subtype) { |
| 192 span.textContent = this._abbreviateFullQualifiedClassName(description); | 220 span.textContent = this._abbreviateFullQualifiedClassName(description); |
| 193 return span; | 221 return span; |
| 194 } | 222 } |
| 195 | 223 |
| 196 span.textContent = description; | 224 span.textContent = description; |
| 197 return span; | 225 return span; |
| 198 } | 226 } |
| 199 }; | 227 }; |
| OLD | NEW |