| 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 /** | 5 /** |
| 6 * @constructor | 6 * @constructor |
| 7 */ | 7 */ |
| 8 WebInspector.RemoteObjectPreviewFormatter = function() | 8 WebInspector.RemoteObjectPreviewFormatter = function() |
| 9 { | 9 { |
| 10 } | 10 } |
| 11 | 11 |
| 12 WebInspector.RemoteObjectPreviewFormatter.prototype = { | 12 WebInspector.RemoteObjectPreviewFormatter.prototype = { |
| 13 /** | 13 /** |
| 14 * @param {!Element} parentElement | 14 * @param {!Element} parentElement |
| 15 * @param {!RuntimeAgent.ObjectPreview} preview | 15 * @param {!RuntimeAgent.ObjectPreview} preview |
| 16 * @return {boolean} true iff preview captured all information. | |
| 17 */ | 16 */ |
| 18 appendObjectPreview: function(parentElement, preview) | 17 appendObjectPreview: function(parentElement, preview) |
| 19 { | 18 { |
| 20 var description = preview.description; | 19 var description = preview.description; |
| 21 if (preview.type !== "object" || preview.subtype === "null") { | 20 if (preview.type !== "object" || preview.subtype === "null") { |
| 22 parentElement.appendChild(this.renderPropertyPreview(preview.type, p
review.subtype, description)); | 21 parentElement.appendChild(this.renderPropertyPreview(preview.type, p
review.subtype, description)); |
| 23 return true; | 22 return; |
| 24 } | 23 } |
| 25 if (description && preview.subtype !== "array") { | 24 if (description && preview.subtype !== "array") { |
| 26 var text = preview.subtype ? description : this._abbreviateFullQuali
fiedClassName(description); | 25 var text = preview.subtype ? description : this._abbreviateFullQuali
fiedClassName(description); |
| 27 parentElement.createTextChildren(text, " "); | 26 parentElement.createTextChildren(text, " "); |
| 28 } | 27 } |
| 29 if (preview.entries) | 28 if (preview.entries) |
| 30 return this._appendEntriesPreview(parentElement, preview); | 29 this._appendEntriesPreview(parentElement, preview); |
| 31 return this._appendPropertiesPreview(parentElement, preview); | 30 else |
| 31 this._appendPropertiesPreview(parentElement, preview); |
| 32 }, | 32 }, |
| 33 | 33 |
| 34 /** | 34 /** |
| 35 * @param {string} description | 35 * @param {string} description |
| 36 * @return {string} | 36 * @return {string} |
| 37 */ | 37 */ |
| 38 _abbreviateFullQualifiedClassName: function(description) | 38 _abbreviateFullQualifiedClassName: function(description) |
| 39 { | 39 { |
| 40 var abbreviatedDescription = description.split("."); | 40 var abbreviatedDescription = description.split("."); |
| 41 for (var i = 0; i < abbreviatedDescription.length - 1; ++i) | 41 for (var i = 0; i < abbreviatedDescription.length - 1; ++i) |
| 42 abbreviatedDescription[i] = abbreviatedDescription[i].trimMiddle(3); | 42 abbreviatedDescription[i] = abbreviatedDescription[i].trimMiddle(3); |
| 43 return abbreviatedDescription.join("."); | 43 return abbreviatedDescription.join("."); |
| 44 }, | 44 }, |
| 45 | 45 |
| 46 /** | 46 /** |
| 47 * @param {!Element} parentElement | 47 * @param {!Element} parentElement |
| 48 * @param {!RuntimeAgent.ObjectPreview} preview | 48 * @param {!RuntimeAgent.ObjectPreview} preview |
| 49 * @return {boolean} true iff preview captured all information. | |
| 50 */ | 49 */ |
| 51 _appendPropertiesPreview: function(parentElement, preview) | 50 _appendPropertiesPreview: function(parentElement, preview) |
| 52 { | 51 { |
| 53 var isArray = preview.subtype === "array"; | 52 var isArray = preview.subtype === "array"; |
| 54 var arrayLength = WebInspector.RemoteObject.arrayLength(preview); | 53 var arrayLength = WebInspector.RemoteObject.arrayLength(preview); |
| 55 var properties = preview.properties; | 54 var properties = preview.properties; |
| 56 if (isArray) | 55 if (isArray) |
| 57 properties = properties.slice().stableSort(compareIndexesFirst); | 56 properties = properties.slice().stableSort(compareIndexesFirst); |
| 58 | 57 |
| 59 /** | 58 /** |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 else | 93 else |
| 95 parentElement.createChild("span", "name").textContent = name
; | 94 parentElement.createChild("span", "name").textContent = name
; |
| 96 parentElement.createTextChild(": "); | 95 parentElement.createTextChild(": "); |
| 97 } | 96 } |
| 98 | 97 |
| 99 parentElement.appendChild(this._renderPropertyPreviewOrAccessor([pro
perty])); | 98 parentElement.appendChild(this._renderPropertyPreviewOrAccessor([pro
perty])); |
| 100 } | 99 } |
| 101 if (preview.overflow) | 100 if (preview.overflow) |
| 102 parentElement.createChild("span").textContent = "\u2026"; | 101 parentElement.createChild("span").textContent = "\u2026"; |
| 103 parentElement.createTextChild(isArray ? "]" : "}"); | 102 parentElement.createTextChild(isArray ? "]" : "}"); |
| 104 return preview.lossless; | |
| 105 }, | 103 }, |
| 106 | 104 |
| 107 | 105 |
| 108 /** | 106 /** |
| 109 * @param {!Element} parentElement | 107 * @param {!Element} parentElement |
| 110 * @param {!RuntimeAgent.ObjectPreview} preview | 108 * @param {!RuntimeAgent.ObjectPreview} preview |
| 111 * @return {boolean} true iff preview captured all information. | |
| 112 */ | 109 */ |
| 113 _appendEntriesPreview: function(parentElement, preview) | 110 _appendEntriesPreview: function(parentElement, preview) |
| 114 { | 111 { |
| 115 var lossless = preview.lossless && !preview.properties.length; | |
| 116 parentElement.createTextChild("{"); | 112 parentElement.createTextChild("{"); |
| 117 for (var i = 0; i < preview.entries.length; ++i) { | 113 for (var i = 0; i < preview.entries.length; ++i) { |
| 118 if (i > 0) | 114 if (i > 0) |
| 119 parentElement.createTextChild(", "); | 115 parentElement.createTextChild(", "); |
| 120 | 116 |
| 121 var entry = preview.entries[i]; | 117 var entry = preview.entries[i]; |
| 122 if (entry.key) { | 118 if (entry.key) { |
| 123 this.appendObjectPreview(parentElement, entry.key); | 119 this.appendObjectPreview(parentElement, entry.key); |
| 124 parentElement.createTextChild(" => "); | 120 parentElement.createTextChild(" => "); |
| 125 } | 121 } |
| 126 this.appendObjectPreview(parentElement, entry.value); | 122 this.appendObjectPreview(parentElement, entry.value); |
| 127 } | 123 } |
| 128 if (preview.overflow) | 124 if (preview.overflow) |
| 129 parentElement.createChild("span").textContent = "\u2026"; | 125 parentElement.createChild("span").textContent = "\u2026"; |
| 130 parentElement.createTextChild("}"); | 126 parentElement.createTextChild("}"); |
| 131 return lossless; | |
| 132 }, | 127 }, |
| 133 | 128 |
| 134 | 129 |
| 135 /** | 130 /** |
| 136 * @param {!Array.<!RuntimeAgent.PropertyPreview>} propertyPath | 131 * @param {!Array.<!RuntimeAgent.PropertyPreview>} propertyPath |
| 137 * @return {!Element} | 132 * @return {!Element} |
| 138 */ | 133 */ |
| 139 _renderPropertyPreviewOrAccessor: function(propertyPath) | 134 _renderPropertyPreviewOrAccessor: function(propertyPath) |
| 140 { | 135 { |
| 141 var property = propertyPath.peekLast(); | 136 var property = propertyPath.peekLast(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 171 | 166 |
| 172 if (type === "object" && !subtype) { | 167 if (type === "object" && !subtype) { |
| 173 span.textContent = this._abbreviateFullQualifiedClassName(descriptio
n); | 168 span.textContent = this._abbreviateFullQualifiedClassName(descriptio
n); |
| 174 return span; | 169 return span; |
| 175 } | 170 } |
| 176 | 171 |
| 177 span.textContent = description; | 172 span.textContent = description; |
| 178 return span; | 173 return span; |
| 179 } | 174 } |
| 180 } | 175 } |
| OLD | NEW |