OLD | NEW |
---|---|
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 ObjectUI.RemoteObjectPreviewFormatter = class { | 7 ObjectUI.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 * @param {boolean} isEntry |
25 */ | 25 */ |
26 appendObjectPreview(parentElement, preview, isEntry) { | 26 appendObjectPreview(parentElement, preview, isEntry) { |
27 const previewExperimentEnabled = Runtime.experiments.isEnabled('objectPrevie ws'); | 27 const previewExperimentEnabled = Runtime.experiments.isEnabled('objectPrevie ws'); |
28 var description = preview.description; | 28 var description = preview.description; |
29 if (preview.type !== 'object' || preview.subtype === 'null' || (previewExper imentEnabled && isEntry)) { | 29 if (preview.type !== 'object' || preview.subtype === 'error' || preview.subt ype === 'null' || |
30 preview.subtype === 'regexp' || (previewExperimentEnabled && isEntry)) { | |
luoe
2017/02/28 22:35:51
These two additional checks have no effect when th
| |
30 parentElement.appendChild(this.renderPropertyPreview(preview.type, preview .subtype, description)); | 31 parentElement.appendChild(this.renderPropertyPreview(preview.type, preview .subtype, description)); |
31 return; | 32 return; |
32 } | 33 } |
33 const isArrayOrTypedArray = preview.subtype === 'array' || preview.subtype = == 'typedarray'; | 34 const isArrayOrTypedArray = preview.subtype === 'array' || preview.subtype = == 'typedarray'; |
34 if (description) { | 35 if (description) { |
35 if (previewExperimentEnabled) { | 36 if (previewExperimentEnabled) { |
36 // Hide the description for plain objects and plain arrays. | 37 // Hide the description for plain objects and plain arrays. |
37 const plainObjectDescription = 'Object'; | 38 const plainObjectDescription = 'Object'; |
38 const size = SDK.RemoteObject.arrayLength(preview) || SDK.RemoteObject.m apOrSetEntriesCount(preview); | 39 const size = SDK.RemoteObject.arrayLength(preview) || SDK.RemoteObject.m apOrSetEntriesCount(preview); |
39 var text = preview.subtype === 'typedarray' ? SDK.RemoteObject.arrayName FromDescription(description) : ''; | 40 var text = preview.subtype === 'typedarray' ? SDK.RemoteObject.arrayName FromDescription(description) : ''; |
40 if (isArrayOrTypedArray) | 41 if (isArrayOrTypedArray) |
41 text += size > 1 ? ('(' + size + ')') : ''; | 42 text += size > 1 ? ('(' + size + ')') : ''; |
42 else | 43 else |
43 text = description === plainObjectDescription ? '' : description; | 44 text = description === plainObjectDescription ? '' : description; |
44 if (text.length > 0) | 45 if (text.length > 0) |
45 parentElement.createChild('span', 'object-description').textContent = text + ' '; | 46 parentElement.createChild('span', 'object-description').textContent = text + ' '; |
46 } else if (preview.subtype !== 'array') { | 47 } else if (preview.subtype !== 'array') { |
47 parentElement.createTextChildren(description, ' '); | 48 parentElement.createTextChildren(description, ' '); |
48 } | 49 } |
49 } | 50 } |
50 | 51 |
51 parentElement.createTextChild(isArrayOrTypedArray ? '[' : '{'); | 52 var valuePreviewElement = parentElement.createChild('span', 'value-preview') ; |
53 valuePreviewElement.createTextChild(isArrayOrTypedArray ? '[' : '{'); | |
52 if (preview.entries) | 54 if (preview.entries) |
53 this._appendEntriesPreview(parentElement, preview); | 55 this._appendEntriesPreview(valuePreviewElement, preview); |
54 else if (isArrayOrTypedArray) | 56 else if (isArrayOrTypedArray) |
55 this._appendArrayPropertiesPreview(parentElement, preview); | 57 this._appendArrayPropertiesPreview(valuePreviewElement, preview); |
56 else | 58 else |
57 this._appendObjectPropertiesPreview(parentElement, preview); | 59 this._appendObjectPropertiesPreview(valuePreviewElement, preview); |
58 if (preview.overflow) | 60 if (preview.overflow) { |
59 parentElement.createChild('span').textContent = '\u2026'; | 61 var ellipsisText = valuePreviewElement.deepTextContent().length > 1 ? ', \ u2026' : '\u2026'; |
60 parentElement.createTextChild(isArrayOrTypedArray ? ']' : '}'); | 62 valuePreviewElement.createChild('span').textContent = ellipsisText; |
63 } | |
64 valuePreviewElement.createTextChild(isArrayOrTypedArray ? ']' : '}'); | |
61 } | 65 } |
62 | 66 |
63 /** | 67 /** |
64 * @param {string} description | 68 * @param {string} description |
65 * @return {string} | 69 * @return {string} |
66 */ | 70 */ |
67 _abbreviateFullQualifiedClassName(description) { | 71 _abbreviateFullQualifiedClassName(description) { |
68 var abbreviatedDescription = description.split('.'); | 72 var abbreviatedDescription = description.split('.'); |
69 for (var i = 0; i < abbreviatedDescription.length - 1; ++i) | 73 for (var i = 0; i < abbreviatedDescription.length - 1; ++i) |
70 abbreviatedDescription[i] = abbreviatedDescription[i].trimMiddle(3); | 74 abbreviatedDescription[i] = abbreviatedDescription[i].trimMiddle(3); |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
241 if (type === 'object' && !subtype) { | 245 if (type === 'object' && !subtype) { |
242 span.textContent = this._abbreviateFullQualifiedClassName(description); | 246 span.textContent = this._abbreviateFullQualifiedClassName(description); |
243 span.title = description; | 247 span.title = description; |
244 return span; | 248 return span; |
245 } | 249 } |
246 | 250 |
247 span.textContent = description; | 251 span.textContent = description; |
248 return span; | 252 return span; |
249 } | 253 } |
250 }; | 254 }; |
OLD | NEW |