| 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 var subTypesWithoutValuePreview = new Set(['null', 'regexp', 'error', 'inter
nal#entry']); |
| 30 if (preview.type !== 'object' || subTypesWithoutValuePreview.has(preview.sub
type) || |
| 31 (previewExperimentEnabled && isEntry)) { |
| 30 parentElement.appendChild(this.renderPropertyPreview(preview.type, preview
.subtype, description)); | 32 parentElement.appendChild(this.renderPropertyPreview(preview.type, preview
.subtype, description)); |
| 31 return; | 33 return; |
| 32 } | 34 } |
| 33 const isArrayOrTypedArray = preview.subtype === 'array' || preview.subtype =
== 'typedarray'; | 35 const isArrayOrTypedArray = preview.subtype === 'array' || preview.subtype =
== 'typedarray'; |
| 34 if (description) { | 36 if (description) { |
| 35 var text; | 37 var text; |
| 36 if (isArrayOrTypedArray) { | 38 if (isArrayOrTypedArray) { |
| 37 var arrayLength = SDK.RemoteObject.arrayLength(preview); | 39 var arrayLength = SDK.RemoteObject.arrayLength(preview); |
| 38 var arrayLengthText = arrayLength > 1 ? ('(' + arrayLength + ')') : ''; | 40 var arrayLengthText = arrayLength > 1 ? ('(' + arrayLength + ')') : ''; |
| 39 var arrayName = preview.subtype === 'typedarray' ? SDK.RemoteObject.arra
yNameFromDescription(description) : ''; | 41 var arrayName = preview.subtype === 'typedarray' ? SDK.RemoteObject.arra
yNameFromDescription(description) : ''; |
| 40 text = arrayName + arrayLengthText; | 42 text = arrayName + arrayLengthText; |
| 41 } else { | 43 } else { |
| 42 var hideDescription = previewExperimentEnabled && description === 'Objec
t'; | 44 var hideDescription = previewExperimentEnabled && description === 'Objec
t'; |
| 43 text = hideDescription ? '' : description; | 45 text = hideDescription ? '' : description; |
| 44 } | 46 } |
| 45 if (text.length > 0) | 47 if (text.length > 0) |
| 46 parentElement.createChild('span', 'object-description').textContent = te
xt + ' '; | 48 parentElement.createChild('span', 'object-description').textContent = te
xt + ' '; |
| 47 } | 49 } |
| 48 | 50 |
| 49 var propertiesElement = parentElement.createChild('span', 'object-properties
-preview source-code'); | 51 var propertiesElement = parentElement.createChild('span', 'object-properties
-preview source-code'); |
| 50 propertiesElement.createTextChild(isArrayOrTypedArray ? '[' : '{'); | 52 propertiesElement.createTextChild(isArrayOrTypedArray ? '[' : '{'); |
| 51 if (preview.entries) | 53 if (preview.entries) |
| 52 this._appendEntriesPreview(propertiesElement, preview); | 54 this._appendEntriesPreview(propertiesElement, preview); |
| 53 else if (isArrayOrTypedArray) | 55 else if (isArrayOrTypedArray) |
| 54 this._appendArrayPropertiesPreview(propertiesElement, preview); | 56 this._appendArrayPropertiesPreview(propertiesElement, preview); |
| 55 else | 57 else |
| 56 this._appendObjectPropertiesPreview(propertiesElement, preview); | 58 this._appendObjectPropertiesPreview(propertiesElement, preview); |
| 57 if (preview.overflow) | 59 if (preview.overflow) { |
| 58 propertiesElement.createChild('span').textContent = '\u2026'; | 60 var ellipsisText = propertiesElement.textContent.length > 1 ? ',\u00a0\u20
26' : '\u2026'; |
| 61 propertiesElement.createChild('span').textContent = ellipsisText; |
| 62 } |
| 59 propertiesElement.createTextChild(isArrayOrTypedArray ? ']' : '}'); | 63 propertiesElement.createTextChild(isArrayOrTypedArray ? ']' : '}'); |
| 60 } | 64 } |
| 61 | 65 |
| 62 /** | 66 /** |
| 63 * @param {string} description | 67 * @param {string} description |
| 64 * @return {string} | 68 * @return {string} |
| 65 */ | 69 */ |
| 66 _abbreviateFullQualifiedClassName(description) { | 70 _abbreviateFullQualifiedClassName(description) { |
| 67 var abbreviatedDescription = description.split('.'); | 71 var abbreviatedDescription = description.split('.'); |
| 68 for (var i = 0; i < abbreviatedDescription.length - 1; ++i) | 72 for (var i = 0; i < abbreviatedDescription.length - 1; ++i) |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 preview = '{\u2026}'; | 247 preview = '{\u2026}'; |
| 244 span.textContent = preview; | 248 span.textContent = preview; |
| 245 span.title = description; | 249 span.title = description; |
| 246 return span; | 250 return span; |
| 247 } | 251 } |
| 248 | 252 |
| 249 span.textContent = description; | 253 span.textContent = description; |
| 250 return span; | 254 return span; |
| 251 } | 255 } |
| 252 }; | 256 }; |
| OLD | NEW |