| 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 /** | |
| 22 * @param {!Element} parentElement | 9 * @param {!Element} parentElement |
| 23 * @param {!Protocol.Runtime.ObjectPreview} preview | 10 * @param {!Protocol.Runtime.ObjectPreview} preview |
| 24 */ | 11 */ |
| 25 appendObjectPreview(parentElement, preview) { | 12 appendObjectPreview(parentElement, preview) { |
| 26 var description = preview.description; | 13 var description = preview.description; |
| 27 if (preview.type !== 'object' || preview.subtype === 'null') { | 14 if (preview.type !== 'object' || preview.subtype === 'null') { |
| 28 parentElement.appendChild(this.renderPropertyPreview(preview.type, preview
.subtype, description)); | 15 parentElement.appendChild(this.renderPropertyPreview(preview.type, preview
.subtype, description)); |
| 29 return; | 16 return; |
| 30 } | 17 } |
| 31 if (description && preview.subtype !== 'array') { | 18 if (description && preview.subtype !== 'array') { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 55 for (var i = 0; i < abbreviatedDescription.length - 1; ++i) | 42 for (var i = 0; i < abbreviatedDescription.length - 1; ++i) |
| 56 abbreviatedDescription[i] = abbreviatedDescription[i].trimMiddle(3); | 43 abbreviatedDescription[i] = abbreviatedDescription[i].trimMiddle(3); |
| 57 return abbreviatedDescription.join('.'); | 44 return abbreviatedDescription.join('.'); |
| 58 } | 45 } |
| 59 | 46 |
| 60 /** | 47 /** |
| 61 * @param {!Element} parentElement | 48 * @param {!Element} parentElement |
| 62 * @param {!Protocol.Runtime.ObjectPreview} preview | 49 * @param {!Protocol.Runtime.ObjectPreview} preview |
| 63 */ | 50 */ |
| 64 _appendObjectPropertiesPreview(parentElement, preview) { | 51 _appendObjectPropertiesPreview(parentElement, preview) { |
| 65 var properties = preview.properties.filter(p => p.type !== 'accessor') | 52 var properties = preview.properties.filter(p => p.type !== 'accessor').stabl
eSort(compareFunctionsLast); |
| 66 .stableSort(Components.RemoteObjectPreviewFormatter._ob
jectPropertyComparator); | 53 |
| 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 |
| 67 for (var i = 0; i < properties.length; ++i) { | 66 for (var i = 0; i < properties.length; ++i) { |
| 68 if (i > 0) | 67 if (i > 0) |
| 69 parentElement.createTextChild(', '); | 68 parentElement.createTextChild(', '); |
| 70 | 69 |
| 71 var property = properties[i]; | 70 var property = properties[i]; |
| 72 parentElement.appendChild(this._renderDisplayName(property.name)); | 71 parentElement.appendChild(this._renderDisplayName(property.name)); |
| 73 parentElement.createTextChild(': '); | 72 parentElement.createTextChild(': '); |
| 74 parentElement.appendChild(this._renderPropertyPreviewOrAccessor([property]
)); | 73 parentElement.appendChild(this._renderPropertyPreviewOrAccessor([property]
)); |
| 75 } | 74 } |
| 76 } | 75 } |
| 77 | 76 |
| 78 /** | 77 /** |
| 79 * @param {!Element} parentElement | 78 * @param {!Element} parentElement |
| 80 * @param {!Protocol.Runtime.ObjectPreview} preview | 79 * @param {!Protocol.Runtime.ObjectPreview} preview |
| 81 */ | 80 */ |
| 82 _appendArrayPropertiesPreview(parentElement, preview) { | 81 _appendArrayPropertiesPreview(parentElement, preview) { |
| 83 var arrayLength = SDK.RemoteObject.arrayLength(preview); | 82 var arrayLength = SDK.RemoteObject.arrayLength(preview); |
| 84 var properties = preview.properties; | 83 var properties = preview.properties; |
| 85 var indexProperties = properties.filter(p => toArrayIndex(p.name) !== -1).st
ableSort(arrayPropertyComparator); | 84 properties = properties.slice().stableSort(compareIndexesFirst); |
| 86 var otherProperties = properties.filter(p => toArrayIndex(p.name) === -1) | |
| 87 .stableSort(Components.RemoteObjectPreviewFormatte
r._objectPropertyComparator); | |
| 88 | 85 |
| 89 /** | 86 /** |
| 90 * @param {!Protocol.Runtime.PropertyPreview} a | 87 * @param {!Protocol.Runtime.PropertyPreview} a |
| 91 * @param {!Protocol.Runtime.PropertyPreview} b | 88 * @param {!Protocol.Runtime.PropertyPreview} b |
| 92 * @return {number} | |
| 93 */ | 89 */ |
| 94 function arrayPropertyComparator(a, b) { | 90 function compareIndexesFirst(a, b) { |
| 95 return toArrayIndex(a.name) - toArrayIndex(b.name); | 91 var index1 = toArrayIndex(a.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 var lastNonEmptyArrayIndex = -1; | 109 for (var i = 0; i < properties.length; ++i) { |
| 110 var property; | |
| 111 for (var i = 0; i < indexProperties.length; ++i) { | |
| 112 if (i > 0) | 110 if (i > 0) |
| 113 parentElement.createTextChild(', '); | 111 parentElement.createTextChild(', '); |
| 114 property = indexProperties[i]; | 112 |
| 115 var index = toArrayIndex(property.name); | 113 var property = properties[i]; |
| 116 if (index - lastNonEmptyArrayIndex > 1) { | 114 if (property.name !== String(i) || i >= arrayLength) { |
| 117 appendUndefined(index); | 115 parentElement.appendChild(this._renderDisplayName(property.name)); |
| 118 parentElement.createTextChild(', '); | 116 parentElement.createTextChild(': '); |
| 119 } | 117 } |
| 120 lastNonEmptyArrayIndex = index; | |
| 121 parentElement.appendChild(this._renderPropertyPreviewOrAccessor([property]
)); | 118 parentElement.appendChild(this._renderPropertyPreviewOrAccessor([property]
)); |
| 122 } | 119 } |
| 123 | |
| 124 var elementsAdded = indexProperties.length > 0; | |
| 125 if (arrayLength - lastNonEmptyArrayIndex > 1) { | |
| 126 if (lastNonEmptyArrayIndex > -1) | |
| 127 parentElement.createTextChild(', '); | |
| 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(': '); | |
| 138 parentElement.appendChild(this._renderPropertyPreviewOrAccessor([property]
)); | |
| 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 } | |
| 148 } | 120 } |
| 149 | 121 |
| 150 /** | 122 /** |
| 151 * @param {!Element} parentElement | 123 * @param {!Element} parentElement |
| 152 * @param {!Protocol.Runtime.ObjectPreview} preview | 124 * @param {!Protocol.Runtime.ObjectPreview} preview |
| 153 */ | 125 */ |
| 154 _appendEntriesPreview(parentElement, preview) { | 126 _appendEntriesPreview(parentElement, preview) { |
| 155 for (var i = 0; i < preview.entries.length; ++i) { | 127 for (var i = 0; i < preview.entries.length; ++i) { |
| 156 if (i > 0) | 128 if (i > 0) |
| 157 parentElement.createTextChild(', '); | 129 parentElement.createTextChild(', '); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 | 190 |
| 219 if (type === 'object' && !subtype) { | 191 if (type === 'object' && !subtype) { |
| 220 span.textContent = this._abbreviateFullQualifiedClassName(description); | 192 span.textContent = this._abbreviateFullQualifiedClassName(description); |
| 221 return span; | 193 return span; |
| 222 } | 194 } |
| 223 | 195 |
| 224 span.textContent = description; | 196 span.textContent = description; |
| 225 return span; | 197 return span; |
| 226 } | 198 } |
| 227 }; | 199 }; |
| OLD | NEW |