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

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

Issue 2605693003: DevTools: introduce object previews experiment (Closed)
Patch Set: rebase Created 3 years, 10 months 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 {!Protocol.Runtime.PropertyPreview} a 9 * @param {!Protocol.Runtime.PropertyPreview} a
10 * @param {!Protocol.Runtime.PropertyPreview} b 10 * @param {!Protocol.Runtime.PropertyPreview} b
11 * @return {number} 11 * @return {number}
12 */ 12 */
13 static _objectPropertyComparator(a, b) { 13 static _objectPropertyComparator(a, b) {
14 if (a.type !== 'function' && b.type === 'function') 14 if (a.type !== 'function' && b.type === 'function')
15 return -1; 15 return -1;
16 if (a.type === 'function' && b.type !== 'function') 16 if (a.type === 'function' && b.type !== 'function')
17 return 1; 17 return 1;
18 return 0; 18 return 0;
19 } 19 }
20 20
21 /** 21 /**
22 * @param {!Element} parentElement 22 * @param {!Element} parentElement
23 * @param {!Protocol.Runtime.ObjectPreview} preview 23 * @param {!Protocol.Runtime.ObjectPreview} preview
24 * @param {boolean} isEntry
24 */ 25 */
25 appendObjectPreview(parentElement, preview) { 26 appendObjectPreview(parentElement, preview, isEntry) {
27 const previewExperimentEnabled = Runtime.experiments.isEnabled('objectPrevie ws');
26 var description = preview.description; 28 var description = preview.description;
27 if (preview.type !== 'object' || preview.subtype === 'null') { 29 if (preview.type !== 'object' || preview.subtype === 'null' || (previewExper imentEnabled && isEntry)) {
28 parentElement.appendChild(this.renderPropertyPreview(preview.type, preview .subtype, description)); 30 parentElement.appendChild(this.renderPropertyPreview(preview.type, preview .subtype, description));
29 return; 31 return;
30 } 32 }
31 if (description && preview.subtype !== 'array') 33 const isArrayOrTypedArray = preview.subtype === 'array' || preview.subtype = == 'typedarray';
32 parentElement.createTextChildren(description, ' '); 34 if (description) {
35 if (previewExperimentEnabled) {
36 // Hide the description for plain objects and plain arrays.
37 const plainObjectDescription = 'Object';
38 const size = SDK.RemoteObject.arrayLength(preview) || SDK.RemoteObject.m apOrSetEntriesCount(preview);
39 var text = preview.subtype === 'typedarray' ? SDK.RemoteObject.arrayName FromDescription(description) : '';
40 if (isArrayOrTypedArray)
41 text += size > 1 ? ('(' + size + ')') : '';
42 else
43 text = description === plainObjectDescription ? '' : description;
44 if (text.length > 0)
45 parentElement.createChild('span', 'object-description').textContent = text + ' ';
46 } else if (preview.subtype !== 'array') {
47 parentElement.createTextChildren(description, ' ');
48 }
49 }
33 50
34 var isArray = preview.subtype === 'array' || preview.subtype === 'typedarray '; 51 parentElement.createTextChild(isArrayOrTypedArray ? '[' : '{');
35 parentElement.createTextChild(isArray ? '[' : '{');
36 if (preview.entries) 52 if (preview.entries)
37 this._appendEntriesPreview(parentElement, preview); 53 this._appendEntriesPreview(parentElement, preview);
38 else if (isArray) 54 else if (isArrayOrTypedArray)
39 this._appendArrayPropertiesPreview(parentElement, preview); 55 this._appendArrayPropertiesPreview(parentElement, preview);
40 else 56 else
41 this._appendObjectPropertiesPreview(parentElement, preview); 57 this._appendObjectPropertiesPreview(parentElement, preview);
42 if (preview.overflow) 58 if (preview.overflow)
43 parentElement.createChild('span').textContent = '\u2026'; 59 parentElement.createChild('span').textContent = '\u2026';
44 parentElement.createTextChild(isArray ? ']' : '}'); 60 parentElement.createTextChild(isArrayOrTypedArray ? ']' : '}');
45 } 61 }
46 62
47 /** 63 /**
48 * @param {string} description 64 * @param {string} description
49 * @return {string} 65 * @return {string}
50 */ 66 */
51 _abbreviateFullQualifiedClassName(description) { 67 _abbreviateFullQualifiedClassName(description) {
52 var abbreviatedDescription = description.split('.'); 68 var abbreviatedDescription = description.split('.');
53 for (var i = 0; i < abbreviatedDescription.length - 1; ++i) 69 for (var i = 0; i < abbreviatedDescription.length - 1; ++i)
54 abbreviatedDescription[i] = abbreviatedDescription[i].trimMiddle(3); 70 abbreviatedDescription[i] = abbreviatedDescription[i].trimMiddle(3);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 * @param {!Element} parentElement 173 * @param {!Element} parentElement
158 * @param {!Protocol.Runtime.ObjectPreview} preview 174 * @param {!Protocol.Runtime.ObjectPreview} preview
159 */ 175 */
160 _appendEntriesPreview(parentElement, preview) { 176 _appendEntriesPreview(parentElement, preview) {
161 for (var i = 0; i < preview.entries.length; ++i) { 177 for (var i = 0; i < preview.entries.length; ++i) {
162 if (i > 0) 178 if (i > 0)
163 parentElement.createTextChild(', '); 179 parentElement.createTextChild(', ');
164 180
165 var entry = preview.entries[i]; 181 var entry = preview.entries[i];
166 if (entry.key) { 182 if (entry.key) {
167 this.appendObjectPreview(parentElement, entry.key); 183 this.appendObjectPreview(parentElement, entry.key, true /* isEntry */);
168 parentElement.createTextChild(' => '); 184 parentElement.createTextChild(' => ');
169 } 185 }
170 this.appendObjectPreview(parentElement, entry.value); 186 this.appendObjectPreview(parentElement, entry.value, true /* isEntry */);
171 } 187 }
172 } 188 }
173 189
174 /** 190 /**
175 * @param {string} name 191 * @param {string} name
176 * @return {!Element} 192 * @return {!Element}
177 */ 193 */
178 _renderDisplayName(name) { 194 _renderDisplayName(name) {
179 var result = createElementWithClass('span', 'name'); 195 var result = createElementWithClass('span', 'name');
180 var needsQuotes = /^\s|\s$|^$|\n/.test(name); 196 var needsQuotes = /^\s|\s$|^$|\n/.test(name);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 if (type === 'object' && !subtype) { 241 if (type === 'object' && !subtype) {
226 span.textContent = this._abbreviateFullQualifiedClassName(description); 242 span.textContent = this._abbreviateFullQualifiedClassName(description);
227 span.title = description; 243 span.title = description;
228 return span; 244 return span;
229 } 245 }
230 246
231 span.textContent = description; 247 span.textContent = description;
232 return span; 248 return span;
233 } 249 }
234 }; 250 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698