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