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

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

Issue 2514893004: DevTools: show array entries that are getters (Closed)
Patch Set: Add needsManualRebase to TE 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 unified diff | Download patch
OLDNEW
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 {!Element} parentElement 9 * @param {!Element} parentElement
10 * @param {!Protocol.Runtime.ObjectPreview} preview 10 * @param {!Protocol.Runtime.ObjectPreview} preview
11 * @param {!SDK.RemoteObject=} objectForAccessing
11 */ 12 */
12 appendObjectPreview(parentElement, preview) { 13 appendObjectPreview(parentElement, preview, objectForAccessing) {
13 var description = preview.description; 14 var description = preview.description;
14 if (preview.type !== 'object' || preview.subtype === 'null') { 15 if (preview.type !== 'object' || preview.subtype === 'null') {
15 parentElement.appendChild(this.renderPropertyPreview(preview.type, preview .subtype, description)); 16 parentElement.appendChild(this.renderPropertyPreview(preview.type, preview .subtype, description));
16 return; 17 return;
17 } 18 }
18 if (description && preview.subtype !== 'array' && preview.subtype !== 'typed array') { 19 if (description && preview.subtype !== 'array' && preview.subtype !== 'typed array') {
19 var text = preview.subtype ? description : this._abbreviateFullQualifiedCl assName(description); 20 var text = preview.subtype ? description : this._abbreviateFullQualifiedCl assName(description);
20 parentElement.createTextChildren(text, ' '); 21 parentElement.createTextChildren(text, ' ');
21 } 22 }
22 if (preview.entries) 23 if (preview.entries)
23 this._appendEntriesPreview(parentElement, preview); 24 this._appendEntriesPreview(parentElement, preview);
24 else 25 else
25 this._appendPropertiesPreview(parentElement, preview); 26 this._appendPropertiesPreview(parentElement, preview, objectForAccessing);
26 } 27 }
27 28
28 /** 29 /**
29 * @param {string} description 30 * @param {string} description
30 * @return {string} 31 * @return {string}
31 */ 32 */
32 _abbreviateFullQualifiedClassName(description) { 33 _abbreviateFullQualifiedClassName(description) {
33 var abbreviatedDescription = description.split('.'); 34 var abbreviatedDescription = description.split('.');
34 for (var i = 0; i < abbreviatedDescription.length - 1; ++i) 35 for (var i = 0; i < abbreviatedDescription.length - 1; ++i)
35 abbreviatedDescription[i] = abbreviatedDescription[i].trimMiddle(3); 36 abbreviatedDescription[i] = abbreviatedDescription[i].trimMiddle(3);
36 return abbreviatedDescription.join('.'); 37 return abbreviatedDescription.join('.');
37 } 38 }
38 39
39 /** 40 /**
40 * @param {!Element} parentElement 41 * @param {!Element} parentElement
41 * @param {!Protocol.Runtime.ObjectPreview} preview 42 * @param {!Protocol.Runtime.ObjectPreview} preview
43 * @param {!SDK.RemoteObject=} objectForAccessing
42 */ 44 */
43 _appendPropertiesPreview(parentElement, preview) { 45 _appendPropertiesPreview(parentElement, preview, objectForAccessing) {
44 var isArray = preview.subtype === 'array' || preview.subtype === 'typedarray '; 46 var isArray = preview.subtype === 'array' || preview.subtype === 'typedarray ';
45 var arrayLength = SDK.RemoteObject.arrayLength(preview); 47 var arrayLength = SDK.RemoteObject.arrayLength(preview);
46 var properties = preview.properties; 48 var properties = preview.properties;
47 if (isArray) 49 if (isArray)
48 properties = properties.slice().stableSort(compareIndexesFirst); 50 properties = properties.slice().stableSort(compareIndexesFirst);
49 else 51 else
50 properties = properties.slice().stableSort(compareFunctionsLast); 52 properties = properties.slice().stableSort(compareFunctionsLast);
51 53
52 /** 54 /**
53 * @param {!Protocol.Runtime.PropertyPreview} a 55 * @param {!Protocol.Runtime.PropertyPreview} a
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 var property = properties[i]; 94 var property = properties[i];
93 var name = property.name; 95 var name = property.name;
94 if (!isArray || name !== String(i) || i >= arrayLength) { 96 if (!isArray || name !== String(i) || i >= arrayLength) {
95 if (/^\s|\s$|^$|\n/.test(name)) 97 if (/^\s|\s$|^$|\n/.test(name))
96 parentElement.createChild('span', 'name').createTextChildren('"', name .replace(/\n/g, '\u21B5'), '"'); 98 parentElement.createChild('span', 'name').createTextChildren('"', name .replace(/\n/g, '\u21B5'), '"');
97 else 99 else
98 parentElement.createChild('span', 'name').textContent = name; 100 parentElement.createChild('span', 'name').textContent = name;
99 parentElement.createTextChild(': '); 101 parentElement.createTextChild(': ');
100 } 102 }
101 103
102 parentElement.appendChild(this._renderPropertyPreviewOrAccessor([property] )); 104 parentElement.appendChild(this.renderPropertyPreviewOrAccessor([property], objectForAccessing));
103 } 105 }
104 if (preview.overflow) 106 if (preview.overflow)
105 parentElement.createChild('span').textContent = '\u2026'; 107 parentElement.createChild('span').textContent = '\u2026';
106 parentElement.createTextChild(isArray ? ']' : '}'); 108 parentElement.createTextChild(isArray ? ']' : '}');
107 } 109 }
108 110
109 /** 111 /**
110 * @param {!Element} parentElement 112 * @param {!Element} parentElement
111 * @param {!Protocol.Runtime.ObjectPreview} preview 113 * @param {!Protocol.Runtime.ObjectPreview} preview
112 */ 114 */
(...skipping 10 matching lines...) Expand all
123 } 125 }
124 this.appendObjectPreview(parentElement, entry.value); 126 this.appendObjectPreview(parentElement, entry.value);
125 } 127 }
126 if (preview.overflow) 128 if (preview.overflow)
127 parentElement.createChild('span').textContent = '\u2026'; 129 parentElement.createChild('span').textContent = '\u2026';
128 parentElement.createTextChild('}'); 130 parentElement.createTextChild('}');
129 } 131 }
130 132
131 /** 133 /**
132 * @param {!Array.<!Protocol.Runtime.PropertyPreview>} propertyPath 134 * @param {!Array.<!Protocol.Runtime.PropertyPreview>} propertyPath
135 * @param {!SDK.RemoteObject=} objectForAccessing
133 * @return {!Element} 136 * @return {!Element}
134 */ 137 */
135 _renderPropertyPreviewOrAccessor(propertyPath) { 138 renderPropertyPreviewOrAccessor(propertyPath, objectForAccessing) {
136 var property = propertyPath.peekLast(); 139 var property = propertyPath.peekLast();
140 if (property.type === 'accessor' && objectForAccessing)
141 return this.formatAsAccessorProperty([property.name], objectForAccessing);
137 return this.renderPropertyPreview(property.type, /** @type {string} */ (prop erty.subtype), property.value); 142 return this.renderPropertyPreview(property.type, /** @type {string} */ (prop erty.subtype), property.value);
138 } 143 }
139 144
140 /** 145 /**
141 * @param {string} type 146 * @param {string} type
142 * @param {string=} subtype 147 * @param {string=} subtype
143 * @param {string=} description 148 * @param {string=} description
144 * @return {!Element} 149 * @return {!Element}
145 */ 150 */
146 renderPropertyPreview(type, subtype, description) { 151 renderPropertyPreview(type, subtype, description) {
(...skipping 16 matching lines...) Expand all
163 } 168 }
164 169
165 if (type === 'object' && !subtype) { 170 if (type === 'object' && !subtype) {
166 span.textContent = this._abbreviateFullQualifiedClassName(description); 171 span.textContent = this._abbreviateFullQualifiedClassName(description);
167 return span; 172 return span;
168 } 173 }
169 174
170 span.textContent = description; 175 span.textContent = description;
171 return span; 176 return span;
172 } 177 }
178
179 /**
180 * @param {!Array.<string>} propertyPath
181 * @param {?SDK.RemoteObject} object
182 * @return {!Element}
183 */
184 formatAsAccessorProperty(propertyPath, object) {
185 var rootElement = Components.ObjectPropertyTreeElement.createRemoteObjectAcc essorPropertySpan(
186 object, propertyPath, onInvokeGetterClick.bind(this));
187
188 /**
189 * @param {?SDK.RemoteObject} result
190 * @param {boolean=} wasThrown
191 * @this {Components.RemoteObjectPreviewFormatter}
192 */
193 function onInvokeGetterClick(result, wasThrown) {
194 if (!result)
195 return;
196 rootElement.removeChildren();
197 if (wasThrown) {
198 var element = rootElement.createChild('span');
199 element.textContent = Common.UIString('<exception>');
200 element.title = /** @type {string} */ (result.description);
201 } else {
202 // Make a PropertyPreview from the RemoteObject similar to the backend l ogic.
203 const maxLength = 100;
204 var type = result.type;
205 var subtype = result.subtype;
206 var description = '';
207 if (type !== 'function' && result.description) {
208 if (type === 'string' || subtype === 'regexp')
209 description = result.description.trimMiddle(maxLength);
210 else
211 description = result.description.trimEnd(maxLength);
212 }
213 rootElement.appendChild(this.renderPropertyPreview(type, subtype, descri ption));
214 }
215 }
216
217 return rootElement;
218 }
173 }; 219 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698