Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 | * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. |
| 4 | * Copyright (C) 2009 Joseph Pecoraro |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions |
| 8 | * are met: |
| 9 | * |
| 10 | * 1. Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * 2. Redistributions in binary form must reproduce the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer in the |
| 14 | * documentation and/or other materials provided with the distribution. |
| 15 | * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of |
| 16 | * its contributors may be used to endorse or promote products derived |
| 17 | * from this software without specific prior written permission. |
| 18 | * |
| 19 | * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
| 20 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 22 | * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | /** |
| 31 | * @implements {Console.ConsoleViewportElement} |
| 32 | * @unrestricted |
| 33 | */ |
| 34 | Console.ConsoleViewMessage = class { |
| 35 | /** |
| 36 | * @param {!SDK.ConsoleMessage} consoleMessage |
| 37 | * @param {!Components.Linkifier} linkifier |
| 38 | * @param {!ProductRegistry.BadgePool} badgePool |
| 39 | * @param {number} nestingLevel |
Erik Luo | 840be6b | 2018-12-03 20:54:27 | [diff] [blame] | 40 | * @param {function(!Common.Event)} onResize |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 41 | */ |
Erik Luo | 840be6b | 2018-12-03 20:54:27 | [diff] [blame] | 42 | constructor(consoleMessage, linkifier, badgePool, nestingLevel, onResize) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 43 | this._message = consoleMessage; |
| 44 | this._linkifier = linkifier; |
| 45 | this._badgePool = badgePool; |
| 46 | this._repeatCount = 1; |
| 47 | this._closeGroupDecorationCount = 0; |
| 48 | this._nestingLevel = nestingLevel; |
Erik Luo | 31c21f6 | 2018-12-13 03:39:39 | [diff] [blame] | 49 | /** @type {!Array<{element: !Element, forceSelect: function()}>} */ |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 50 | this._selectableChildren = []; |
Erik Luo | 840be6b | 2018-12-03 20:54:27 | [diff] [blame] | 51 | this._messageResized = onResize; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 52 | |
| 53 | /** @type {?DataGrid.DataGrid} */ |
| 54 | this._dataGrid = null; |
| 55 | this._previewFormatter = new ObjectUI.RemoteObjectPreviewFormatter(); |
| 56 | this._searchRegex = null; |
| 57 | /** @type {?UI.Icon} */ |
| 58 | this._messageLevelIcon = null; |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 59 | this._traceExpanded = false; |
| 60 | /** @type {?function(boolean)} */ |
| 61 | this._expandTrace = null; |
John Emau | bb2897a | 2019-10-04 17:37:32 | [diff] [blame] | 62 | /** @type {?Element} */ |
| 63 | this._anchorElement = null; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | /** |
| 67 | * @override |
| 68 | * @return {!Element} |
| 69 | */ |
| 70 | element() { |
| 71 | return this.toMessageElement(); |
| 72 | } |
| 73 | |
| 74 | /** |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 75 | * @override |
| 76 | */ |
| 77 | wasShown() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 78 | if (this._dataGrid) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 79 | this._dataGrid.updateWidths(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 80 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 81 | this._isVisible = true; |
| 82 | } |
| 83 | |
| 84 | onResize() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 85 | if (!this._isVisible) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 86 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 87 | } |
| 88 | if (this._dataGrid) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 89 | this._dataGrid.onResize(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 90 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | /** |
| 94 | * @override |
| 95 | */ |
| 96 | willHide() { |
| 97 | this._isVisible = false; |
Erik Luo | 4b00232 | 2018-07-30 21:23:31 | [diff] [blame] | 98 | this._cachedHeight = this.element().offsetHeight; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | /** |
| 102 | * @return {number} |
| 103 | */ |
| 104 | fastHeight() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 105 | if (this._cachedHeight) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 106 | return this._cachedHeight; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 107 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 108 | // This value reflects the 18px min-height of .console-message, plus the |
| 109 | // 1px border of .console-message-wrapper. Keep in sync with consoleView.css. |
| 110 | const defaultConsoleRowHeight = 19; |
| 111 | if (this._message.type === SDK.ConsoleMessage.MessageType.Table) { |
| 112 | const table = this._message.parameters[0]; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 113 | if (table && table.preview) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 114 | return defaultConsoleRowHeight * table.preview.properties.length; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 115 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 116 | } |
| 117 | return defaultConsoleRowHeight; |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * @return {!SDK.ConsoleMessage} |
| 122 | */ |
| 123 | consoleMessage() { |
| 124 | return this._message; |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * @return {!Element} |
| 129 | */ |
| 130 | _buildTableMessage() { |
| 131 | const formattedMessage = createElementWithClass('span', 'source-code'); |
Erik Luo | 5976c8c | 2018-07-24 02:03:09 | [diff] [blame] | 132 | this._anchorElement = this._buildMessageAnchor(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 133 | if (this._anchorElement) { |
Erik Luo | 5976c8c | 2018-07-24 02:03:09 | [diff] [blame] | 134 | formattedMessage.appendChild(this._anchorElement); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 135 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 136 | const badgeElement = this._buildMessageBadge(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 137 | if (badgeElement) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 138 | formattedMessage.appendChild(badgeElement); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 139 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 140 | |
| 141 | let table = this._message.parameters && this._message.parameters.length ? this._message.parameters[0] : null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 142 | if (table) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 143 | table = this._parameterToRemoteObject(table); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 144 | } |
| 145 | if (!table || !table.preview) { |
Erik Luo | 16e3e38 | 2018-11-09 02:56:01 | [diff] [blame] | 146 | return this._buildMessage(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 147 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 148 | |
| 149 | const rawValueColumnSymbol = Symbol('rawValueColumn'); |
| 150 | const columnNames = []; |
| 151 | const preview = table.preview; |
| 152 | const rows = []; |
| 153 | for (let i = 0; i < preview.properties.length; ++i) { |
| 154 | const rowProperty = preview.properties[i]; |
| 155 | let rowSubProperties; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 156 | if (rowProperty.valuePreview) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 157 | rowSubProperties = rowProperty.valuePreview.properties; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 158 | } else if (rowProperty.value) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 159 | rowSubProperties = [{name: rawValueColumnSymbol, type: rowProperty.type, value: rowProperty.value}]; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 160 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 161 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 162 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 163 | |
| 164 | const rowValue = {}; |
| 165 | const maxColumnsToRender = 20; |
| 166 | for (let j = 0; j < rowSubProperties.length; ++j) { |
| 167 | const cellProperty = rowSubProperties[j]; |
| 168 | let columnRendered = columnNames.indexOf(cellProperty.name) !== -1; |
| 169 | if (!columnRendered) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 170 | if (columnNames.length === maxColumnsToRender) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 171 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 172 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 173 | columnRendered = true; |
| 174 | columnNames.push(cellProperty.name); |
| 175 | } |
| 176 | |
| 177 | if (columnRendered) { |
| 178 | const cellElement = this._renderPropertyPreviewOrAccessor(table, [rowProperty, cellProperty]); |
| 179 | cellElement.classList.add('console-message-nowrap-below'); |
| 180 | rowValue[cellProperty.name] = cellElement; |
| 181 | } |
| 182 | } |
| 183 | rows.push([rowProperty.name, rowValue]); |
| 184 | } |
| 185 | |
| 186 | const flatValues = []; |
| 187 | for (let i = 0; i < rows.length; ++i) { |
| 188 | const rowName = rows[i][0]; |
| 189 | const rowValue = rows[i][1]; |
| 190 | flatValues.push(rowName); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 191 | for (let j = 0; j < columnNames.length; ++j) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 192 | flatValues.push(rowValue[columnNames[j]]); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 193 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 194 | } |
| 195 | columnNames.unshift(Common.UIString('(index)')); |
| 196 | const columnDisplayNames = columnNames.map(name => name === rawValueColumnSymbol ? Common.UIString('Value') : name); |
| 197 | |
| 198 | if (flatValues.length) { |
| 199 | this._dataGrid = DataGrid.SortableDataGrid.create(columnDisplayNames, flatValues); |
| 200 | this._dataGrid.setStriped(true); |
Anubha Mathur | fbacf4e | 2019-10-28 19:08:03 | [diff] [blame^] | 201 | this._dataGrid.setFocusable(false); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 202 | |
| 203 | const formattedResult = createElementWithClass('span', 'console-message-text'); |
| 204 | const tableElement = formattedResult.createChild('div', 'console-message-formatted-table'); |
| 205 | const dataGridContainer = tableElement.createChild('span'); |
| 206 | tableElement.appendChild(this._formatParameter(table, true, false)); |
| 207 | dataGridContainer.appendChild(this._dataGrid.element); |
| 208 | formattedMessage.appendChild(formattedResult); |
| 209 | this._dataGrid.renderInline(); |
| 210 | } |
| 211 | return formattedMessage; |
| 212 | } |
| 213 | |
| 214 | /** |
| 215 | * @return {!Element} |
| 216 | */ |
| 217 | _buildMessage() { |
| 218 | let messageElement; |
| 219 | let messageText = this._message.messageText; |
| 220 | if (this._message.source === SDK.ConsoleMessage.MessageSource.ConsoleAPI) { |
| 221 | switch (this._message.type) { |
| 222 | case SDK.ConsoleMessage.MessageType.Trace: |
| 223 | messageElement = this._format(this._message.parameters || ['console.trace']); |
| 224 | break; |
| 225 | case SDK.ConsoleMessage.MessageType.Clear: |
| 226 | messageElement = createElementWithClass('span', 'console-info'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 227 | if (Common.moduleSetting('preserveConsoleLog').get()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 228 | messageElement.textContent = Common.UIString('console.clear() was prevented due to \'Preserve log\''); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 229 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 230 | messageElement.textContent = Common.UIString('Console was cleared'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 231 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 232 | messageElement.title = |
Lorne Mitchell | 81a1a97 | 2019-03-06 18:13:13 | [diff] [blame] | 233 | ls`Clear all messages with ${UI.shortcutRegistry.shortcutTitleForAction('console.clear')}`; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 234 | break; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 235 | case SDK.ConsoleMessage.MessageType.Dir: { |
| 236 | const obj = this._message.parameters ? this._message.parameters[0] : undefined; |
| 237 | const args = ['%O', obj]; |
| 238 | messageElement = this._format(args); |
| 239 | break; |
| 240 | } |
| 241 | case SDK.ConsoleMessage.MessageType.Profile: |
| 242 | case SDK.ConsoleMessage.MessageType.ProfileEnd: |
| 243 | messageElement = this._format([messageText]); |
| 244 | break; |
Pavel Feldman | 9f0f0a3 | 2018-12-18 02:09:13 | [diff] [blame] | 245 | case SDK.ConsoleMessage.MessageType.Assert: |
| 246 | this._messagePrefix = ls`Assertion failed: `; |
| 247 | // Fall through. |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 248 | default: { |
| 249 | if (this._message.parameters && this._message.parameters.length === 1 && |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 250 | this._message.parameters[0].type === 'string') { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 251 | messageElement = this._tryFormatAsError(/** @type {string} */ (this._message.parameters[0].value)); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 252 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 253 | const args = this._message.parameters || [messageText]; |
| 254 | messageElement = messageElement || this._format(args); |
| 255 | } |
| 256 | } |
| 257 | } else { |
Erik Luo | fc2214f | 2018-11-21 19:54:58 | [diff] [blame] | 258 | if (this._message.source === SDK.ConsoleMessage.MessageSource.Network) { |
| 259 | messageElement = this._formatAsNetworkRequest() || this._format([messageText]); |
| 260 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 261 | const messageInParameters = |
| 262 | this._message.parameters && messageText === /** @type {string} */ (this._message.parameters[0]); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 263 | if (this._message.source === SDK.ConsoleMessage.MessageSource.Violation) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 264 | messageText = Common.UIString('[Violation] %s', messageText); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 265 | } else if (this._message.source === SDK.ConsoleMessage.MessageSource.Intervention) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 266 | messageText = Common.UIString('[Intervention] %s', messageText); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 267 | } else if (this._message.source === SDK.ConsoleMessage.MessageSource.Deprecation) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 268 | messageText = Common.UIString('[Deprecation] %s', messageText); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 269 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 270 | const args = this._message.parameters || [messageText]; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 271 | if (messageInParameters) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 272 | args[0] = messageText; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 273 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 274 | messageElement = this._format(args); |
| 275 | } |
| 276 | } |
| 277 | messageElement.classList.add('console-message-text'); |
| 278 | |
| 279 | const formattedMessage = createElementWithClass('span', 'source-code'); |
Erik Luo | 5976c8c | 2018-07-24 02:03:09 | [diff] [blame] | 280 | this._anchorElement = this._buildMessageAnchor(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 281 | if (this._anchorElement) { |
Erik Luo | 5976c8c | 2018-07-24 02:03:09 | [diff] [blame] | 282 | formattedMessage.appendChild(this._anchorElement); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 283 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 284 | const badgeElement = this._buildMessageBadge(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 285 | if (badgeElement) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 286 | formattedMessage.appendChild(badgeElement); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 287 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 288 | formattedMessage.appendChild(messageElement); |
| 289 | return formattedMessage; |
| 290 | } |
| 291 | |
| 292 | /** |
| 293 | * @return {?Element} |
| 294 | */ |
Erik Luo | fc2214f | 2018-11-21 19:54:58 | [diff] [blame] | 295 | _formatAsNetworkRequest() { |
| 296 | const request = SDK.NetworkLog.requestForConsoleMessage(this._message); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 297 | if (!request) { |
Erik Luo | fc2214f | 2018-11-21 19:54:58 | [diff] [blame] | 298 | return null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 299 | } |
Erik Luo | fc2214f | 2018-11-21 19:54:58 | [diff] [blame] | 300 | const messageElement = createElement('span'); |
| 301 | if (this._message.level === SDK.ConsoleMessage.MessageLevel.Error) { |
| 302 | messageElement.createTextChild(request.requestMethod + ' '); |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 303 | const linkElement = Components.Linkifier.linkifyRevealable(request, request.url(), request.url()); |
| 304 | // Focus is handled by the viewport. |
| 305 | linkElement.tabIndex = -1; |
Erik Luo | 31c21f6 | 2018-12-13 03:39:39 | [diff] [blame] | 306 | this._selectableChildren.push({element: linkElement, forceSelect: () => linkElement.focus()}); |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 307 | messageElement.appendChild(linkElement); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 308 | if (request.failed) { |
Erik Luo | fc2214f | 2018-11-21 19:54:58 | [diff] [blame] | 309 | messageElement.createTextChildren(' ', request.localizedFailDescription); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 310 | } |
| 311 | if (request.statusCode !== 0) { |
Erik Luo | fc2214f | 2018-11-21 19:54:58 | [diff] [blame] | 312 | messageElement.createTextChildren(' ', String(request.statusCode)); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 313 | } |
| 314 | if (request.statusText) { |
Erik Luo | fc2214f | 2018-11-21 19:54:58 | [diff] [blame] | 315 | messageElement.createTextChildren(' (', request.statusText, ')'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 316 | } |
Erik Luo | fc2214f | 2018-11-21 19:54:58 | [diff] [blame] | 317 | } else { |
Erik Luo | ad5f394 | 2019-03-26 20:53:44 | [diff] [blame] | 318 | const messageText = this._message.messageText; |
| 319 | const fragment = this._linkifyWithCustomLinkifier(messageText, (text, url, lineNumber, columnNumber) => { |
| 320 | let linkElement; |
| 321 | if (url === request.url()) { |
| 322 | linkElement = Components.Linkifier.linkifyRevealable( |
| 323 | /** @type {!SDK.NetworkRequest} */ (request), url, request.url()); |
| 324 | } else { |
| 325 | linkElement = Components.Linkifier.linkifyURL(url, {text, lineNumber, columnNumber}); |
| 326 | } |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 327 | linkElement.tabIndex = -1; |
Erik Luo | 31c21f6 | 2018-12-13 03:39:39 | [diff] [blame] | 328 | this._selectableChildren.push({element: linkElement, forceSelect: () => linkElement.focus()}); |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 329 | return linkElement; |
| 330 | }); |
Erik Luo | fc2214f | 2018-11-21 19:54:58 | [diff] [blame] | 331 | messageElement.appendChild(fragment); |
| 332 | } |
| 333 | return messageElement; |
| 334 | } |
| 335 | |
| 336 | /** |
| 337 | * @return {?Element} |
| 338 | */ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 339 | _buildMessageAnchor() { |
| 340 | let anchorElement = null; |
| 341 | if (this._message.scriptId) { |
| 342 | anchorElement = this._linkifyScriptId( |
| 343 | this._message.scriptId, this._message.url || '', this._message.line, this._message.column); |
| 344 | } else if (this._message.stackTrace && this._message.stackTrace.callFrames.length) { |
| 345 | anchorElement = this._linkifyStackTraceTopFrame(this._message.stackTrace); |
| 346 | } else if (this._message.url && this._message.url !== 'undefined') { |
| 347 | anchorElement = this._linkifyLocation(this._message.url, this._message.line, this._message.column); |
| 348 | } |
| 349 | |
| 350 | // Append a space to prevent the anchor text from being glued to the console message when the user selects and copies the console messages. |
| 351 | if (anchorElement) { |
John Emau | f7e30fb | 2019-10-04 19:12:32 | [diff] [blame] | 352 | anchorElement.tabIndex = -1; |
| 353 | this._selectableChildren.push({ |
| 354 | element: anchorElement, |
| 355 | forceSelect: () => anchorElement.focus(), |
| 356 | }); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 357 | const anchorWrapperElement = createElementWithClass('span', 'console-message-anchor'); |
| 358 | anchorWrapperElement.appendChild(anchorElement); |
| 359 | anchorWrapperElement.createTextChild(' '); |
| 360 | return anchorWrapperElement; |
| 361 | } |
| 362 | return null; |
| 363 | } |
| 364 | |
| 365 | /** |
| 366 | * @return {?Element} |
| 367 | */ |
| 368 | _buildMessageBadge() { |
| 369 | const badgeElement = this._badgeElement(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 370 | if (!badgeElement) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 371 | return null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 372 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 373 | badgeElement.classList.add('console-message-badge'); |
| 374 | return badgeElement; |
| 375 | } |
| 376 | |
| 377 | /** |
| 378 | * @return {?Element} |
| 379 | */ |
| 380 | _badgeElement() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 381 | if (this._message._url) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 382 | return this._badgePool.badgeForURL(new Common.ParsedURL(this._message._url)); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 383 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 384 | if (this._message.stackTrace) { |
| 385 | let stackTrace = this._message.stackTrace; |
| 386 | while (stackTrace) { |
| 387 | for (const callFrame of this._message.stackTrace.callFrames) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 388 | if (callFrame.url) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 389 | return this._badgePool.badgeForURL(new Common.ParsedURL(callFrame.url)); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 390 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 391 | } |
| 392 | stackTrace = stackTrace.parent; |
| 393 | } |
| 394 | } |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 395 | if (!this._message.executionContextId) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 396 | return null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 397 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 398 | const runtimeModel = this._message.runtimeModel(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 399 | if (!runtimeModel) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 400 | return null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 401 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 402 | const executionContext = runtimeModel.executionContext(this._message.executionContextId); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 403 | if (!executionContext || !executionContext.frameId) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 404 | return null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 405 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 406 | const resourceTreeModel = executionContext.target().model(SDK.ResourceTreeModel); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 407 | if (!resourceTreeModel) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 408 | return null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 409 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 410 | const frame = resourceTreeModel.frameForId(executionContext.frameId); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 411 | if (!frame || !frame.parentFrame) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 412 | return null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 413 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 414 | return this._badgePool.badgeForFrame(frame); |
| 415 | } |
| 416 | |
| 417 | /** |
| 418 | * @return {!Element} |
| 419 | */ |
| 420 | _buildMessageWithStackTrace() { |
| 421 | const toggleElement = createElementWithClass('div', 'console-message-stack-trace-toggle'); |
| 422 | const contentElement = toggleElement.createChild('div', 'console-message-stack-trace-wrapper'); |
| 423 | |
| 424 | const messageElement = this._buildMessage(); |
| 425 | const icon = UI.Icon.create('smallicon-triangle-right', 'console-message-expand-icon'); |
| 426 | const clickableElement = contentElement.createChild('div'); |
| 427 | clickableElement.appendChild(icon); |
Erik Luo | b5bfff4 | 2018-09-20 02:52:39 | [diff] [blame] | 428 | // Intercept focus to avoid highlight on click. |
| 429 | clickableElement.tabIndex = -1; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 430 | |
| 431 | clickableElement.appendChild(messageElement); |
| 432 | const stackTraceElement = contentElement.createChild('div'); |
| 433 | const stackTracePreview = Components.JSPresentationUtils.buildStackTracePreviewContents( |
| 434 | this._message.runtimeModel().target(), this._linkifier, this._message.stackTrace); |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 435 | stackTraceElement.appendChild(stackTracePreview.element); |
| 436 | for (const linkElement of stackTracePreview.links) { |
| 437 | linkElement.tabIndex = -1; |
Erik Luo | 31c21f6 | 2018-12-13 03:39:39 | [diff] [blame] | 438 | this._selectableChildren.push({element: linkElement, forceSelect: () => linkElement.focus()}); |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 439 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 440 | stackTraceElement.classList.add('hidden'); |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 441 | this._expandTrace = expand => { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 442 | icon.setIconType(expand ? 'smallicon-triangle-down' : 'smallicon-triangle-right'); |
| 443 | stackTraceElement.classList.toggle('hidden', !expand); |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 444 | this._traceExpanded = expand; |
| 445 | }; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 446 | |
| 447 | /** |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 448 | * @this {!Console.ConsoleViewMessage} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 449 | * @param {?Event} event |
| 450 | */ |
| 451 | function toggleStackTrace(event) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 452 | if (UI.isEditing() || contentElement.hasSelection()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 453 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 454 | } |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 455 | this._expandTrace(stackTraceElement.classList.contains('hidden')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 456 | event.consume(); |
| 457 | } |
| 458 | |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 459 | clickableElement.addEventListener('click', toggleStackTrace.bind(this), false); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 460 | if (this._message.type === SDK.ConsoleMessage.MessageType.Trace) { |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 461 | this._expandTrace(true); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 462 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 463 | |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 464 | toggleElement._expandStackTraceForTest = this._expandTrace.bind(this, true); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 465 | return toggleElement; |
| 466 | } |
| 467 | |
| 468 | /** |
| 469 | * @param {string} url |
| 470 | * @param {number} lineNumber |
| 471 | * @param {number} columnNumber |
| 472 | * @return {?Element} |
| 473 | */ |
| 474 | _linkifyLocation(url, lineNumber, columnNumber) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 475 | if (!this._message.runtimeModel()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 476 | return null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 477 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 478 | return this._linkifier.linkifyScriptLocation( |
| 479 | this._message.runtimeModel().target(), null, url, lineNumber, columnNumber); |
| 480 | } |
| 481 | |
| 482 | /** |
| 483 | * @param {!Protocol.Runtime.StackTrace} stackTrace |
| 484 | * @return {?Element} |
| 485 | */ |
| 486 | _linkifyStackTraceTopFrame(stackTrace) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 487 | if (!this._message.runtimeModel()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 488 | return null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 489 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 490 | return this._linkifier.linkifyStackTraceTopFrame(this._message.runtimeModel().target(), stackTrace); |
| 491 | } |
| 492 | |
| 493 | /** |
| 494 | * @param {string} scriptId |
| 495 | * @param {string} url |
| 496 | * @param {number} lineNumber |
| 497 | * @param {number} columnNumber |
| 498 | * @return {?Element} |
| 499 | */ |
| 500 | _linkifyScriptId(scriptId, url, lineNumber, columnNumber) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 501 | if (!this._message.runtimeModel()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 502 | return null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 503 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 504 | return this._linkifier.linkifyScriptLocation( |
| 505 | this._message.runtimeModel().target(), scriptId, url, lineNumber, columnNumber); |
| 506 | } |
| 507 | |
| 508 | /** |
| 509 | * @param {!SDK.RemoteObject|!Protocol.Runtime.RemoteObject|string} parameter |
| 510 | * @return {!SDK.RemoteObject} |
| 511 | */ |
| 512 | _parameterToRemoteObject(parameter) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 513 | if (parameter instanceof SDK.RemoteObject) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 514 | return parameter; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 515 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 516 | const runtimeModel = this._message.runtimeModel(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 517 | if (!runtimeModel) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 518 | return SDK.RemoteObject.fromLocalObject(parameter); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 519 | } |
| 520 | if (typeof parameter === 'object') { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 521 | return runtimeModel.createRemoteObject(parameter); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 522 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 523 | return runtimeModel.createRemoteObjectFromPrimitiveValue(parameter); |
| 524 | } |
| 525 | |
| 526 | /** |
| 527 | * @param {!Array.<!SDK.RemoteObject|string>} rawParameters |
| 528 | * @return {!Element} |
| 529 | */ |
| 530 | _format(rawParameters) { |
| 531 | // This node is used like a Builder. Values are continually appended onto it. |
| 532 | const formattedResult = createElement('span'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 533 | if (this._messagePrefix) { |
Pavel Feldman | 9f0f0a3 | 2018-12-18 02:09:13 | [diff] [blame] | 534 | formattedResult.createChild('span').textContent = this._messagePrefix; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 535 | } |
| 536 | if (!rawParameters.length) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 537 | return formattedResult; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 538 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 539 | |
| 540 | // Formatting code below assumes that parameters are all wrappers whereas frontend console |
| 541 | // API allows passing arbitrary values as messages (strings, numbers, etc.). Wrap them here. |
| 542 | // FIXME: Only pass runtime wrappers here. |
| 543 | let parameters = []; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 544 | for (let i = 0; i < rawParameters.length; ++i) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 545 | parameters[i] = this._parameterToRemoteObject(rawParameters[i]); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 546 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 547 | |
| 548 | // There can be string log and string eval result. We distinguish between them based on message type. |
| 549 | const shouldFormatMessage = |
| 550 | SDK.RemoteObject.type((/** @type {!Array.<!SDK.RemoteObject>} **/ (parameters))[0]) === 'string' && |
| 551 | (this._message.type !== SDK.ConsoleMessage.MessageType.Result || |
| 552 | this._message.level === SDK.ConsoleMessage.MessageLevel.Error); |
| 553 | |
| 554 | // Multiple parameters with the first being a format string. Save unused substitutions. |
| 555 | if (shouldFormatMessage) { |
| 556 | const result = this._formatWithSubstitutionString( |
| 557 | /** @type {string} **/ (parameters[0].description), parameters.slice(1), formattedResult); |
| 558 | parameters = result.unusedSubstitutions; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 559 | if (parameters.length) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 560 | formattedResult.createTextChild(' '); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 561 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | // Single parameter, or unused substitutions from above. |
| 565 | for (let i = 0; i < parameters.length; ++i) { |
| 566 | // Inline strings when formatting. |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 567 | if (shouldFormatMessage && parameters[i].type === 'string') { |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 568 | formattedResult.appendChild(this._linkifyStringAsFragment(parameters[i].description)); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 569 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 570 | formattedResult.appendChild(this._formatParameter(parameters[i], false, true)); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 571 | } |
| 572 | if (i < parameters.length - 1) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 573 | formattedResult.createTextChild(' '); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 574 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 575 | } |
| 576 | return formattedResult; |
| 577 | } |
| 578 | |
| 579 | /** |
| 580 | * @param {!SDK.RemoteObject} output |
| 581 | * @param {boolean=} forceObjectFormat |
| 582 | * @param {boolean=} includePreview |
| 583 | * @return {!Element} |
| 584 | */ |
| 585 | _formatParameter(output, forceObjectFormat, includePreview) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 586 | if (output.customPreview()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 587 | return (new ObjectUI.CustomPreviewComponent(output)).element; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 588 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 589 | |
| 590 | const type = forceObjectFormat ? 'object' : (output.subtype || output.type); |
| 591 | let element; |
| 592 | switch (type) { |
| 593 | case 'error': |
| 594 | element = this._formatParameterAsError(output); |
| 595 | break; |
| 596 | case 'function': |
| 597 | element = this._formatParameterAsFunction(output, includePreview); |
| 598 | break; |
| 599 | case 'array': |
| 600 | case 'arraybuffer': |
| 601 | case 'blob': |
| 602 | case 'dataview': |
| 603 | case 'generator': |
| 604 | case 'iterator': |
| 605 | case 'map': |
| 606 | case 'object': |
| 607 | case 'promise': |
| 608 | case 'proxy': |
| 609 | case 'set': |
| 610 | case 'typedarray': |
| 611 | case 'weakmap': |
| 612 | case 'weakset': |
| 613 | element = this._formatParameterAsObject(output, includePreview); |
| 614 | break; |
| 615 | case 'node': |
| 616 | element = output.isNode() ? this._formatParameterAsNode(output) : this._formatParameterAsObject(output, false); |
| 617 | break; |
| 618 | case 'string': |
| 619 | element = this._formatParameterAsString(output); |
| 620 | break; |
| 621 | case 'boolean': |
| 622 | case 'date': |
| 623 | case 'null': |
| 624 | case 'number': |
| 625 | case 'regexp': |
| 626 | case 'symbol': |
| 627 | case 'undefined': |
| 628 | case 'bigint': |
| 629 | element = this._formatParameterAsValue(output); |
| 630 | break; |
| 631 | default: |
| 632 | element = this._formatParameterAsValue(output); |
| 633 | console.error('Tried to format remote object of unknown type.'); |
| 634 | } |
| 635 | element.classList.add('object-value-' + type); |
| 636 | element.classList.add('source-code'); |
| 637 | return element; |
| 638 | } |
| 639 | |
| 640 | /** |
| 641 | * @param {!SDK.RemoteObject} obj |
| 642 | * @return {!Element} |
| 643 | */ |
| 644 | _formatParameterAsValue(obj) { |
| 645 | const result = createElement('span'); |
| 646 | const description = obj.description || ''; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 647 | if (description.length > Console.ConsoleViewMessage._MaxTokenizableStringLength) { |
Erik Luo | 5fb33bd | 2018-06-04 23:23:52 | [diff] [blame] | 648 | result.appendChild(UI.createExpandableText(description, Console.ConsoleViewMessage._LongStringVisibleLength)); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 649 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 650 | result.createTextChild(description); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 651 | } |
| 652 | if (obj.objectId) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 653 | result.addEventListener('contextmenu', this._contextMenuEventFired.bind(this, obj), false); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 654 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 655 | return result; |
| 656 | } |
| 657 | |
| 658 | /** |
| 659 | * @param {!SDK.RemoteObject} obj |
| 660 | * @param {boolean=} includePreview |
| 661 | * @return {!Element} |
| 662 | */ |
| 663 | _formatParameterAsObject(obj, includePreview) { |
| 664 | const titleElement = createElementWithClass('span', 'console-object'); |
| 665 | if (includePreview && obj.preview) { |
| 666 | titleElement.classList.add('console-object-preview'); |
| 667 | this._previewFormatter.appendObjectPreview(titleElement, obj.preview, false /* isEntry */); |
| 668 | } else if (obj.type === 'function') { |
| 669 | const functionElement = titleElement.createChild('span'); |
| 670 | ObjectUI.ObjectPropertiesSection.formatObjectAsFunction(obj, functionElement, false); |
| 671 | titleElement.classList.add('object-value-function'); |
| 672 | } else { |
| 673 | titleElement.createTextChild(obj.description || ''); |
| 674 | } |
| 675 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 676 | if (!obj.hasChildren || obj.customPreview()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 677 | return titleElement; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 678 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 679 | |
| 680 | const note = titleElement.createChild('span', 'object-state-note info-note'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 681 | if (this._message.type === SDK.ConsoleMessage.MessageType.QueryObjectResult) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 682 | note.title = ls`This value will not be collected until console is cleared.`; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 683 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 684 | note.title = ls`Value below was evaluated just now.`; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 685 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 686 | |
| 687 | const section = new ObjectUI.ObjectPropertiesSection(obj, titleElement, this._linkifier); |
| 688 | section.element.classList.add('console-view-object-properties-section'); |
| 689 | section.enableContextMenu(); |
Erik Luo | cc14b81 | 2018-11-03 01:33:09 | [diff] [blame] | 690 | section.setShowSelectionOnKeyboardFocus(true, true); |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 691 | this._selectableChildren.push(section); |
Erik Luo | 840be6b | 2018-12-03 20:54:27 | [diff] [blame] | 692 | section.addEventListener(UI.TreeOutline.Events.ElementAttached, this._messageResized); |
| 693 | section.addEventListener(UI.TreeOutline.Events.ElementExpanded, this._messageResized); |
| 694 | section.addEventListener(UI.TreeOutline.Events.ElementCollapsed, this._messageResized); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 695 | return section.element; |
| 696 | } |
| 697 | |
| 698 | /** |
| 699 | * @param {!SDK.RemoteObject} func |
| 700 | * @param {boolean=} includePreview |
| 701 | * @return {!Element} |
| 702 | */ |
| 703 | _formatParameterAsFunction(func, includePreview) { |
| 704 | const result = createElement('span'); |
| 705 | SDK.RemoteFunction.objectAsFunction(func).targetFunction().then(formatTargetFunction.bind(this)); |
| 706 | return result; |
| 707 | |
| 708 | /** |
| 709 | * @param {!SDK.RemoteObject} targetFunction |
| 710 | * @this {Console.ConsoleViewMessage} |
| 711 | */ |
| 712 | function formatTargetFunction(targetFunction) { |
| 713 | const functionElement = createElement('span'); |
Joey Arhar | d78a58f | 2018-12-05 01:59:45 | [diff] [blame] | 714 | const promise = ObjectUI.ObjectPropertiesSection.formatObjectAsFunction( |
| 715 | targetFunction, functionElement, true, includePreview); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 716 | result.appendChild(functionElement); |
| 717 | if (targetFunction !== func) { |
| 718 | const note = result.createChild('span', 'object-info-state-note'); |
| 719 | note.title = Common.UIString('Function was resolved from bound function.'); |
| 720 | } |
| 721 | result.addEventListener('contextmenu', this._contextMenuEventFired.bind(this, targetFunction), false); |
Joey Arhar | d78a58f | 2018-12-05 01:59:45 | [diff] [blame] | 722 | promise.then(() => this._formattedParameterAsFunctionForTest()); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 723 | } |
| 724 | } |
| 725 | |
Joey Arhar | d78a58f | 2018-12-05 01:59:45 | [diff] [blame] | 726 | _formattedParameterAsFunctionForTest() { |
| 727 | } |
| 728 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 729 | /** |
| 730 | * @param {!SDK.RemoteObject} obj |
| 731 | * @param {!Event} event |
| 732 | */ |
| 733 | _contextMenuEventFired(obj, event) { |
| 734 | const contextMenu = new UI.ContextMenu(event); |
| 735 | contextMenu.appendApplicableItems(obj); |
| 736 | contextMenu.show(); |
| 737 | } |
| 738 | |
| 739 | /** |
| 740 | * @param {?SDK.RemoteObject} object |
| 741 | * @param {!Array.<!Protocol.Runtime.PropertyPreview>} propertyPath |
| 742 | * @return {!Element} |
| 743 | */ |
| 744 | _renderPropertyPreviewOrAccessor(object, propertyPath) { |
| 745 | const property = propertyPath.peekLast(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 746 | if (property.type === 'accessor') { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 747 | return this._formatAsAccessorProperty(object, propertyPath.map(property => property.name), false); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 748 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 749 | return this._previewFormatter.renderPropertyPreview( |
| 750 | property.type, /** @type {string} */ (property.subtype), property.value); |
| 751 | } |
| 752 | |
| 753 | /** |
| 754 | * @param {!SDK.RemoteObject} remoteObject |
| 755 | * @return {!Element} |
| 756 | */ |
| 757 | _formatParameterAsNode(remoteObject) { |
| 758 | const result = createElement('span'); |
| 759 | |
| 760 | const domModel = remoteObject.runtimeModel().target().model(SDK.DOMModel); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 761 | if (!domModel) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 762 | return result; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 763 | } |
Erik Luo | 54fdd91 | 2018-11-01 17:57:01 | [diff] [blame] | 764 | domModel.pushObjectAsNodeToFrontend(remoteObject).then(async node => { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 765 | if (!node) { |
| 766 | result.appendChild(this._formatParameterAsObject(remoteObject, false)); |
| 767 | return; |
| 768 | } |
Erik Luo | 54fdd91 | 2018-11-01 17:57:01 | [diff] [blame] | 769 | const renderResult = await UI.Renderer.render(/** @type {!Object} */ (node)); |
Erik Luo | fc6a630 | 2018-11-02 06:48:52 | [diff] [blame] | 770 | if (renderResult) { |
Erik Luo | 840be6b | 2018-12-03 20:54:27 | [diff] [blame] | 771 | if (renderResult.tree) { |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 772 | this._selectableChildren.push(renderResult.tree); |
Erik Luo | 840be6b | 2018-12-03 20:54:27 | [diff] [blame] | 773 | renderResult.tree.addEventListener(UI.TreeOutline.Events.ElementAttached, this._messageResized); |
| 774 | renderResult.tree.addEventListener(UI.TreeOutline.Events.ElementExpanded, this._messageResized); |
| 775 | renderResult.tree.addEventListener(UI.TreeOutline.Events.ElementCollapsed, this._messageResized); |
| 776 | } |
Erik Luo | fc6a630 | 2018-11-02 06:48:52 | [diff] [blame] | 777 | result.appendChild(renderResult.node); |
| 778 | } else { |
| 779 | result.appendChild(this._formatParameterAsObject(remoteObject, false)); |
| 780 | } |
Erik Luo | 54fdd91 | 2018-11-01 17:57:01 | [diff] [blame] | 781 | this._formattedParameterAsNodeForTest(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 782 | }); |
| 783 | |
| 784 | return result; |
| 785 | } |
| 786 | |
| 787 | _formattedParameterAsNodeForTest() { |
| 788 | } |
| 789 | |
| 790 | /** |
| 791 | * @param {!SDK.RemoteObject} output |
| 792 | * @return {!Element} |
| 793 | */ |
| 794 | _formatParameterAsString(output) { |
| 795 | const span = createElement('span'); |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 796 | span.appendChild(this._linkifyStringAsFragment(output.description || '')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 797 | |
| 798 | const result = createElement('span'); |
| 799 | result.createChild('span', 'object-value-string-quote').textContent = '"'; |
| 800 | result.appendChild(span); |
| 801 | result.createChild('span', 'object-value-string-quote').textContent = '"'; |
| 802 | return result; |
| 803 | } |
| 804 | |
| 805 | /** |
| 806 | * @param {!SDK.RemoteObject} output |
| 807 | * @return {!Element} |
| 808 | */ |
| 809 | _formatParameterAsError(output) { |
| 810 | const result = createElement('span'); |
| 811 | const errorSpan = this._tryFormatAsError(output.description || ''); |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 812 | result.appendChild(errorSpan ? errorSpan : this._linkifyStringAsFragment(output.description || '')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 813 | return result; |
| 814 | } |
| 815 | |
| 816 | /** |
| 817 | * @param {!SDK.RemoteObject} output |
| 818 | * @return {!Element} |
| 819 | */ |
| 820 | _formatAsArrayEntry(output) { |
| 821 | return this._previewFormatter.renderPropertyPreview(output.type, output.subtype, output.description); |
| 822 | } |
| 823 | |
| 824 | /** |
| 825 | * @param {?SDK.RemoteObject} object |
| 826 | * @param {!Array.<string>} propertyPath |
| 827 | * @param {boolean} isArrayEntry |
| 828 | * @return {!Element} |
| 829 | */ |
| 830 | _formatAsAccessorProperty(object, propertyPath, isArrayEntry) { |
| 831 | const rootElement = ObjectUI.ObjectPropertyTreeElement.createRemoteObjectAccessorPropertySpan( |
| 832 | object, propertyPath, onInvokeGetterClick.bind(this)); |
| 833 | |
| 834 | /** |
Alexey Kozyatinskiy | 330bffb | 2018-09-21 19:20:18 | [diff] [blame] | 835 | * @param {!SDK.CallFunctionResult} result |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 836 | * @this {Console.ConsoleViewMessage} |
| 837 | */ |
Alexey Kozyatinskiy | 330bffb | 2018-09-21 19:20:18 | [diff] [blame] | 838 | function onInvokeGetterClick(result) { |
| 839 | const wasThrown = result.wasThrown; |
| 840 | const object = result.object; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 841 | if (!object) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 842 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 843 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 844 | rootElement.removeChildren(); |
| 845 | if (wasThrown) { |
| 846 | const element = rootElement.createChild('span'); |
| 847 | element.textContent = Common.UIString('<exception>'); |
Alexey Kozyatinskiy | 330bffb | 2018-09-21 19:20:18 | [diff] [blame] | 848 | element.title = /** @type {string} */ (object.description); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 849 | } else if (isArrayEntry) { |
Alexey Kozyatinskiy | 330bffb | 2018-09-21 19:20:18 | [diff] [blame] | 850 | rootElement.appendChild(this._formatAsArrayEntry(object)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 851 | } else { |
| 852 | // Make a PropertyPreview from the RemoteObject similar to the backend logic. |
| 853 | const maxLength = 100; |
Alexey Kozyatinskiy | 330bffb | 2018-09-21 19:20:18 | [diff] [blame] | 854 | const type = object.type; |
| 855 | const subtype = object.subtype; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 856 | let description = ''; |
Alexey Kozyatinskiy | 330bffb | 2018-09-21 19:20:18 | [diff] [blame] | 857 | if (type !== 'function' && object.description) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 858 | if (type === 'string' || subtype === 'regexp') { |
Alexey Kozyatinskiy | 330bffb | 2018-09-21 19:20:18 | [diff] [blame] | 859 | description = object.description.trimMiddle(maxLength); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 860 | } else { |
Tim van der Lippe | ffa7862 | 2019-09-16 12:07:12 | [diff] [blame] | 861 | description = object.description.trimEndWithMaxLength(maxLength); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 862 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 863 | } |
| 864 | rootElement.appendChild(this._previewFormatter.renderPropertyPreview(type, subtype, description)); |
| 865 | } |
| 866 | } |
| 867 | |
| 868 | return rootElement; |
| 869 | } |
| 870 | |
| 871 | /** |
| 872 | * @param {string} format |
| 873 | * @param {!Array.<!SDK.RemoteObject>} parameters |
| 874 | * @param {!Element} formattedResult |
| 875 | */ |
| 876 | _formatWithSubstitutionString(format, parameters, formattedResult) { |
| 877 | const formatters = {}; |
| 878 | |
| 879 | /** |
| 880 | * @param {boolean} force |
| 881 | * @param {boolean} includePreview |
| 882 | * @param {!SDK.RemoteObject} obj |
| 883 | * @return {!Element} |
| 884 | * @this {Console.ConsoleViewMessage} |
| 885 | */ |
| 886 | function parameterFormatter(force, includePreview, obj) { |
| 887 | return this._formatParameter(obj, force, includePreview); |
| 888 | } |
| 889 | |
| 890 | function stringFormatter(obj) { |
| 891 | return obj.description; |
| 892 | } |
| 893 | |
| 894 | function floatFormatter(obj) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 895 | if (typeof obj.value !== 'number') { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 896 | return 'NaN'; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 897 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 898 | return obj.value; |
| 899 | } |
| 900 | |
| 901 | function integerFormatter(obj) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 902 | if (obj.type === 'bigint') { |
Alexey Kozyatinskiy | beb38de | 2018-08-10 18:54:19 | [diff] [blame] | 903 | return obj.description; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 904 | } |
| 905 | if (typeof obj.value !== 'number') { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 906 | return 'NaN'; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 907 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 908 | return Math.floor(obj.value); |
| 909 | } |
| 910 | |
| 911 | function bypassFormatter(obj) { |
| 912 | return (obj instanceof Node) ? obj : ''; |
| 913 | } |
| 914 | |
| 915 | let currentStyle = null; |
| 916 | function styleFormatter(obj) { |
| 917 | currentStyle = {}; |
| 918 | const buffer = createElement('span'); |
| 919 | buffer.setAttribute('style', obj.description); |
| 920 | for (let i = 0; i < buffer.style.length; i++) { |
| 921 | const property = buffer.style[i]; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 922 | if (isWhitelistedProperty(property)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 923 | currentStyle[property] = buffer.style[property]; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 924 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 925 | } |
| 926 | } |
| 927 | |
| 928 | function isWhitelistedProperty(property) { |
| 929 | // Make sure that allowed properties do not interfere with link visibility. |
| 930 | const prefixes = [ |
| 931 | 'background', 'border', 'color', 'font', 'line', 'margin', 'padding', 'text', '-webkit-background', |
| 932 | '-webkit-border', '-webkit-font', '-webkit-margin', '-webkit-padding', '-webkit-text' |
| 933 | ]; |
| 934 | for (let i = 0; i < prefixes.length; i++) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 935 | if (property.startsWith(prefixes[i])) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 936 | return true; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 937 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 938 | } |
| 939 | return false; |
| 940 | } |
| 941 | |
| 942 | // Firebug uses %o for formatting objects. |
| 943 | formatters.o = parameterFormatter.bind(this, false /* force */, true /* includePreview */); |
| 944 | formatters.s = stringFormatter; |
| 945 | formatters.f = floatFormatter; |
| 946 | // Firebug allows both %i and %d for formatting integers. |
| 947 | formatters.i = integerFormatter; |
| 948 | formatters.d = integerFormatter; |
| 949 | |
| 950 | // Firebug uses %c for styling the message. |
| 951 | formatters.c = styleFormatter; |
| 952 | |
| 953 | // Support %O to force object formatting, instead of the type-based %o formatting. |
| 954 | formatters.O = parameterFormatter.bind(this, true /* force */, false /* includePreview */); |
| 955 | |
| 956 | formatters._ = bypassFormatter; |
| 957 | |
| 958 | /** |
| 959 | * @param {!Element} a |
| 960 | * @param {*} b |
| 961 | * @this {!Console.ConsoleViewMessage} |
Erik Luo | 1792639 | 2018-05-17 22:06:12 | [diff] [blame] | 962 | * @return {!Element} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 963 | */ |
| 964 | function append(a, b) { |
| 965 | if (b instanceof Node) { |
| 966 | a.appendChild(b); |
Erik Luo | 1792639 | 2018-05-17 22:06:12 | [diff] [blame] | 967 | return a; |
| 968 | } |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 969 | if (typeof b === 'undefined') { |
Erik Luo | 1792639 | 2018-05-17 22:06:12 | [diff] [blame] | 970 | return a; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 971 | } |
Erik Luo | 1792639 | 2018-05-17 22:06:12 | [diff] [blame] | 972 | if (!currentStyle) { |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 973 | a.appendChild(this._linkifyStringAsFragment(String(b))); |
Erik Luo | 1792639 | 2018-05-17 22:06:12 | [diff] [blame] | 974 | return a; |
| 975 | } |
| 976 | const lines = String(b).split('\n'); |
| 977 | for (let i = 0; i < lines.length; i++) { |
| 978 | const line = lines[i]; |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 979 | const lineFragment = this._linkifyStringAsFragment(line); |
Erik Luo | 1792639 | 2018-05-17 22:06:12 | [diff] [blame] | 980 | const wrapper = createElement('span'); |
| 981 | wrapper.style.setProperty('contain', 'paint'); |
| 982 | wrapper.style.setProperty('display', 'inline-block'); |
| 983 | wrapper.style.setProperty('max-width', '100%'); |
| 984 | wrapper.appendChild(lineFragment); |
| 985 | applyCurrentStyle(wrapper); |
| 986 | for (const child of wrapper.children) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 987 | if (child.classList.contains('devtools-link')) { |
Erik Luo | 1792639 | 2018-05-17 22:06:12 | [diff] [blame] | 988 | this._applyForcedVisibleStyle(child); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 989 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 990 | } |
Erik Luo | 1792639 | 2018-05-17 22:06:12 | [diff] [blame] | 991 | a.appendChild(wrapper); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 992 | if (i < lines.length - 1) { |
Erik Luo | 1792639 | 2018-05-17 22:06:12 | [diff] [blame] | 993 | a.appendChild(createElement('br')); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 994 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 995 | } |
| 996 | return a; |
| 997 | } |
| 998 | |
| 999 | /** |
| 1000 | * @param {!Element} element |
| 1001 | */ |
| 1002 | function applyCurrentStyle(element) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1003 | for (const key in currentStyle) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1004 | element.style[key] = currentStyle[key]; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1005 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | // String.format does treat formattedResult like a Builder, result is an object. |
| 1009 | return String.format(format, parameters, formatters, formattedResult, append.bind(this)); |
| 1010 | } |
| 1011 | |
| 1012 | /** |
| 1013 | * @param {!Element} element |
| 1014 | */ |
| 1015 | _applyForcedVisibleStyle(element) { |
| 1016 | element.style.setProperty('-webkit-text-stroke', '0', 'important'); |
| 1017 | element.style.setProperty('text-decoration', 'underline', 'important'); |
| 1018 | |
| 1019 | const themedColor = UI.themeSupport.patchColorText('rgb(33%, 33%, 33%)', UI.ThemeSupport.ColorUsage.Foreground); |
| 1020 | element.style.setProperty('color', themedColor, 'important'); |
| 1021 | |
| 1022 | let backgroundColor = 'hsl(0, 0%, 100%)'; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1023 | if (this._message.level === SDK.ConsoleMessage.MessageLevel.Error) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1024 | backgroundColor = 'hsl(0, 100%, 97%)'; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1025 | } else if (this._message.level === SDK.ConsoleMessage.MessageLevel.Warning || this._shouldRenderAsWarning()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1026 | backgroundColor = 'hsl(50, 100%, 95%)'; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1027 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1028 | const themedBackgroundColor = |
| 1029 | UI.themeSupport.patchColorText(backgroundColor, UI.ThemeSupport.ColorUsage.Background); |
| 1030 | element.style.setProperty('background-color', themedBackgroundColor, 'important'); |
| 1031 | } |
| 1032 | |
| 1033 | /** |
| 1034 | * @return {boolean} |
| 1035 | */ |
| 1036 | matchesFilterRegex(regexObject) { |
| 1037 | regexObject.lastIndex = 0; |
Erik Luo | 5976c8c | 2018-07-24 02:03:09 | [diff] [blame] | 1038 | const contentElement = this.contentElement(); |
| 1039 | const anchorText = this._anchorElement ? this._anchorElement.deepTextContent() : ''; |
| 1040 | return (anchorText && regexObject.test(anchorText.trim())) || |
| 1041 | regexObject.test(contentElement.deepTextContent().slice(anchorText.length)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1042 | } |
| 1043 | |
| 1044 | /** |
| 1045 | * @param {string} filter |
| 1046 | * @return {boolean} |
| 1047 | */ |
| 1048 | matchesFilterText(filter) { |
| 1049 | const text = this.contentElement().deepTextContent(); |
| 1050 | return text.toLowerCase().includes(filter.toLowerCase()); |
| 1051 | } |
| 1052 | |
| 1053 | updateTimestamp() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1054 | if (!this._contentElement) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1055 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1056 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1057 | |
| 1058 | if (Common.moduleSetting('consoleTimestampsEnabled').get()) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1059 | if (!this._timestampElement) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1060 | this._timestampElement = createElementWithClass('span', 'console-timestamp'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1061 | } |
Rayan Kanso | aca06e7 | 2019-03-27 11:57:06 | [diff] [blame] | 1062 | this._timestampElement.textContent = UI.formatTimestamp(this._message.timestamp, false) + ' '; |
| 1063 | this._timestampElement.title = UI.formatTimestamp(this._message.timestamp, true); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1064 | this._contentElement.insertBefore(this._timestampElement, this._contentElement.firstChild); |
| 1065 | } else if (this._timestampElement) { |
| 1066 | this._timestampElement.remove(); |
| 1067 | delete this._timestampElement; |
| 1068 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1069 | } |
| 1070 | |
| 1071 | /** |
| 1072 | * @return {number} |
| 1073 | */ |
| 1074 | nestingLevel() { |
| 1075 | return this._nestingLevel; |
| 1076 | } |
| 1077 | |
| 1078 | /** |
| 1079 | * @param {boolean} inSimilarGroup |
| 1080 | * @param {boolean=} isLast |
| 1081 | */ |
| 1082 | setInSimilarGroup(inSimilarGroup, isLast) { |
| 1083 | this._inSimilarGroup = inSimilarGroup; |
| 1084 | this._lastInSimilarGroup = inSimilarGroup && !!isLast; |
| 1085 | if (this._similarGroupMarker && !inSimilarGroup) { |
| 1086 | this._similarGroupMarker.remove(); |
| 1087 | this._similarGroupMarker = null; |
| 1088 | } else if (this._element && !this._similarGroupMarker && inSimilarGroup) { |
| 1089 | this._similarGroupMarker = createElementWithClass('div', 'nesting-level-marker'); |
| 1090 | this._element.insertBefore(this._similarGroupMarker, this._element.firstChild); |
| 1091 | this._similarGroupMarker.classList.toggle('group-closed', this._lastInSimilarGroup); |
| 1092 | } |
| 1093 | } |
| 1094 | |
| 1095 | /** |
| 1096 | * @return {boolean} |
| 1097 | */ |
| 1098 | isLastInSimilarGroup() { |
| 1099 | return this._inSimilarGroup && this._lastInSimilarGroup; |
| 1100 | } |
| 1101 | |
| 1102 | resetCloseGroupDecorationCount() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1103 | if (!this._closeGroupDecorationCount) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1104 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1105 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1106 | this._closeGroupDecorationCount = 0; |
| 1107 | this._updateCloseGroupDecorations(); |
| 1108 | } |
| 1109 | |
| 1110 | incrementCloseGroupDecorationCount() { |
| 1111 | ++this._closeGroupDecorationCount; |
| 1112 | this._updateCloseGroupDecorations(); |
| 1113 | } |
| 1114 | |
| 1115 | _updateCloseGroupDecorations() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1116 | if (!this._nestingLevelMarkers) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1117 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1118 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1119 | for (let i = 0, n = this._nestingLevelMarkers.length; i < n; ++i) { |
| 1120 | const marker = this._nestingLevelMarkers[i]; |
| 1121 | marker.classList.toggle('group-closed', n - i <= this._closeGroupDecorationCount); |
| 1122 | } |
| 1123 | } |
| 1124 | |
| 1125 | /** |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1126 | * @return {number} |
| 1127 | */ |
| 1128 | _focusedChildIndex() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1129 | if (!this._selectableChildren.length) { |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1130 | return -1; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1131 | } |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 1132 | return this._selectableChildren.findIndex(child => child.element.hasFocus()); |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1133 | } |
| 1134 | |
| 1135 | /** |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1136 | * @param {!Event} event |
| 1137 | */ |
| 1138 | _onKeyDown(event) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1139 | if (UI.isEditing() || !this._element.hasFocus() || this._element.hasSelection()) { |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1140 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1141 | } |
| 1142 | if (this.maybeHandleOnKeyDown(event)) { |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1143 | event.consume(true); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1144 | } |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1145 | } |
| 1146 | |
| 1147 | /** |
| 1148 | * @protected |
| 1149 | * @param {!Event} event |
| 1150 | */ |
| 1151 | maybeHandleOnKeyDown(event) { |
| 1152 | // Handle trace expansion. |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1153 | const focusedChildIndex = this._focusedChildIndex(); |
| 1154 | const isWrapperFocused = focusedChildIndex === -1; |
| 1155 | if (this._expandTrace && isWrapperFocused) { |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1156 | if ((event.key === 'ArrowLeft' && this._traceExpanded) || (event.key === 'ArrowRight' && !this._traceExpanded)) { |
| 1157 | this._expandTrace(!this._traceExpanded); |
| 1158 | return true; |
| 1159 | } |
| 1160 | } |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1161 | if (!this._selectableChildren.length) { |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1162 | return false; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1163 | } |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1164 | |
| 1165 | if (event.key === 'ArrowLeft') { |
| 1166 | this._element.focus(); |
| 1167 | return true; |
| 1168 | } |
| 1169 | if (event.key === 'ArrowRight') { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1170 | if (isWrapperFocused && this._selectNearestVisibleChild(0)) { |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1171 | return true; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1172 | } |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1173 | } |
| 1174 | if (event.key === 'ArrowUp') { |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 1175 | const firstVisibleChild = this._nearestVisibleChild(0); |
| 1176 | if (this._selectableChildren[focusedChildIndex] === firstVisibleChild && firstVisibleChild) { |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1177 | this._element.focus(); |
| 1178 | return true; |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 1179 | } else if (this._selectNearestVisibleChild(focusedChildIndex - 1, true /* backwards */)) { |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1180 | return true; |
| 1181 | } |
| 1182 | } |
| 1183 | if (event.key === 'ArrowDown') { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1184 | if (isWrapperFocused && this._selectNearestVisibleChild(0)) { |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1185 | return true; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1186 | } |
| 1187 | if (!isWrapperFocused && this._selectNearestVisibleChild(focusedChildIndex + 1)) { |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1188 | return true; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1189 | } |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1190 | } |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1191 | return false; |
| 1192 | } |
| 1193 | |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 1194 | /** |
| 1195 | * @param {number} fromIndex |
| 1196 | * @param {boolean=} backwards |
| 1197 | * @return {boolean} |
| 1198 | */ |
| 1199 | _selectNearestVisibleChild(fromIndex, backwards) { |
| 1200 | const nearestChild = this._nearestVisibleChild(fromIndex, backwards); |
| 1201 | if (nearestChild) { |
Erik Luo | 31c21f6 | 2018-12-13 03:39:39 | [diff] [blame] | 1202 | nearestChild.forceSelect(); |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 1203 | return true; |
| 1204 | } |
| 1205 | return false; |
| 1206 | } |
| 1207 | |
| 1208 | /** |
| 1209 | * @param {number} fromIndex |
| 1210 | * @param {boolean=} backwards |
Erik Luo | 31c21f6 | 2018-12-13 03:39:39 | [diff] [blame] | 1211 | * @return {?{element: !Element, forceSelect: function()}} |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 1212 | */ |
| 1213 | _nearestVisibleChild(fromIndex, backwards) { |
| 1214 | const childCount = this._selectableChildren.length; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1215 | if (fromIndex < 0 || fromIndex >= childCount) { |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 1216 | return null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1217 | } |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 1218 | const direction = backwards ? -1 : 1; |
| 1219 | let index = fromIndex; |
| 1220 | |
| 1221 | while (!this._selectableChildren[index].element.offsetParent) { |
| 1222 | index += direction; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1223 | if (index < 0 || index >= childCount) { |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 1224 | return null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1225 | } |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 1226 | } |
| 1227 | return this._selectableChildren[index]; |
| 1228 | } |
| 1229 | |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1230 | focusLastChildOrSelf() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1231 | if (this._element && !this._selectNearestVisibleChild(this._selectableChildren.length - 1, true /* backwards */)) { |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1232 | this._element.focus(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1233 | } |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1234 | } |
| 1235 | |
| 1236 | /** |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1237 | * @return {!Element} |
| 1238 | */ |
| 1239 | contentElement() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1240 | if (this._contentElement) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1241 | return this._contentElement; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1242 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1243 | |
| 1244 | const contentElement = createElementWithClass('div', 'console-message'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1245 | if (this._messageLevelIcon) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1246 | contentElement.appendChild(this._messageLevelIcon); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1247 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1248 | this._contentElement = contentElement; |
| 1249 | |
| 1250 | let formattedMessage; |
| 1251 | const shouldIncludeTrace = !!this._message.stackTrace && |
| 1252 | (this._message.source === SDK.ConsoleMessage.MessageSource.Network || |
| 1253 | this._message.source === SDK.ConsoleMessage.MessageSource.Violation || |
| 1254 | this._message.level === SDK.ConsoleMessage.MessageLevel.Error || |
| 1255 | this._message.level === SDK.ConsoleMessage.MessageLevel.Warning || |
| 1256 | this._message.type === SDK.ConsoleMessage.MessageType.Trace); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1257 | if (this._message.runtimeModel() && shouldIncludeTrace) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1258 | formattedMessage = this._buildMessageWithStackTrace(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1259 | } else if (this._message.type === SDK.ConsoleMessage.MessageType.Table) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1260 | formattedMessage = this._buildTableMessage(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1261 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1262 | formattedMessage = this._buildMessage(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1263 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1264 | contentElement.appendChild(formattedMessage); |
| 1265 | |
| 1266 | this.updateTimestamp(); |
| 1267 | return this._contentElement; |
| 1268 | } |
| 1269 | |
| 1270 | /** |
| 1271 | * @return {!Element} |
| 1272 | */ |
| 1273 | toMessageElement() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1274 | if (this._element) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1275 | return this._element; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1276 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1277 | |
| 1278 | this._element = createElement('div'); |
Pavel Feldman | db31091 | 2019-01-30 00:31:20 | [diff] [blame] | 1279 | this._element.tabIndex = -1; |
| 1280 | this._element.addEventListener('keydown', this._onKeyDown.bind(this)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1281 | this.updateMessageElement(); |
| 1282 | return this._element; |
| 1283 | } |
| 1284 | |
| 1285 | updateMessageElement() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1286 | if (!this._element) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1287 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1288 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1289 | |
| 1290 | this._element.className = 'console-message-wrapper'; |
| 1291 | this._element.removeChildren(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1292 | if (this._message.isGroupStartMessage()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1293 | this._element.classList.add('console-group-title'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1294 | } |
| 1295 | if (this._message.source === SDK.ConsoleMessage.MessageSource.ConsoleAPI) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1296 | this._element.classList.add('console-from-api'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1297 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1298 | if (this._inSimilarGroup) { |
| 1299 | this._similarGroupMarker = this._element.createChild('div', 'nesting-level-marker'); |
| 1300 | this._similarGroupMarker.classList.toggle('group-closed', this._lastInSimilarGroup); |
| 1301 | } |
| 1302 | |
| 1303 | this._nestingLevelMarkers = []; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1304 | for (let i = 0; i < this._nestingLevel; ++i) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1305 | this._nestingLevelMarkers.push(this._element.createChild('div', 'nesting-level-marker')); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1306 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1307 | this._updateCloseGroupDecorations(); |
| 1308 | this._element.message = this; |
| 1309 | |
| 1310 | switch (this._message.level) { |
| 1311 | case SDK.ConsoleMessage.MessageLevel.Verbose: |
| 1312 | this._element.classList.add('console-verbose-level'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1313 | break; |
| 1314 | case SDK.ConsoleMessage.MessageLevel.Info: |
| 1315 | this._element.classList.add('console-info-level'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1316 | if (this._message.type === SDK.ConsoleMessage.MessageType.System) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1317 | this._element.classList.add('console-system-type'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1318 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1319 | break; |
| 1320 | case SDK.ConsoleMessage.MessageLevel.Warning: |
| 1321 | this._element.classList.add('console-warning-level'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1322 | break; |
| 1323 | case SDK.ConsoleMessage.MessageLevel.Error: |
| 1324 | this._element.classList.add('console-error-level'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1325 | break; |
| 1326 | } |
Erik Luo | fd3e7d4 | 2018-09-25 02:12:35 | [diff] [blame] | 1327 | this._updateMessageLevelIcon(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1328 | if (this._shouldRenderAsWarning()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1329 | this._element.classList.add('console-warning-level'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1330 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1331 | |
| 1332 | this._element.appendChild(this.contentElement()); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1333 | if (this._repeatCount > 1) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1334 | this._showRepeatCountElement(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1335 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1336 | } |
| 1337 | |
| 1338 | /** |
| 1339 | * @return {boolean} |
| 1340 | */ |
| 1341 | _shouldRenderAsWarning() { |
| 1342 | return (this._message.level === SDK.ConsoleMessage.MessageLevel.Verbose || |
| 1343 | this._message.level === SDK.ConsoleMessage.MessageLevel.Info) && |
| 1344 | (this._message.source === SDK.ConsoleMessage.MessageSource.Violation || |
| 1345 | this._message.source === SDK.ConsoleMessage.MessageSource.Deprecation || |
| 1346 | this._message.source === SDK.ConsoleMessage.MessageSource.Intervention || |
| 1347 | this._message.source === SDK.ConsoleMessage.MessageSource.Recommendation); |
| 1348 | } |
| 1349 | |
Erik Luo | fd3e7d4 | 2018-09-25 02:12:35 | [diff] [blame] | 1350 | _updateMessageLevelIcon() { |
| 1351 | let iconType = ''; |
| 1352 | let accessibleName = ''; |
| 1353 | if (this._message.level === SDK.ConsoleMessage.MessageLevel.Warning) { |
| 1354 | iconType = 'smallicon-warning'; |
| 1355 | accessibleName = ls`Warning`; |
| 1356 | } else if (this._message.level === SDK.ConsoleMessage.MessageLevel.Error) { |
| 1357 | iconType = 'smallicon-error'; |
| 1358 | accessibleName = ls`Error`; |
| 1359 | } |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1360 | if (!iconType && !this._messageLevelIcon) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1361 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1362 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1363 | if (iconType && !this._messageLevelIcon) { |
| 1364 | this._messageLevelIcon = UI.Icon.create('', 'message-level-icon'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1365 | if (this._contentElement) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1366 | this._contentElement.insertBefore(this._messageLevelIcon, this._contentElement.firstChild); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1367 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1368 | } |
| 1369 | this._messageLevelIcon.setIconType(iconType); |
Erik Luo | fd3e7d4 | 2018-09-25 02:12:35 | [diff] [blame] | 1370 | UI.ARIAUtils.setAccessibleName(this._messageLevelIcon, accessibleName); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1371 | } |
| 1372 | |
| 1373 | /** |
| 1374 | * @return {number} |
| 1375 | */ |
| 1376 | repeatCount() { |
| 1377 | return this._repeatCount || 1; |
| 1378 | } |
| 1379 | |
| 1380 | resetIncrementRepeatCount() { |
| 1381 | this._repeatCount = 1; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1382 | if (!this._repeatCountElement) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1383 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1384 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1385 | |
| 1386 | this._repeatCountElement.remove(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1387 | if (this._contentElement) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1388 | this._contentElement.classList.remove('repeated-message'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1389 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1390 | delete this._repeatCountElement; |
| 1391 | } |
| 1392 | |
| 1393 | incrementRepeatCount() { |
| 1394 | this._repeatCount++; |
| 1395 | this._showRepeatCountElement(); |
| 1396 | } |
| 1397 | |
| 1398 | /** |
| 1399 | * @param {number} repeatCount |
| 1400 | */ |
| 1401 | setRepeatCount(repeatCount) { |
| 1402 | this._repeatCount = repeatCount; |
| 1403 | this._showRepeatCountElement(); |
| 1404 | } |
| 1405 | |
| 1406 | _showRepeatCountElement() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1407 | if (!this._element) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1408 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1409 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1410 | |
| 1411 | if (!this._repeatCountElement) { |
Joel Einbinder | 7fbe24c | 2019-01-24 05:19:01 | [diff] [blame] | 1412 | this._repeatCountElement = createElementWithClass('span', 'console-message-repeat-count', 'dt-small-bubble'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1413 | switch (this._message.level) { |
| 1414 | case SDK.ConsoleMessage.MessageLevel.Warning: |
| 1415 | this._repeatCountElement.type = 'warning'; |
| 1416 | break; |
| 1417 | case SDK.ConsoleMessage.MessageLevel.Error: |
| 1418 | this._repeatCountElement.type = 'error'; |
| 1419 | break; |
| 1420 | case SDK.ConsoleMessage.MessageLevel.Verbose: |
| 1421 | this._repeatCountElement.type = 'verbose'; |
| 1422 | break; |
| 1423 | default: |
| 1424 | this._repeatCountElement.type = 'info'; |
| 1425 | } |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1426 | if (this._shouldRenderAsWarning()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1427 | this._repeatCountElement.type = 'warning'; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1428 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1429 | |
| 1430 | this._element.insertBefore(this._repeatCountElement, this._contentElement); |
| 1431 | this._contentElement.classList.add('repeated-message'); |
| 1432 | } |
| 1433 | this._repeatCountElement.textContent = this._repeatCount; |
Erik Luo | fd3e7d4 | 2018-09-25 02:12:35 | [diff] [blame] | 1434 | let accessibleName = ls`Repeat ${this._repeatCount}`; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1435 | if (this._message.level === SDK.ConsoleMessage.MessageLevel.Warning) { |
Erik Luo | fd3e7d4 | 2018-09-25 02:12:35 | [diff] [blame] | 1436 | accessibleName = ls`Warning ${accessibleName}`; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1437 | } else if (this._message.level === SDK.ConsoleMessage.MessageLevel.Error) { |
Erik Luo | fd3e7d4 | 2018-09-25 02:12:35 | [diff] [blame] | 1438 | accessibleName = ls`Error ${accessibleName}`; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1439 | } |
Erik Luo | fd3e7d4 | 2018-09-25 02:12:35 | [diff] [blame] | 1440 | UI.ARIAUtils.setAccessibleName(this._repeatCountElement, accessibleName); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1441 | } |
| 1442 | |
| 1443 | get text() { |
| 1444 | return this._message.messageText; |
| 1445 | } |
| 1446 | |
| 1447 | /** |
| 1448 | * @return {string} |
| 1449 | */ |
| 1450 | toExportString() { |
| 1451 | const lines = []; |
| 1452 | const nodes = this.contentElement().childTextNodes(); |
| 1453 | const messageContent = nodes.map(Components.Linkifier.untruncatedNodeText).join(''); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1454 | for (let i = 0; i < this.repeatCount(); ++i) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1455 | lines.push(messageContent); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1456 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1457 | return lines.join('\n'); |
| 1458 | } |
| 1459 | |
| 1460 | /** |
| 1461 | * @param {?RegExp} regex |
| 1462 | */ |
| 1463 | setSearchRegex(regex) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1464 | if (this._searchHiglightNodeChanges && this._searchHiglightNodeChanges.length) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1465 | UI.revertDomChanges(this._searchHiglightNodeChanges); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1466 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1467 | this._searchRegex = regex; |
| 1468 | this._searchHighlightNodes = []; |
| 1469 | this._searchHiglightNodeChanges = []; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1470 | if (!this._searchRegex) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1471 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1472 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1473 | |
| 1474 | const text = this.contentElement().deepTextContent(); |
| 1475 | let match; |
| 1476 | this._searchRegex.lastIndex = 0; |
| 1477 | const sourceRanges = []; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1478 | while ((match = this._searchRegex.exec(text)) && match[0]) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1479 | sourceRanges.push(new TextUtils.SourceRange(match.index, match[0].length)); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1480 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1481 | |
| 1482 | if (sourceRanges.length) { |
| 1483 | this._searchHighlightNodes = |
| 1484 | UI.highlightSearchResults(this.contentElement(), sourceRanges, this._searchHiglightNodeChanges); |
| 1485 | } |
| 1486 | } |
| 1487 | |
| 1488 | /** |
| 1489 | * @return {?RegExp} |
| 1490 | */ |
| 1491 | searchRegex() { |
| 1492 | return this._searchRegex; |
| 1493 | } |
| 1494 | |
| 1495 | /** |
| 1496 | * @return {number} |
| 1497 | */ |
| 1498 | searchCount() { |
| 1499 | return this._searchHighlightNodes.length; |
| 1500 | } |
| 1501 | |
| 1502 | /** |
| 1503 | * @return {!Element} |
| 1504 | */ |
| 1505 | searchHighlightNode(index) { |
| 1506 | return this._searchHighlightNodes[index]; |
| 1507 | } |
| 1508 | |
| 1509 | /** |
| 1510 | * @param {string} string |
| 1511 | * @return {?Element} |
| 1512 | */ |
| 1513 | _tryFormatAsError(string) { |
| 1514 | /** |
| 1515 | * @param {string} prefix |
| 1516 | */ |
| 1517 | function startsWith(prefix) { |
| 1518 | return string.startsWith(prefix); |
| 1519 | } |
| 1520 | |
| 1521 | const errorPrefixes = |
| 1522 | ['EvalError', 'ReferenceError', 'SyntaxError', 'TypeError', 'RangeError', 'Error', 'URIError']; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1523 | if (!this._message.runtimeModel() || !errorPrefixes.some(startsWith)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1524 | return null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1525 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1526 | const debuggerModel = this._message.runtimeModel().debuggerModel(); |
| 1527 | const baseURL = this._message.runtimeModel().target().inspectedURL(); |
| 1528 | |
| 1529 | const lines = string.split('\n'); |
| 1530 | const links = []; |
| 1531 | let position = 0; |
| 1532 | for (let i = 0; i < lines.length; ++i) { |
| 1533 | position += i > 0 ? lines[i - 1].length + 1 : 0; |
| 1534 | const isCallFrameLine = /^\s*at\s/.test(lines[i]); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1535 | if (!isCallFrameLine && links.length) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1536 | return null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1537 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1538 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1539 | if (!isCallFrameLine) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1540 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1541 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1542 | |
| 1543 | let openBracketIndex = -1; |
| 1544 | let closeBracketIndex = -1; |
Yang Guo | 39256bd | 2019-07-18 06:02:25 | [diff] [blame] | 1545 | const inBracketsWithLineAndColumn = /\([^\)\(]+:\d+:\d+\)/g; |
| 1546 | const inBrackets = /\([^\)\(]+\)/g; |
| 1547 | let lastMatch = null; |
| 1548 | let currentMatch; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1549 | while ((currentMatch = inBracketsWithLineAndColumn.exec(lines[i]))) { |
Yang Guo | 39256bd | 2019-07-18 06:02:25 | [diff] [blame] | 1550 | lastMatch = currentMatch; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1551 | } |
Yang Guo | 39256bd | 2019-07-18 06:02:25 | [diff] [blame] | 1552 | if (!lastMatch) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1553 | while ((currentMatch = inBrackets.exec(lines[i]))) { |
Yang Guo | 39256bd | 2019-07-18 06:02:25 | [diff] [blame] | 1554 | lastMatch = currentMatch; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1555 | } |
Yang Guo | 39256bd | 2019-07-18 06:02:25 | [diff] [blame] | 1556 | } |
| 1557 | if (lastMatch) { |
| 1558 | openBracketIndex = lastMatch.index; |
| 1559 | closeBracketIndex = lastMatch.index + lastMatch[0].length - 1; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1560 | } |
| 1561 | const hasOpenBracket = openBracketIndex !== -1; |
| 1562 | const left = hasOpenBracket ? openBracketIndex + 1 : lines[i].indexOf('at') + 3; |
| 1563 | const right = hasOpenBracket ? closeBracketIndex : lines[i].length; |
| 1564 | const linkCandidate = lines[i].substring(left, right); |
| 1565 | const splitResult = Common.ParsedURL.splitLineAndColumn(linkCandidate); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1566 | if (!splitResult) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1567 | return null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1568 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1569 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1570 | if (splitResult.url === '<anonymous>') { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1571 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1572 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1573 | let url = parseOrScriptMatch(splitResult.url); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1574 | if (!url && Common.ParsedURL.isRelativeURL(splitResult.url)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1575 | url = parseOrScriptMatch(Common.ParsedURL.completeURL(baseURL, splitResult.url)); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1576 | } |
| 1577 | if (!url) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1578 | return null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1579 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1580 | |
| 1581 | links.push({ |
| 1582 | url: url, |
| 1583 | positionLeft: position + left, |
| 1584 | positionRight: position + right, |
| 1585 | lineNumber: splitResult.lineNumber, |
| 1586 | columnNumber: splitResult.columnNumber |
| 1587 | }); |
| 1588 | } |
| 1589 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1590 | if (!links.length) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1591 | return null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1592 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1593 | |
| 1594 | const formattedResult = createElement('span'); |
| 1595 | let start = 0; |
| 1596 | for (let i = 0; i < links.length; ++i) { |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 1597 | formattedResult.appendChild(this._linkifyStringAsFragment(string.substring(start, links[i].positionLeft))); |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 1598 | const scriptLocationLink = this._linkifier.linkifyScriptLocation( |
| 1599 | debuggerModel.target(), null, links[i].url, links[i].lineNumber, links[i].columnNumber); |
| 1600 | scriptLocationLink.tabIndex = -1; |
Erik Luo | 31c21f6 | 2018-12-13 03:39:39 | [diff] [blame] | 1601 | this._selectableChildren.push({element: scriptLocationLink, forceSelect: () => scriptLocationLink.focus()}); |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 1602 | formattedResult.appendChild(scriptLocationLink); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1603 | start = links[i].positionRight; |
| 1604 | } |
| 1605 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1606 | if (start !== string.length) { |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 1607 | formattedResult.appendChild(this._linkifyStringAsFragment(string.substring(start))); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1608 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1609 | |
| 1610 | return formattedResult; |
| 1611 | |
| 1612 | /** |
| 1613 | * @param {?string} url |
| 1614 | * @return {?string} |
| 1615 | */ |
| 1616 | function parseOrScriptMatch(url) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1617 | if (!url) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1618 | return null; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1619 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1620 | const parsedURL = url.asParsedURL(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1621 | if (parsedURL) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1622 | return parsedURL.url; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1623 | } |
| 1624 | if (debuggerModel.scriptsForSourceURL(url).length) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1625 | return url; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1626 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1627 | return null; |
| 1628 | } |
| 1629 | } |
| 1630 | |
| 1631 | /** |
| 1632 | * @param {string} string |
| 1633 | * @param {function(string,string,number=,number=):!Node} linkifier |
| 1634 | * @return {!DocumentFragment} |
| 1635 | */ |
Erik Luo | fc2214f | 2018-11-21 19:54:58 | [diff] [blame] | 1636 | _linkifyWithCustomLinkifier(string, linkifier) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1637 | if (string.length > Console.ConsoleViewMessage._MaxTokenizableStringLength) { |
Erik Luo | 5fb33bd | 2018-06-04 23:23:52 | [diff] [blame] | 1638 | return UI.createExpandableText(string, Console.ConsoleViewMessage._LongStringVisibleLength); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1639 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1640 | const container = createDocumentFragment(); |
Erik Luo | fc2214f | 2018-11-21 19:54:58 | [diff] [blame] | 1641 | const tokens = Console.ConsoleViewMessage._tokenizeMessageText(string); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1642 | for (const token of tokens) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1643 | if (!token.text) { |
Erik Luo | fc2214f | 2018-11-21 19:54:58 | [diff] [blame] | 1644 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1645 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1646 | switch (token.type) { |
| 1647 | case 'url': { |
| 1648 | const realURL = (token.text.startsWith('www.') ? 'http://' + token.text : token.text); |
| 1649 | const splitResult = Common.ParsedURL.splitLineAndColumn(realURL); |
| 1650 | let linkNode; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1651 | if (splitResult) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1652 | linkNode = linkifier(token.text, splitResult.url, splitResult.lineNumber, splitResult.columnNumber); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1653 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1654 | linkNode = linkifier(token.text, token.value); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1655 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1656 | container.appendChild(linkNode); |
| 1657 | break; |
| 1658 | } |
| 1659 | default: |
| 1660 | container.appendChild(createTextNode(token.text)); |
| 1661 | break; |
| 1662 | } |
| 1663 | } |
| 1664 | return container; |
| 1665 | } |
| 1666 | |
| 1667 | /** |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1668 | * @param {string} string |
| 1669 | * @return {!DocumentFragment} |
| 1670 | */ |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 1671 | _linkifyStringAsFragment(string) { |
Erik Luo | fc2214f | 2018-11-21 19:54:58 | [diff] [blame] | 1672 | return this._linkifyWithCustomLinkifier(string, (text, url, lineNumber, columnNumber) => { |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 1673 | const linkElement = Components.Linkifier.linkifyURL(url, {text, lineNumber, columnNumber}); |
| 1674 | linkElement.tabIndex = -1; |
Erik Luo | 31c21f6 | 2018-12-13 03:39:39 | [diff] [blame] | 1675 | this._selectableChildren.push({element: linkElement, forceSelect: () => linkElement.focus()}); |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 1676 | return linkElement; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1677 | }); |
| 1678 | } |
| 1679 | |
| 1680 | /** |
| 1681 | * @param {string} string |
| 1682 | * @return {!Array<{type: string, text: (string|undefined)}>} |
| 1683 | */ |
| 1684 | static _tokenizeMessageText(string) { |
| 1685 | if (!Console.ConsoleViewMessage._tokenizerRegexes) { |
| 1686 | const controlCodes = '\\u0000-\\u0020\\u007f-\\u009f'; |
| 1687 | const linkStringRegex = new RegExp( |
| 1688 | '(?:[a-zA-Z][a-zA-Z0-9+.-]{2,}:\\/\\/|data:|www\\.)[^\\s' + controlCodes + '"]{2,}[^\\s' + controlCodes + |
| 1689 | '"\')}\\],:;.!?]', |
| 1690 | 'u'); |
| 1691 | const pathLineRegex = /(?:\/[\w\.-]*)+\:[\d]+/; |
| 1692 | const timeRegex = /took [\d]+ms/; |
| 1693 | const eventRegex = /'\w+' event/; |
| 1694 | const milestoneRegex = /\sM[6-7]\d/; |
| 1695 | const autofillRegex = /\(suggested: \"[\w-]+\"\)/; |
| 1696 | const handlers = new Map(); |
| 1697 | handlers.set(linkStringRegex, 'url'); |
| 1698 | handlers.set(pathLineRegex, 'url'); |
| 1699 | handlers.set(timeRegex, 'time'); |
| 1700 | handlers.set(eventRegex, 'event'); |
| 1701 | handlers.set(milestoneRegex, 'milestone'); |
| 1702 | handlers.set(autofillRegex, 'autofill'); |
| 1703 | Console.ConsoleViewMessage._tokenizerRegexes = Array.from(handlers.keys()); |
| 1704 | Console.ConsoleViewMessage._tokenizerTypes = Array.from(handlers.values()); |
| 1705 | } |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1706 | if (string.length > Console.ConsoleViewMessage._MaxTokenizableStringLength) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1707 | return [{text: string, type: undefined}]; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1708 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1709 | const results = TextUtils.TextUtils.splitStringByRegexes(string, Console.ConsoleViewMessage._tokenizerRegexes); |
| 1710 | return results.map( |
| 1711 | result => ({text: result.value, type: Console.ConsoleViewMessage._tokenizerTypes[result.regexIndex]})); |
| 1712 | } |
| 1713 | |
| 1714 | /** |
| 1715 | * @return {string} |
| 1716 | */ |
| 1717 | groupKey() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1718 | if (!this._groupKey) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1719 | this._groupKey = this._message.groupCategoryKey() + ':' + this.groupTitle(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1720 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1721 | return this._groupKey; |
| 1722 | } |
| 1723 | |
| 1724 | /** |
| 1725 | * @return {string} |
| 1726 | */ |
| 1727 | groupTitle() { |
| 1728 | const tokens = Console.ConsoleViewMessage._tokenizeMessageText(this._message.messageText); |
| 1729 | const result = tokens.reduce((acc, token) => { |
| 1730 | let text = token.text; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1731 | if (token.type === 'url') { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1732 | text = Common.UIString('<URL>'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1733 | } else if (token.type === 'time') { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1734 | text = Common.UIString('took <N>ms'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1735 | } else if (token.type === 'event') { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1736 | text = Common.UIString('<some> event'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1737 | } else if (token.type === 'milestone') { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1738 | text = Common.UIString(' M<XX>'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1739 | } else if (token.type === 'autofill') { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1740 | text = Common.UIString('<attribute>'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1741 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1742 | return acc + text; |
| 1743 | }, ''); |
| 1744 | return result.replace(/[%]o/g, ''); |
| 1745 | } |
| 1746 | }; |
| 1747 | |
| 1748 | /** |
| 1749 | * @unrestricted |
| 1750 | */ |
| 1751 | Console.ConsoleGroupViewMessage = class extends Console.ConsoleViewMessage { |
| 1752 | /** |
| 1753 | * @param {!SDK.ConsoleMessage} consoleMessage |
| 1754 | * @param {!Components.Linkifier} linkifier |
| 1755 | * @param {!ProductRegistry.BadgePool} badgePool |
| 1756 | * @param {number} nestingLevel |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1757 | * @param {function()} onToggle |
Erik Luo | 840be6b | 2018-12-03 20:54:27 | [diff] [blame] | 1758 | * @param {function(!Common.Event)} onResize |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1759 | */ |
Erik Luo | 840be6b | 2018-12-03 20:54:27 | [diff] [blame] | 1760 | constructor(consoleMessage, linkifier, badgePool, nestingLevel, onToggle, onResize) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1761 | console.assert(consoleMessage.isGroupStartMessage()); |
Erik Luo | 840be6b | 2018-12-03 20:54:27 | [diff] [blame] | 1762 | super(consoleMessage, linkifier, badgePool, nestingLevel, onResize); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1763 | this._collapsed = consoleMessage.type === SDK.ConsoleMessage.MessageType.StartGroupCollapsed; |
| 1764 | /** @type {?UI.Icon} */ |
| 1765 | this._expandGroupIcon = null; |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1766 | this._onToggle = onToggle; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1767 | } |
| 1768 | |
| 1769 | /** |
| 1770 | * @param {boolean} collapsed |
| 1771 | */ |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1772 | _setCollapsed(collapsed) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1773 | this._collapsed = collapsed; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1774 | if (this._expandGroupIcon) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1775 | this._expandGroupIcon.setIconType(this._collapsed ? 'smallicon-triangle-right' : 'smallicon-triangle-down'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1776 | } |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1777 | this._onToggle.call(null); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1778 | } |
| 1779 | |
| 1780 | /** |
| 1781 | * @return {boolean} |
| 1782 | */ |
| 1783 | collapsed() { |
| 1784 | return this._collapsed; |
| 1785 | } |
| 1786 | |
| 1787 | /** |
| 1788 | * @override |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1789 | * @param {!Event} event |
| 1790 | */ |
| 1791 | maybeHandleOnKeyDown(event) { |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1792 | const focusedChildIndex = this._focusedChildIndex(); |
| 1793 | if (focusedChildIndex === -1) { |
| 1794 | if ((event.key === 'ArrowLeft' && !this._collapsed) || (event.key === 'ArrowRight' && this._collapsed)) { |
| 1795 | this._setCollapsed(!this._collapsed); |
| 1796 | return true; |
| 1797 | } |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1798 | } |
| 1799 | return super.maybeHandleOnKeyDown(event); |
| 1800 | } |
| 1801 | |
| 1802 | /** |
| 1803 | * @override |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1804 | * @return {!Element} |
| 1805 | */ |
| 1806 | toMessageElement() { |
| 1807 | if (!this._element) { |
| 1808 | super.toMessageElement(); |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1809 | const iconType = this._collapsed ? 'smallicon-triangle-right' : 'smallicon-triangle-down'; |
| 1810 | this._expandGroupIcon = UI.Icon.create(iconType, 'expand-group-icon'); |
Erik Luo | b5bfff4 | 2018-09-20 02:52:39 | [diff] [blame] | 1811 | // Intercept focus to avoid highlight on click. |
| 1812 | this._contentElement.tabIndex = -1; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1813 | if (this._repeatCountElement) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1814 | this._repeatCountElement.insertBefore(this._expandGroupIcon, this._repeatCountElement.firstChild); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1815 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1816 | this._element.insertBefore(this._expandGroupIcon, this._contentElement); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1817 | } |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1818 | this._element.addEventListener('click', () => this._setCollapsed(!this._collapsed)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1819 | } |
| 1820 | return this._element; |
| 1821 | } |
| 1822 | |
| 1823 | /** |
| 1824 | * @override |
| 1825 | */ |
| 1826 | _showRepeatCountElement() { |
| 1827 | super._showRepeatCountElement(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1828 | if (this._repeatCountElement && this._expandGroupIcon) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1829 | this._repeatCountElement.insertBefore(this._expandGroupIcon, this._repeatCountElement.firstChild); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 1830 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1831 | } |
| 1832 | }; |
| 1833 | |
| 1834 | /** |
| 1835 | * @const |
| 1836 | * @type {number} |
| 1837 | */ |
| 1838 | Console.ConsoleViewMessage.MaxLengthForLinks = 40; |
| 1839 | |
| 1840 | Console.ConsoleViewMessage._MaxTokenizableStringLength = 10000; |
| 1841 | |
| 1842 | Console.ConsoleViewMessage._LongStringVisibleLength = 5000; |