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

Unified Diff: third_party/WebKit/Source/devtools/front_end/components/RemoteObjectPreviewFormatter.js

Issue 2515913002: DevTools: object formatter renders arrays the same way as printArrayResult() (Closed)
Patch Set: DevTools: object formatter renders arrays the same way as printArrayResult() Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/inspector/sources/debugger-ui/debugger-inline-values-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 40c57590953542fb5f39dbb1c92aae913e42ddd1..d699ac7ab4ae2f8344bf17043dd920dd55d44fdf 100644
--- a/third_party/WebKit/Source/devtools/front_end/components/RemoteObjectPreviewFormatter.js
+++ b/third_party/WebKit/Source/devtools/front_end/components/RemoteObjectPreviewFormatter.js
@@ -16,14 +16,22 @@ Components.RemoteObjectPreviewFormatter = class {
parentElement.appendChild(this.renderPropertyPreview(preview.type, preview.subtype, description));
return;
}
- if (description && preview.subtype !== 'array' && preview.subtype !== 'typedarray') {
+ var isArray = preview.subtype === 'array' || preview.subtype === 'typedarray';
+ if (description && !isArray) {
var text = preview.subtype ? description : this._abbreviateFullQualifiedClassName(description);
parentElement.createTextChildren(text, ' ');
}
+
+ parentElement.createTextChild(isArray ? '[' : '{');
if (preview.entries)
this._appendEntriesPreview(parentElement, preview);
+ else if (isArray)
+ this._appendArrayPropertiesPreview(parentElement, preview, objectForAccessing);
else
this._appendPropertiesPreview(parentElement, preview, objectForAccessing);
+ if (preview.overflow)
+ parentElement.createChild('span').textContent = '\u2026';
+ parentElement.createTextChild(isArray ? ']' : '}');
}
/**
@@ -43,13 +51,7 @@ Components.RemoteObjectPreviewFormatter = class {
* @param {!SDK.RemoteObject=} objectForAccessing
*/
_appendPropertiesPreview(parentElement, preview, objectForAccessing) {
- var isArray = preview.subtype === 'array' || preview.subtype === 'typedarray';
- var arrayLength = SDK.RemoteObject.arrayLength(preview);
- var properties = preview.properties;
- if (isArray)
- properties = properties.slice().stableSort(compareIndexesFirst);
- else
- properties = properties.slice().stableSort(compareFunctionsLast);
+ var properties = preview.properties.slice().stableSort(compareFunctionsLast);
/**
* @param {!Protocol.Runtime.PropertyPreview} a
@@ -63,6 +65,59 @@ Components.RemoteObjectPreviewFormatter = class {
return 0;
}
+ for (var i = 0; i < properties.length; ++i) {
+ if (i > 0)
+ parentElement.createTextChild(', ');
+
+ var property = properties[i];
+ var name = property.name;
+ if (/^\s|\s$|^$|\n/.test(name))
+ parentElement.createChild('span', 'name').createTextChildren('"', name.replace(/\n/g, '\u21B5'), '"');
+ else
+ parentElement.createChild('span', 'name').textContent = name;
+ parentElement.createTextChild(': ');
+ parentElement.appendChild(this.renderPropertyPreviewOrAccessor([property], objectForAccessing));
+ }
+ }
+
+ /**
+ * @param {!Element} parentElement
+ * @param {!Protocol.Runtime.ObjectPreview} preview
+ * @param {!SDK.RemoteObject=} objectForAccessing
+ */
+ _appendArrayPropertiesPreview(parentElement, preview, objectForAccessing) {
+ var arrayLength = SDK.RemoteObject.arrayLength(preview);
+ var properties = preview.properties.slice().stableSort(compareIndexesFirst);
+ var lastNonEmptyArrayIndex = -1;
+ for (var i = 0; i < properties.length; ++i) {
+ var property = properties[i];
+ var name = property.name;
+ if (isNaN(name))
+ continue;
+ if (i > 0)
+ parentElement.createTextChild(', ');
+ var index = parseInt(name, 10);
+ if (index - lastNonEmptyArrayIndex > 1) {
+ appendUndefined(index);
+ parentElement.createTextChild(', ');
+ }
+ parentElement.appendChild(this.renderPropertyPreviewOrAccessor([property], objectForAccessing));
+ lastNonEmptyArrayIndex = index;
+ }
+ if (lastNonEmptyArrayIndex > -1 && arrayLength - lastNonEmptyArrayIndex > 1) {
+ parentElement.createTextChild(', ');
+ appendUndefined(arrayLength);
+ }
+
+ /**
+ * @param {number} index
+ */
+ function appendUndefined(index) {
+ var span = parentElement.createChild('span', 'object-value-undefined');
+ var gapSize = index - lastNonEmptyArrayIndex - 1;
+ span.textContent = gapSize > 1 ? Common.UIString('undefined × %d', gapSize) : Common.UIString('undefined');
+ }
+
/**
* @param {!Protocol.Runtime.PropertyPreview} a
* @param {!Protocol.Runtime.PropertyPreview} b
@@ -85,27 +140,6 @@ Components.RemoteObjectPreviewFormatter = class {
return index;
return -1;
}
-
- parentElement.createTextChild(isArray ? '[' : '{');
- for (var i = 0; i < properties.length; ++i) {
- if (i > 0)
- parentElement.createTextChild(', ');
-
- var property = properties[i];
- var name = property.name;
- if (!isArray || name !== String(i) || i >= arrayLength) {
- if (/^\s|\s$|^$|\n/.test(name))
- parentElement.createChild('span', 'name').createTextChildren('"', name.replace(/\n/g, '\u21B5'), '"');
- else
- parentElement.createChild('span', 'name').textContent = name;
- parentElement.createTextChild(': ');
- }
-
- parentElement.appendChild(this.renderPropertyPreviewOrAccessor([property], objectForAccessing));
- }
- if (preview.overflow)
- parentElement.createChild('span').textContent = '\u2026';
- parentElement.createTextChild(isArray ? ']' : '}');
}
/**
@@ -113,7 +147,6 @@ Components.RemoteObjectPreviewFormatter = class {
* @param {!Protocol.Runtime.ObjectPreview} preview
*/
_appendEntriesPreview(parentElement, preview) {
- parentElement.createTextChild('{');
for (var i = 0; i < preview.entries.length; ++i) {
if (i > 0)
parentElement.createTextChild(', ');
@@ -125,9 +158,6 @@ Components.RemoteObjectPreviewFormatter = class {
}
this.appendObjectPreview(parentElement, entry.value);
}
- if (preview.overflow)
- parentElement.createChild('span').textContent = '\u2026';
- parentElement.createTextChild('}');
}
/**
« no previous file with comments | « third_party/WebKit/LayoutTests/inspector/sources/debugger-ui/debugger-inline-values-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698