blob: 0925e00623d436bd69839e765b0ada62787ae1b0 [file] [log] [blame]
Blink Reformat4c46d092018-04-07 15:32:371/*
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 Lippe8987f8f2020-01-03 15:03:1626
Tim van der Lippefbbf9812020-02-13 14:43:4627import * as Common from '../common/common.js';
28import * as Components from '../components/components.js';
29import * as ObjectUI from '../object_ui/object_ui.js';
30import * as SDK from '../sdk/sdk.js';
31import * as UI from '../ui/ui.js';
32
Paul Lewis39944952020-01-22 15:45:1833import {resolveScopeInObject, resolveThisObject} from './SourceMapNamesResolver.js';
34
Blink Reformat4c46d092018-04-07 15:32:3735/**
Tim van der Lippefbbf9812020-02-13 14:43:4636 * @implements {UI.ContextFlavorListener.ContextFlavorListener}
Blink Reformat4c46d092018-04-07 15:32:3737 * @unrestricted
38 */
Philip Pfaffe674ff272020-04-30 13:55:5239export class ScopeChainSidebarPane extends UI.Widget.VBox {
Blink Reformat4c46d092018-04-07 15:32:3740 constructor() {
41 super(true);
42 this.registerRequiredCSS('sources/scopeChainSidebarPane.css');
Tim van der Lippefbbf9812020-02-13 14:43:4643 this._treeOutline = new ObjectUI.ObjectPropertiesSection.ObjectPropertiesSectionsTreeOutline();
Jack Lynch2938cf32019-11-05 19:24:1244 this._treeOutline.registerRequiredCSS('sources/scopeChainSidebarPane.css');
45 this._treeOutline.setShowSelectionOnKeyboardFocus(/* show */ true);
Tim van der Lippefbbf9812020-02-13 14:43:4646 this._expandController =
47 new ObjectUI.ObjectPropertiesSection.ObjectPropertiesSectionsTreeExpandController(this._treeOutline);
48 this._linkifier = new Components.Linkifier.Linkifier();
Jack Lynch2938cf32019-11-05 19:24:1249 this._infoElement = createElement('div');
50 this._infoElement.className = 'gray-info-message';
51 this._infoElement.textContent = ls`Not paused`;
52 this._infoElement.tabIndex = -1;
Blink Reformat4c46d092018-04-07 15:32:3753 this._update();
54 }
55
56 /**
57 * @override
58 * @param {?Object} object
59 */
60 flavorChanged(object) {
61 this._update();
62 }
63
Jack Lynch2938cf32019-11-05 19:24:1264 /**
65 * @override
66 */
67 focus() {
68 if (this.hasFocus()) {
69 return;
70 }
71
Tim van der Lippefbbf9812020-02-13 14:43:4672 if (self.UI.context.flavor(SDK.DebuggerModel.DebuggerPausedDetails)) {
Jack Lynch2938cf32019-11-05 19:24:1273 this._treeOutline.forceSelect();
74 }
75 }
76
Philip Pfaffef5d825a2020-01-27 16:00:5377 _getScopeChain(callFrame) {
Philip Pfaffe674ff272020-04-30 13:55:5278 return callFrame.sourceScopeChain || callFrame.scopeChain();
Philip Pfaffef5d825a2020-01-27 16:00:5379 }
80
Blink Reformat4c46d092018-04-07 15:32:3781 _update() {
Paul Lewisd9907342020-01-24 13:49:4782 const callFrame = self.UI.context.flavor(SDK.DebuggerModel.CallFrame);
Tim van der Lippefbbf9812020-02-13 14:43:4683 const details = self.UI.context.flavor(SDK.DebuggerModel.DebuggerPausedDetails);
Blink Reformat4c46d092018-04-07 15:32:3784 this._linkifier.reset();
Paul Lewis39944952020-01-22 15:45:1885 resolveThisObject(callFrame).then(this._innerUpdate.bind(this, details, callFrame));
Blink Reformat4c46d092018-04-07 15:32:3786 }
87
88 /**
Tim van der Lippefbbf9812020-02-13 14:43:4689 * @param {?SDK.DebuggerModel.DebuggerPausedDetails} details
Blink Reformat4c46d092018-04-07 15:32:3790 * @param {?SDK.DebuggerModel.CallFrame} callFrame
Tim van der Lippefbbf9812020-02-13 14:43:4691 * @param {?SDK.RemoteObject.RemoteObject} thisObject
Blink Reformat4c46d092018-04-07 15:32:3792 */
93 _innerUpdate(details, callFrame, thisObject) {
Jack Lynch2938cf32019-11-05 19:24:1294 this._treeOutline.removeChildren();
Blink Reformat4c46d092018-04-07 15:32:3795 this.contentElement.removeChildren();
96
97 if (!details || !callFrame) {
Jack Lynch2938cf32019-11-05 19:24:1298 this.contentElement.appendChild(this._infoElement);
Blink Reformat4c46d092018-04-07 15:32:3799 return;
100 }
101
Jack Lynch2938cf32019-11-05 19:24:12102 this.contentElement.appendChild(this._treeOutline.element);
Blink Reformat4c46d092018-04-07 15:32:37103 let foundLocalScope = false;
Philip Pfaffef5d825a2020-01-27 16:00:53104 const scopeChain = this._getScopeChain(callFrame);
Philip Pfaffe674ff272020-04-30 13:55:52105 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 Reformat4c46d092018-04-07 15:32:37108
Philip Pfaffe674ff272020-04-30 13:55:52109 if (scope.type() === Protocol.Debugger.ScopeType.Local) {
110 foundLocalScope = true;
111 }
Blink Reformat4c46d092018-04-07 15:32:37112
Philip Pfaffe674ff272020-04-30 13:55:52113 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 Reformat4c46d092018-04-07 15:32:37119
Philip Pfaffe674ff272020-04-30 13:55:52120 this._treeOutline.appendChild(section);
121 if (i === 0) {
122 section.select(/* omitFocus */ true);
Jack Lynch2938cf32019-11-05 19:24:12123 }
Blink Reformat4c46d092018-04-07 15:32:37124 }
125 this._sidebarPaneUpdatedForTest();
126 }
127
Jack Lynch2938cf32019-11-05 19:24:12128 /**
129 * @param {!SDK.DebuggerModel.Scope} scope
Tim van der Lippefbbf9812020-02-13 14:43:46130 * @param {!Array.<!SDK.RemoteObject.RemoteObjectProperty>} extraProperties
Jack Lynch2938cf32019-11-05 19:24:12131 * @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 Lippefbbf9812020-02-13 14:43:46143 title = ls`Closure (${UI.UIUtils.beautifyFunctionName(scopeName)})`;
Jack Lynch2938cf32019-11-05 19:24:12144 } 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 Lippee7f27052020-05-01 15:15:28153 const titleElement = document.createElement('div');
154 titleElement.classList.add('scope-chain-sidebar-pane-section-header');
155 titleElement.classList.add('tree-element-title');
Jack Lynch2938cf32019-11-05 19:24:12156 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 Lewis39944952020-01-22 15:45:18160 resolveScopeInObject(scope), this._linkifier, emptyPlaceholder,
Jack Lynch2938cf32019-11-05 19:24:12161 /* ignoreHasOwnProperty */ true, extraProperties);
162 section.title = titleElement;
163 section.listItemElement.classList.add('scope-chain-sidebar-pane-section');
Kim-Anh Tran9f22ceb2020-05-27 09:46:54164 section.listItemElement.setAttribute('aria-label', title);
Jack Lynch2938cf32019-11-05 19:24:12165 this._expandController.watchSection(title + (subtitle ? ':' + subtitle : ''), section);
166
167 return section;
168 }
169
170 /**
171 * @param {!SDK.DebuggerModel.Scope} scope
Tim van der Lippefbbf9812020-02-13 14:43:46172 * @param {?SDK.DebuggerModel.DebuggerPausedDetails} details
Jack Lynch2938cf32019-11-05 19:24:12173 * @param {?SDK.DebuggerModel.CallFrame} callFrame
Tim van der Lippefbbf9812020-02-13 14:43:46174 * @param {?SDK.RemoteObject.RemoteObject} thisObject
Jack Lynch2938cf32019-11-05 19:24:12175 * @param {boolean} isFirstScope
Tim van der Lippefbbf9812020-02-13 14:43:46176 * @return {!Array.<!SDK.RemoteObject.RemoteObjectProperty>}
Jack Lynch2938cf32019-11-05 19:24:12177 */
178 _extraPropertiesForScope(scope, details, callFrame, thisObject, isFirstScope) {
Kim-Anh Tran9f22ceb2020-05-27 09:46:54179 if (scope.type() !== Protocol.Debugger.ScopeType.Local || callFrame.script.isWasm()) {
Jack Lynch2938cf32019-11-05 19:24:12180 return [];
181 }
182
183 const extraProperties = [];
184 if (thisObject) {
Tim van der Lippefbbf9812020-02-13 14:43:46185 extraProperties.push(new SDK.RemoteObject.RemoteObjectProperty('this', thisObject));
Jack Lynch2938cf32019-11-05 19:24:12186 }
187 if (isFirstScope) {
188 const exception = details.exception();
189 if (exception) {
Tim van der Lippefbbf9812020-02-13 14:43:46190 extraProperties.push(new SDK.RemoteObject.RemoteObjectProperty(
191 Common.UIString.UIString('Exception'), exception, undefined, undefined, undefined, undefined, undefined,
Jack Lynch2938cf32019-11-05 19:24:12192 /* synthetic */ true));
193 }
194 const returnValue = callFrame.returnValue();
195 if (returnValue) {
Tim van der Lippefbbf9812020-02-13 14:43:46196 extraProperties.push(new SDK.RemoteObject.RemoteObjectProperty(
197 Common.UIString.UIString('Return value'), returnValue, undefined, undefined, undefined, undefined,
198 undefined,
Jack Lynch2938cf32019-11-05 19:24:12199 /* synthetic */ true, callFrame.setReturnValue.bind(callFrame)));
200 }
201 }
202
203 return extraProperties;
204 }
205
Blink Reformat4c46d092018-04-07 15:32:37206 _sidebarPaneUpdatedForTest() {
207 }
Tim van der Lippe8987f8f2020-01-03 15:03:16208}
Blink Reformat4c46d092018-04-07 15:32:37209
Paul Lewis39944952020-01-22 15:45:18210export const pathSymbol = Symbol('path');