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(); |
Jack Lynch | 2938cf3 | 2019-11-05 19:24:12 | [diff] [blame] | 49 | this._infoElement = createElement('div'); |
| 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 | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 72 | if (self.UI.context.flavor(SDK.DebuggerModel.DebuggerPausedDetails)) { |
Jack Lynch | 2938cf3 | 2019-11-05 19:24:12 | [diff] [blame] | 73 | this._treeOutline.forceSelect(); |
| 74 | } |
| 75 | } |
| 76 | |
Philip Pfaffe | f5d825a | 2020-01-27 16:00:53 | [diff] [blame] | 77 | _getScopeChain(callFrame) { |
Philip Pfaffe | 674ff27 | 2020-04-30 13:55:52 | [diff] [blame] | 78 | return callFrame.sourceScopeChain || callFrame.scopeChain(); |
Philip Pfaffe | f5d825a | 2020-01-27 16:00:53 | [diff] [blame] | 79 | } |
| 80 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 81 | _update() { |
Paul Lewis | d990734 | 2020-01-24 13:49:47 | [diff] [blame] | 82 | const callFrame = self.UI.context.flavor(SDK.DebuggerModel.CallFrame); |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 83 | const details = self.UI.context.flavor(SDK.DebuggerModel.DebuggerPausedDetails); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 84 | this._linkifier.reset(); |
Paul Lewis | 3994495 | 2020-01-22 15:45:18 | [diff] [blame] | 85 | resolveThisObject(callFrame).then(this._innerUpdate.bind(this, details, callFrame)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | /** |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 89 | * @param {?SDK.DebuggerModel.DebuggerPausedDetails} details |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 90 | * @param {?SDK.DebuggerModel.CallFrame} callFrame |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 91 | * @param {?SDK.RemoteObject.RemoteObject} thisObject |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 92 | */ |
| 93 | _innerUpdate(details, callFrame, thisObject) { |
Jack Lynch | 2938cf3 | 2019-11-05 19:24:12 | [diff] [blame] | 94 | this._treeOutline.removeChildren(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 95 | this.contentElement.removeChildren(); |
| 96 | |
| 97 | if (!details || !callFrame) { |
Jack Lynch | 2938cf3 | 2019-11-05 19:24:12 | [diff] [blame] | 98 | this.contentElement.appendChild(this._infoElement); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 99 | return; |
| 100 | } |
| 101 | |
Jack Lynch | 2938cf3 | 2019-11-05 19:24:12 | [diff] [blame] | 102 | this.contentElement.appendChild(this._treeOutline.element); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 103 | let foundLocalScope = false; |
Philip Pfaffe | f5d825a | 2020-01-27 16:00:53 | [diff] [blame] | 104 | const scopeChain = this._getScopeChain(callFrame); |
Philip Pfaffe | 674ff27 | 2020-04-30 13:55:52 | [diff] [blame] | 105 | for (let i = 0; i < scopeChain.length; ++i) { |
| 106 | const scope = scopeChain[i]; |
| 107 | const extraProperties = this._extraPropertiesForScope(scope, details, callFrame, thisObject, i === 0); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 108 | |
Philip Pfaffe | 674ff27 | 2020-04-30 13:55:52 | [diff] [blame] | 109 | if (scope.type() === Protocol.Debugger.ScopeType.Local) { |
| 110 | foundLocalScope = true; |
| 111 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 112 | |
Philip Pfaffe | 674ff27 | 2020-04-30 13:55:52 | [diff] [blame] | 113 | const section = this._createScopeSectionTreeElement(scope, extraProperties); |
| 114 | if (scope.type() === Protocol.Debugger.ScopeType.Global) { |
| 115 | section.collapse(); |
| 116 | } else if (!foundLocalScope || scope.type() === Protocol.Debugger.ScopeType.Local) { |
| 117 | section.expand(); |
| 118 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 119 | |
Philip Pfaffe | 674ff27 | 2020-04-30 13:55:52 | [diff] [blame] | 120 | this._treeOutline.appendChild(section); |
| 121 | if (i === 0) { |
| 122 | section.select(/* omitFocus */ true); |
Jack Lynch | 2938cf3 | 2019-11-05 19:24:12 | [diff] [blame] | 123 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 124 | } |
| 125 | this._sidebarPaneUpdatedForTest(); |
| 126 | } |
| 127 | |
Jack Lynch | 2938cf3 | 2019-11-05 19:24:12 | [diff] [blame] | 128 | /** |
| 129 | * @param {!SDK.DebuggerModel.Scope} scope |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 130 | * @param {!Array.<!SDK.RemoteObject.RemoteObjectProperty>} extraProperties |
Jack Lynch | 2938cf3 | 2019-11-05 19:24:12 | [diff] [blame] | 131 | * @return {!ObjectUI.ObjectPropertiesSection.RootElement} |
| 132 | */ |
| 133 | _createScopeSectionTreeElement(scope, extraProperties) { |
| 134 | let emptyPlaceholder = null; |
| 135 | if (scope.type() === Protocol.Debugger.ScopeType.Local || Protocol.Debugger.ScopeType.Closure) { |
| 136 | emptyPlaceholder = ls`No variables`; |
| 137 | } |
| 138 | |
| 139 | let title = scope.typeName(); |
| 140 | if (scope.type() === Protocol.Debugger.ScopeType.Closure) { |
| 141 | const scopeName = scope.name(); |
| 142 | if (scopeName) { |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 143 | title = ls`Closure (${UI.UIUtils.beautifyFunctionName(scopeName)})`; |
Jack Lynch | 2938cf3 | 2019-11-05 19:24:12 | [diff] [blame] | 144 | } else { |
| 145 | title = ls`Closure`; |
| 146 | } |
| 147 | } |
| 148 | let subtitle = scope.description(); |
| 149 | if (!title || title === subtitle) { |
| 150 | subtitle = undefined; |
| 151 | } |
| 152 | |
Tim van der Lippe | e7f2705 | 2020-05-01 15:15:28 | [diff] [blame] | 153 | const titleElement = document.createElement('div'); |
| 154 | titleElement.classList.add('scope-chain-sidebar-pane-section-header'); |
| 155 | titleElement.classList.add('tree-element-title'); |
Jack Lynch | 2938cf3 | 2019-11-05 19:24:12 | [diff] [blame] | 156 | titleElement.createChild('div', 'scope-chain-sidebar-pane-section-subtitle').textContent = subtitle; |
| 157 | titleElement.createChild('div', 'scope-chain-sidebar-pane-section-title').textContent = title; |
| 158 | |
| 159 | const section = new ObjectUI.ObjectPropertiesSection.RootElement( |
Paul Lewis | 3994495 | 2020-01-22 15:45:18 | [diff] [blame] | 160 | resolveScopeInObject(scope), this._linkifier, emptyPlaceholder, |
Jack Lynch | 2938cf3 | 2019-11-05 19:24:12 | [diff] [blame] | 161 | /* ignoreHasOwnProperty */ true, extraProperties); |
| 162 | section.title = titleElement; |
| 163 | section.listItemElement.classList.add('scope-chain-sidebar-pane-section'); |
Kim-Anh Tran | 9f22ceb | 2020-05-27 09:46:54 | [diff] [blame^] | 164 | section.listItemElement.setAttribute('aria-label', title); |
Jack Lynch | 2938cf3 | 2019-11-05 19:24:12 | [diff] [blame] | 165 | this._expandController.watchSection(title + (subtitle ? ':' + subtitle : ''), section); |
| 166 | |
| 167 | return section; |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * @param {!SDK.DebuggerModel.Scope} scope |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 172 | * @param {?SDK.DebuggerModel.DebuggerPausedDetails} details |
Jack Lynch | 2938cf3 | 2019-11-05 19:24:12 | [diff] [blame] | 173 | * @param {?SDK.DebuggerModel.CallFrame} callFrame |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 174 | * @param {?SDK.RemoteObject.RemoteObject} thisObject |
Jack Lynch | 2938cf3 | 2019-11-05 19:24:12 | [diff] [blame] | 175 | * @param {boolean} isFirstScope |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 176 | * @return {!Array.<!SDK.RemoteObject.RemoteObjectProperty>} |
Jack Lynch | 2938cf3 | 2019-11-05 19:24:12 | [diff] [blame] | 177 | */ |
| 178 | _extraPropertiesForScope(scope, details, callFrame, thisObject, isFirstScope) { |
Kim-Anh Tran | 9f22ceb | 2020-05-27 09:46:54 | [diff] [blame^] | 179 | if (scope.type() !== Protocol.Debugger.ScopeType.Local || callFrame.script.isWasm()) { |
Jack Lynch | 2938cf3 | 2019-11-05 19:24:12 | [diff] [blame] | 180 | return []; |
| 181 | } |
| 182 | |
| 183 | const extraProperties = []; |
| 184 | if (thisObject) { |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 185 | extraProperties.push(new SDK.RemoteObject.RemoteObjectProperty('this', thisObject)); |
Jack Lynch | 2938cf3 | 2019-11-05 19:24:12 | [diff] [blame] | 186 | } |
| 187 | if (isFirstScope) { |
| 188 | const exception = details.exception(); |
| 189 | if (exception) { |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 190 | extraProperties.push(new SDK.RemoteObject.RemoteObjectProperty( |
| 191 | Common.UIString.UIString('Exception'), exception, undefined, undefined, undefined, undefined, undefined, |
Jack Lynch | 2938cf3 | 2019-11-05 19:24:12 | [diff] [blame] | 192 | /* synthetic */ true)); |
| 193 | } |
| 194 | const returnValue = callFrame.returnValue(); |
| 195 | if (returnValue) { |
Tim van der Lippe | fbbf981 | 2020-02-13 14:43:46 | [diff] [blame] | 196 | extraProperties.push(new SDK.RemoteObject.RemoteObjectProperty( |
| 197 | Common.UIString.UIString('Return value'), returnValue, undefined, undefined, undefined, undefined, |
| 198 | undefined, |
Jack Lynch | 2938cf3 | 2019-11-05 19:24:12 | [diff] [blame] | 199 | /* synthetic */ true, callFrame.setReturnValue.bind(callFrame))); |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | return extraProperties; |
| 204 | } |
| 205 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 206 | _sidebarPaneUpdatedForTest() { |
| 207 | } |
Tim van der Lippe | 8987f8f | 2020-01-03 15:03:16 | [diff] [blame] | 208 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 209 | |
Paul Lewis | 3994495 | 2020-01-22 15:45:18 | [diff] [blame] | 210 | export const pathSymbol = Symbol('path'); |