Chromium Code Reviews| Index: third_party/WebKit/Source/devtools/front_end/components/RemoteObjectPreviewFormatter.js |
| diff --git a/third_party/WebKit/Source/devtools/front_end/components/RemoteObjectPreviewFormatter.js b/third_party/WebKit/Source/devtools/front_end/components/RemoteObjectPreviewFormatter.js |
| index 54b36b0506c204d162804a7155aecbb6f9195e9d..880c626605781f5068420adf098b72df9b4445e1 100644 |
| --- a/third_party/WebKit/Source/devtools/front_end/components/RemoteObjectPreviewFormatter.js |
| +++ b/third_party/WebKit/Source/devtools/front_end/components/RemoteObjectPreviewFormatter.js |
| @@ -6,6 +6,19 @@ |
| */ |
| Components.RemoteObjectPreviewFormatter = class { |
| /** |
| + * @param {!Protocol.Runtime.PropertyPreview} a |
| + * @param {!Protocol.Runtime.PropertyPreview} b |
| + * @return {number} |
| + */ |
| + static objectPropertyComparator(a, b) { |
|
lushnikov
2016/12/12 22:10:43
should it be private?
luoe
2016/12/13 03:57:35
Done.
|
| + if (a.type !== 'function' && b.type === 'function') |
| + return -1; |
| + if (a.type === 'function' && b.type !== 'function') |
| + return 1; |
| + return 0; |
| + } |
| + |
| + /** |
| * @param {!Element} parentElement |
| * @param {!Protocol.Runtime.ObjectPreview} preview |
| */ |
| @@ -49,20 +62,8 @@ Components.RemoteObjectPreviewFormatter = class { |
| * @param {!Protocol.Runtime.ObjectPreview} preview |
| */ |
| _appendObjectPropertiesPreview(parentElement, preview) { |
| - var properties = preview.properties.filter(p => p.type !== 'accessor').stableSort(compareFunctionsLast); |
| - |
| - /** |
| - * @param {!Protocol.Runtime.PropertyPreview} a |
| - * @param {!Protocol.Runtime.PropertyPreview} b |
| - */ |
| - function compareFunctionsLast(a, b) { |
| - if (a.type !== 'function' && b.type === 'function') |
| - return -1; |
| - if (a.type === 'function' && b.type !== 'function') |
| - return 1; |
| - return 0; |
| - } |
| - |
| + var properties = preview.properties.filter(p => p.type !== 'accessor') |
| + .stableSort(Components.RemoteObjectPreviewFormatter.objectPropertyComparator); |
| for (var i = 0; i < properties.length; ++i) { |
| if (i > 0) |
| parentElement.createTextChild(', '); |
| @@ -80,20 +81,9 @@ Components.RemoteObjectPreviewFormatter = class { |
| */ |
| _appendArrayPropertiesPreview(parentElement, preview) { |
| var arrayLength = SDK.RemoteObject.arrayLength(preview); |
| - var properties = preview.properties; |
| - properties = properties.slice().stableSort(compareIndexesFirst); |
| - |
| - /** |
| - * @param {!Protocol.Runtime.PropertyPreview} a |
| - * @param {!Protocol.Runtime.PropertyPreview} b |
| - */ |
| - function compareIndexesFirst(a, b) { |
| - var index1 = toArrayIndex(a.name); |
| - var index2 = toArrayIndex(b.name); |
| - if (index1 < 0) |
| - return index2 < 0 ? 0 : 1; |
| - return index2 < 0 ? -1 : index1 - index2; |
| - } |
| + var indexProperties = preview.properties.filter(p => toArrayIndex(p.name) !== -1).stableSort(); |
|
lushnikov
2016/12/12 22:10:43
don't you need to pass in comparator here as well?
luoe
2016/12/13 03:57:35
Done.
|
| + var otherProperties = preview.properties.filter(p => toArrayIndex(p.name) === -1) |
| + .stableSort(Components.RemoteObjectPreviewFormatter.objectPropertyComparator); |
| /** |
| * @param {string} name |
| @@ -106,17 +96,45 @@ Components.RemoteObjectPreviewFormatter = class { |
| return -1; |
| } |
| - for (var i = 0; i < properties.length; ++i) { |
| + var lastNonEmptyArrayIndex = -1; |
| + var property; |
| + for (var i = 0; i < indexProperties.length; ++i) { |
| if (i > 0) |
| parentElement.createTextChild(', '); |
| - |
| - var property = properties[i]; |
| - if (property.name !== String(i) || i >= arrayLength) { |
| - parentElement.appendChild(this._renderDisplayName(property.name)); |
| - parentElement.createTextChild(': '); |
| + property = indexProperties[i]; |
| + var index = toArrayIndex(property.name); |
| + if (index - lastNonEmptyArrayIndex > 1) { |
| + appendUndefined(index); |
| + parentElement.createTextChild(', '); |
| } |
| + lastNonEmptyArrayIndex = index; |
| parentElement.appendChild(this._renderPropertyPreviewOrAccessor([property])); |
| } |
| + |
| + var elementsAdded = indexProperties.length > 0; |
| + if (arrayLength - lastNonEmptyArrayIndex > 1) { |
| + if (lastNonEmptyArrayIndex > -1) |
| + parentElement.createTextChild(', '); |
| + appendUndefined(arrayLength); |
| + elementsAdded = true; |
| + } |
| + |
| + for (var i = 0; i < otherProperties.length; ++i) { |
| + if (elementsAdded || i > 0) |
| + parentElement.createTextChild(', '); |
| + property = otherProperties[i]; |
| + parentElement.appendChild(this._renderDisplayName(property.name)); |
| + parentElement.createTextChild(': '); |
| + parentElement.appendChild(this._renderPropertyPreviewOrAccessor([property])); |
| + } |
| + |
| + /** |
| + * @param {number} index |
| + */ |
| + function appendUndefined(index) { |
| + var span = parentElement.createChild('span', 'object-value-undefined'); |
| + span.textContent = Common.UIString('undefined × %d', index - lastNonEmptyArrayIndex - 1); |
| + } |
| } |
| /** |