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 a3e780d336f72591d36fa8cde1676b598cad1bba..40c57590953542fb5f39dbb1c92aae913e42ddd1 100644 |
--- a/third_party/WebKit/Source/devtools/front_end/components/RemoteObjectPreviewFormatter.js |
+++ b/third_party/WebKit/Source/devtools/front_end/components/RemoteObjectPreviewFormatter.js |
@@ -8,8 +8,9 @@ Components.RemoteObjectPreviewFormatter = class { |
/** |
* @param {!Element} parentElement |
* @param {!Protocol.Runtime.ObjectPreview} preview |
+ * @param {!SDK.RemoteObject=} objectForAccessing |
*/ |
- appendObjectPreview(parentElement, preview) { |
+ appendObjectPreview(parentElement, preview, objectForAccessing) { |
var description = preview.description; |
if (preview.type !== 'object' || preview.subtype === 'null') { |
parentElement.appendChild(this.renderPropertyPreview(preview.type, preview.subtype, description)); |
@@ -22,7 +23,7 @@ Components.RemoteObjectPreviewFormatter = class { |
if (preview.entries) |
this._appendEntriesPreview(parentElement, preview); |
else |
- this._appendPropertiesPreview(parentElement, preview); |
+ this._appendPropertiesPreview(parentElement, preview, objectForAccessing); |
} |
/** |
@@ -39,8 +40,9 @@ Components.RemoteObjectPreviewFormatter = class { |
/** |
* @param {!Element} parentElement |
* @param {!Protocol.Runtime.ObjectPreview} preview |
+ * @param {!SDK.RemoteObject=} objectForAccessing |
*/ |
- _appendPropertiesPreview(parentElement, preview) { |
+ _appendPropertiesPreview(parentElement, preview, objectForAccessing) { |
var isArray = preview.subtype === 'array' || preview.subtype === 'typedarray'; |
var arrayLength = SDK.RemoteObject.arrayLength(preview); |
var properties = preview.properties; |
@@ -99,7 +101,7 @@ Components.RemoteObjectPreviewFormatter = class { |
parentElement.createTextChild(': '); |
} |
- parentElement.appendChild(this._renderPropertyPreviewOrAccessor([property])); |
+ parentElement.appendChild(this.renderPropertyPreviewOrAccessor([property], objectForAccessing)); |
} |
if (preview.overflow) |
parentElement.createChild('span').textContent = '\u2026'; |
@@ -130,10 +132,13 @@ Components.RemoteObjectPreviewFormatter = class { |
/** |
* @param {!Array.<!Protocol.Runtime.PropertyPreview>} propertyPath |
+ * @param {!SDK.RemoteObject=} objectForAccessing |
* @return {!Element} |
*/ |
- _renderPropertyPreviewOrAccessor(propertyPath) { |
+ renderPropertyPreviewOrAccessor(propertyPath, objectForAccessing) { |
var property = propertyPath.peekLast(); |
+ if (property.type === 'accessor' && objectForAccessing) |
+ return this.formatAsAccessorProperty([property.name], objectForAccessing); |
return this.renderPropertyPreview(property.type, /** @type {string} */ (property.subtype), property.value); |
} |
@@ -170,4 +175,45 @@ Components.RemoteObjectPreviewFormatter = class { |
span.textContent = description; |
return span; |
} |
+ |
+ /** |
+ * @param {!Array.<string>} propertyPath |
+ * @param {?SDK.RemoteObject} object |
+ * @return {!Element} |
+ */ |
+ formatAsAccessorProperty(propertyPath, object) { |
+ var rootElement = Components.ObjectPropertyTreeElement.createRemoteObjectAccessorPropertySpan( |
+ object, propertyPath, onInvokeGetterClick.bind(this)); |
+ |
+ /** |
+ * @param {?SDK.RemoteObject} result |
+ * @param {boolean=} wasThrown |
+ * @this {Components.RemoteObjectPreviewFormatter} |
+ */ |
+ function onInvokeGetterClick(result, wasThrown) { |
+ if (!result) |
+ return; |
+ rootElement.removeChildren(); |
+ if (wasThrown) { |
+ var element = rootElement.createChild('span'); |
+ element.textContent = Common.UIString('<exception>'); |
+ element.title = /** @type {string} */ (result.description); |
+ } else { |
+ // Make a PropertyPreview from the RemoteObject similar to the backend logic. |
+ const maxLength = 100; |
+ var type = result.type; |
+ var subtype = result.subtype; |
+ var description = ''; |
+ if (type !== 'function' && result.description) { |
+ if (type === 'string' || subtype === 'regexp') |
+ description = result.description.trimMiddle(maxLength); |
+ else |
+ description = result.description.trimEnd(maxLength); |
+ } |
+ rootElement.appendChild(this.renderPropertyPreview(type, subtype, description)); |
+ } |
+ } |
+ |
+ return rootElement; |
+ } |
}; |