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 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 */ | 24 */ |
25 appendObjectPreview(parentElement, preview) { | 25 appendObjectPreview(parentElement, preview) { |
26 var description = preview.description; | 26 var description = preview.description; |
27 if (preview.type !== 'object' || preview.subtype === 'null') { | 27 if (preview.type !== 'object' || preview.subtype === 'null' || preview.subty pe === 'regexp' || |
28 preview.subtype === 'error' || preview.subtype === 'internal#entry') { | |
28 parentElement.appendChild(this.renderPropertyPreview(preview.type, preview .subtype, description)); | 29 parentElement.appendChild(this.renderPropertyPreview(preview.type, preview .subtype, description)); |
29 return; | 30 return; |
30 } | 31 } |
31 if (description && preview.subtype !== 'array') | 32 if (description) { |
32 parentElement.createTextChildren(description, ' '); | 33 if (Runtime.experiments.isEnabled('objectPreviews')) { |
34 var text = ''; | |
35 if (preview.subtype === 'typedarray' || preview.subtype === 'map' || pre view.subtype === 'set') | |
36 text = description.replace(/\[([0-9]+)\]|\(([0-9]+)\)/, ''); | |
37 else if (preview.subtype !== 'array') | |
38 text = description; | |
39 var size = SDK.RemoteObject.arrayLength(preview) || SDK.RemoteObject.num Entries(preview); | |
40 if (size > 1) | |
41 text += '(' + size + ')'; | |
42 if (text.length > 0) | |
43 parentElement.createChild('span', 'object-description').textContent = text + ' '; | |
44 } else if (preview.subtype !== 'array') { | |
45 parentElement.createTextChildren(description, ' '); | |
46 } | |
47 } | |
33 | 48 |
34 var isArray = preview.subtype === 'array' || preview.subtype === 'typedarray '; | 49 var isArray = preview.subtype === 'array' || preview.subtype === 'typedarray '; |
35 parentElement.createTextChild(isArray ? '[' : '{'); | 50 var previewElement = parentElement.createChild('span', 'object-preview'); |
51 previewElement.createTextChild(isArray ? '[' : '{'); | |
36 if (preview.entries) | 52 if (preview.entries) |
37 this._appendEntriesPreview(parentElement, preview); | 53 this._appendEntriesPreview(previewElement, preview); |
38 else if (isArray) | 54 else if (isArray) |
39 this._appendArrayPropertiesPreview(parentElement, preview); | 55 this._appendArrayPropertiesPreview(previewElement, preview); |
40 else | 56 else |
41 this._appendObjectPropertiesPreview(parentElement, preview); | 57 this._appendObjectPropertiesPreview(previewElement, preview); |
42 if (preview.overflow) | 58 if (preview.overflow) |
43 parentElement.createChild('span').textContent = '\u2026'; | 59 previewElement.createChild('span').textContent = '\u2026'; |
44 parentElement.createTextChild(isArray ? ']' : '}'); | 60 previewElement.createTextChild(isArray ? ']' : '}'); |
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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
221 span.createTextChildren('"', description.replace(/\n/g, '\u21B5'), '"'); | 237 span.createTextChildren('"', description.replace(/\n/g, '\u21B5'), '"'); |
222 return span; | 238 return span; |
223 } | 239 } |
224 | 240 |
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.setTextContentTruncatedIfNeeded(description); |
luoe
2017/01/04 04:10:27
With regexp and error types are going through here
| |
232 return span; | 248 return span; |
233 } | 249 } |
234 }; | 250 }; |
OLD | NEW |