Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
| 3 | * Copyright (C) 2011 Google Inc. All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 15 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 18 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 21 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 22 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 | */ |
Tim van der Lippe | 8987f8f | 2020-01-03 15:03:16 | [diff] [blame] | 26 | |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 27 | import * as Common from '../common/common.js'; |
| 28 | import * as Components from '../components/components.js'; |
| 29 | import * as ObjectUI from '../object_ui/object_ui.js'; |
| 30 | import * as SDK from '../sdk/sdk.js'; |
| 31 | import * as UI from '../ui/ui.js'; |
| 32 | |
Paul Lewis | 3994495 | 2020-01-22 15:45:18 | [diff] [blame] | 33 | import {resolveScopeInObject, resolveThisObject} from './SourceMapNamesResolver.js'; |
| 34 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 35 | /** |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 36 | * @implements {UI.ContextFlavorListener.ContextFlavorListener} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 37 | * @unrestricted |
| 38 | */ |
Philip Pfaffe | 674ff27 | 2020-04-30 13:55:52 | [diff] [blame] | 39 | export class ScopeChainSidebarPane extends UI.Widget.VBox { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 40 | constructor() { |
| 41 | super(true); |
| 42 | this.registerRequiredCSS('sources/scopeChainSidebarPane.css'); |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 43 | this._treeOutline = new ObjectUI.ObjectPropertiesSection.ObjectPropertiesSectionsTreeOutline(); |
Jack Lynch | 2938cf3 | 2019-11-05 19:24:12 | [diff] [blame] | 44 | this._treeOutline.registerRequiredCSS('sources/scopeChainSidebarPane.css'); |
| 45 | this._treeOutline.setShowSelectionOnKeyboardFocus(/* show */ true); |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 46 | this._expandController = |
| 47 | new ObjectUI.ObjectPropertiesSection.ObjectPropertiesSectionsTreeExpandController(this._treeOutline); |
| 48 | this._linkifier = new Components.Linkifier.Linkifier(); |
Simon Zünd | 51a46de | 2020-09-22 13:52:44 | [diff] [blame] | 49 | this._infoElement = document.createElement('div'); |
Jack Lynch | 2938cf3 | 2019-11-05 19:24:12 | [diff] [blame] | 50 | this._infoElement.className = 'gray-info-message'; |
| 51 | this._infoElement.textContent = ls`Not paused`; |
| 52 | this._infoElement.tabIndex = -1; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 53 | this._update(); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * @override |
| 58 | * @param {?Object} object |
| 59 | */ |
| 60 | flavorChanged(object) { |
| 61 | this._update(); |
| 62 | } |
| 63 | |
Jack Lynch | 2938cf3 | 2019-11-05 19:24:12 | [diff] [blame] | 64 | /** |
| 65 | * @override |
| 66 | */ |
| 67 | focus() { |
| 68 | if (this.hasFocus()) { |
| 69 | return; |
| 70 | } |
| 71 | |
Tim van der Lippe | d1a00aa | 2020-08-19 16:03:56 | [diff] [blame] | 72 | if (UI.Context.Context.instance().flavor(SDK.DebuggerModel.DebuggerPausedDetails)) { |
Jack Lynch | 2938cf3 | 2019-11-05 19:24:12 | [diff] [blame] | 73 | this._treeOutline.forceSelect(); |
| 74 | } |
| 75 | } |
| 76 | |
Simon Zünd | 51a46de | 2020-09-22 13:52:44 | [diff] [blame] | 77 | /** |
| 78 | * @param {!SDK.DebuggerModel.CallFrame} callFrame |
Benedikt Meurer | fa97163 | 2020-10-23 08:42:05 | [diff] [blame^] | 79 | * @return {!Promise<!Array<!SDK.DebuggerModel.ScopeChainEntry>>} |
Simon Zünd | 51a46de | 2020-09-22 13:52:44 | [diff] [blame] | 80 | */ |
Benedikt Meurer | fa97163 | 2020-10-23 08:42:05 | [diff] [blame^] | 81 | async _getScopeChain(callFrame) { |
| 82 | return (await callFrame.sourceScopeChain) || callFrame.scopeChain(); |
Philip Pfaffe | f5d825a | 2020-01-27 16:00:53 | [diff] [blame] | 83 | } |
| 84 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 85 | _update() { |
Tim van der Lippe | d1a00aa | 2020-08-19 16:03:56 | [diff] [blame] | 86 | const callFrame = UI.Context.Context.instance().flavor(SDK.DebuggerModel.CallFrame); |
| 87 | const details = UI.Context.Context.instance().flavor(SDK.DebuggerModel.DebuggerPausedDetails); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 88 | this._linkifier.reset(); |
Paul Lewis | 3994495 | 2020-01-22 15:45:18 | [diff] [blame] | 89 | resolveThisObject(callFrame).then(this._innerUpdate.bind(this, details, callFrame)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | /** |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 93 | * @param {?SDK.DebuggerModel.DebuggerPausedDetails} details |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 94 | * @param {?SDK.DebuggerModel.CallFrame} callFrame |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 95 | * @param {?SDK.RemoteObject.RemoteObject} thisObject |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 96 | */ |
Benedikt Meurer | fa97163 | 2020-10-23 08:42:05 | [diff] [blame^] | 97 | async _innerUpdate(details, callFrame, thisObject) { |
Jack Lynch | 2938cf3 | 2019-11-05 19:24:12 | [diff] [blame] | 98 | this._treeOutline.removeChildren(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 99 | this.contentElement.removeChildren(); |
| 100 | |
| 101 | if (!details || !callFrame) { |
Jack Lynch | 2938cf3 | 2019-11-05 19:24:12 | [diff] [blame] | 102 | this.contentElement.appendChild(this._infoElement); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 103 | return; |
| 104 | } |
| 105 | |
Jack Lynch | 2938cf3 | 2019-11-05 19:24:12 | [diff] [blame] | 106 | this.contentElement.appendChild(this._treeOutline.element); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 107 | let foundLocalScope = false; |
Benedikt Meurer | fa97163 | 2020-10-23 08:42:05 | [diff] [blame^] | 108 | const scopeChain = await this._getScopeChain(callFrame); |
Philip Pfaffe | 674ff27 | 2020-04-30 13:55:52 | [diff] [blame] | 109 | for (let i = 0; i < scopeChain.length; ++i) { |
| 110 | const scope = scopeChain[i]; |
| 111 | const extraProperties = this._extraPropertiesForScope(scope, details, callFrame, thisObject, i === 0); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 112 | |
Philip Pfaffe | 674ff27 | 2020-04-30 13:55:52 | [diff] [blame] | 113 | if (scope.type() === Protocol.Debugger.ScopeType.Local) { |
| 114 | foundLocalScope = true; |
| 115 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 116 | |
Philip Pfaffe | 674ff27 | 2020-04-30 13:55:52 | [diff] [blame] | 117 | const section = this._createScopeSectionTreeElement(scope, extraProperties); |
| 118 | if (scope.type() === Protocol.Debugger.ScopeType.Global) { |
| 119 | section.collapse(); |
| 120 | } else if (!foundLocalScope || scope.type() === Protocol.Debugger.ScopeType.Local) { |
| 121 | section.expand(); |
| 122 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 123 | |
Philip Pfaffe | 674ff27 | 2020-04-30 13:55:52 | [diff] [blame] | 124 | this._treeOutline.appendChild(section); |
| 125 | if (i === 0) { |
| 126 | section.select(/* omitFocus */ true); |
Jack Lynch | 2938cf3 | 2019-11-05 19:24:12 | [diff] [blame] | 127 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 128 | } |
| 129 | this._sidebarPaneUpdatedForTest(); |
| 130 | } |
| 131 | |
Jack Lynch | 2938cf3 | 2019-11-05 19:24:12 | [diff] [blame] | 132 | /** |
Benedikt Meurer | 38243f3 | 2020-10-08 13:30:04 | [diff] [blame] | 133 | * @param {!SDK.DebuggerModel.ScopeChainEntry} scope |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 134 | * @param {!Array.<!SDK.RemoteObject.RemoteObjectProperty>} extraProperties |
Jack Lynch | 2938cf3 | 2019-11-05 19:24:12 | [diff] [blame] | 135 | * @return {!ObjectUI.ObjectPropertiesSection.RootElement} |
| 136 | */ |
| 137 | _createScopeSectionTreeElement(scope, extraProperties) { |
| 138 | let emptyPlaceholder = null; |
| 139 | if (scope.type() === Protocol.Debugger.ScopeType.Local || Protocol.Debugger.ScopeType.Closure) { |
| 140 | emptyPlaceholder = ls`No variables`; |
| 141 | } |
| 142 | |
| 143 | let title = scope.typeName(); |
| 144 | if (scope.type() === Protocol.Debugger.ScopeType.Closure) { |
| 145 | const scopeName = scope.name(); |
| 146 | if (scopeName) { |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 147 | title = ls`Closure (${UI.UIUtils.beautifyFunctionName(scopeName)})`; |
Jack Lynch | 2938cf3 | 2019-11-05 19:24:12 | [diff] [blame] | 148 | } else { |
| 149 | title = ls`Closure`; |
| 150 | } |
| 151 | } |
Simon Zünd | 51a46de | 2020-09-22 13:52:44 | [diff] [blame] | 152 | /** @type {?string} */ |
Jack Lynch | 2938cf3 | 2019-11-05 19:24:12 | [diff] [blame] | 153 | let subtitle = scope.description(); |
| 154 | if (!title || title === subtitle) { |
Simon Zünd | 51a46de | 2020-09-22 13:52:44 | [diff] [blame] | 155 | subtitle = null; |
Jack Lynch | 2938cf3 | 2019-11-05 19:24:12 | [diff] [blame] | 156 | } |
Benedikt Meurer | 723d543 | 2020-10-09 09:02:42 | [diff] [blame] | 157 | const icon = scope.icon(); |
Jack Lynch | 2938cf3 | 2019-11-05 19:24:12 | [diff] [blame] | 158 | |
Tim van der Lippe | e7f2705 | 2020-05-01 15:15:28 | [diff] [blame] | 159 | const titleElement = document.createElement('div'); |
| 160 | titleElement.classList.add('scope-chain-sidebar-pane-section-header'); |
| 161 | titleElement.classList.add('tree-element-title'); |
Benedikt Meurer | 723d543 | 2020-10-09 09:02:42 | [diff] [blame] | 162 | if (icon) { |
| 163 | const iconElement = document.createElement('img'); |
| 164 | iconElement.classList.add('scope-chain-sidebar-pane-section-icon'); |
| 165 | iconElement.src = icon; |
| 166 | titleElement.appendChild(iconElement); |
| 167 | } |
Jack Lynch | 2938cf3 | 2019-11-05 19:24:12 | [diff] [blame] | 168 | titleElement.createChild('div', 'scope-chain-sidebar-pane-section-subtitle').textContent = subtitle; |
| 169 | titleElement.createChild('div', 'scope-chain-sidebar-pane-section-title').textContent = title; |
| 170 | |
| 171 | const section = new ObjectUI.ObjectPropertiesSection.RootElement( |
Paul Lewis | 3994495 | 2020-01-22 15:45:18 | [diff] [blame] | 172 | resolveScopeInObject(scope), this._linkifier, emptyPlaceholder, |
Jack Lynch | 2938cf3 | 2019-11-05 19:24:12 | [diff] [blame] | 173 | /* ignoreHasOwnProperty */ true, extraProperties); |
| 174 | section.title = titleElement; |
| 175 | section.listItemElement.classList.add('scope-chain-sidebar-pane-section'); |
Kim-Anh Tran | 9f22ceb | 2020-05-27 09:46:54 | [diff] [blame] | 176 | section.listItemElement.setAttribute('aria-label', title); |
Jack Lynch | 2938cf3 | 2019-11-05 19:24:12 | [diff] [blame] | 177 | this._expandController.watchSection(title + (subtitle ? ':' + subtitle : ''), section); |
| 178 | |
| 179 | return section; |
| 180 | } |
| 181 | |
| 182 | /** |
Benedikt Meurer | 38243f3 | 2020-10-08 13:30:04 | [diff] [blame] | 183 | * @param {!SDK.DebuggerModel.ScopeChainEntry} scope |
Simon Zünd | 51a46de | 2020-09-22 13:52:44 | [diff] [blame] | 184 | * @param {!SDK.DebuggerModel.DebuggerPausedDetails} details |
| 185 | * @param {!SDK.DebuggerModel.CallFrame} callFrame |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 186 | * @param {?SDK.RemoteObject.RemoteObject} thisObject |
Jack Lynch | 2938cf3 | 2019-11-05 19:24:12 | [diff] [blame] | 187 | * @param {boolean} isFirstScope |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 188 | * @return {!Array.<!SDK.RemoteObject.RemoteObjectProperty>} |
Jack Lynch | 2938cf3 | 2019-11-05 19:24:12 | [diff] [blame] | 189 | */ |
| 190 | _extraPropertiesForScope(scope, details, callFrame, thisObject, isFirstScope) { |
Kim-Anh Tran | 9f22ceb | 2020-05-27 09:46:54 | [diff] [blame] | 191 | if (scope.type() !== Protocol.Debugger.ScopeType.Local || callFrame.script.isWasm()) { |
Jack Lynch | 2938cf3 | 2019-11-05 19:24:12 | [diff] [blame] | 192 | return []; |
| 193 | } |
| 194 | |
| 195 | const extraProperties = []; |
| 196 | if (thisObject) { |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 197 | extraProperties.push(new SDK.RemoteObject.RemoteObjectProperty('this', thisObject)); |
Jack Lynch | 2938cf3 | 2019-11-05 19:24:12 | [diff] [blame] | 198 | } |
| 199 | if (isFirstScope) { |
| 200 | const exception = details.exception(); |
| 201 | if (exception) { |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 202 | extraProperties.push(new SDK.RemoteObject.RemoteObjectProperty( |
| 203 | Common.UIString.UIString('Exception'), exception, undefined, undefined, undefined, undefined, undefined, |
Jack Lynch | 2938cf3 | 2019-11-05 19:24:12 | [diff] [blame] | 204 | /* synthetic */ true)); |
| 205 | } |
| 206 | const returnValue = callFrame.returnValue(); |
| 207 | if (returnValue) { |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 208 | extraProperties.push(new SDK.RemoteObject.RemoteObjectProperty( |
| 209 | Common.UIString.UIString('Return value'), returnValue, undefined, undefined, undefined, undefined, |
| 210 | undefined, |
Jack Lynch | 2938cf3 | 2019-11-05 19:24:12 | [diff] [blame] | 211 | /* synthetic */ true, callFrame.setReturnValue.bind(callFrame))); |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | return extraProperties; |
| 216 | } |
| 217 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 218 | _sidebarPaneUpdatedForTest() { |
| 219 | } |
Tim van der Lippe | 8987f8f | 2020-01-03 15:03:16 | [diff] [blame] | 220 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 221 | |
Paul Lewis | 3994495 | 2020-01-22 15:45:18 | [diff] [blame] | 222 | export const pathSymbol = Symbol('path'); |