@yuebai008/cli
Version:
Command line interface for rapid qg-minigame development
1 lines • 6.44 kB
JavaScript
import*as Host from"../../core/host/host.js";import*as i18n from"../../core/i18n/i18n.js";import*as SDK from"../../core/sdk/sdk.js";import*as SourceMapScopes from"../../models/source_map_scopes/source_map_scopes.js";import*as LinearMemoryInspector from"../../ui/components/linear_memory_inspector/linear_memory_inspector.js";import*as ObjectUI from"../../ui/legacy/components/object_ui/object_ui.js";import*as Components from"../../ui/legacy/components/utils/utils.js";import*as UI from"../../ui/legacy/legacy.js";import scopeChainSidebarPaneStyles from"./scopeChainSidebarPane.css.js";const UIStrings={loading:"Loading...",notPaused:"Not paused",noVariables:"No variables",closureS:"Closure ({PH1})",closure:"Closure",exception:"Exception",returnValue:"Return value",revealInMemoryInspectorPanel:"Reveal in Memory Inspector panel"},str_=i18n.i18n.registerUIStrings("panels/sources/ScopeChainSidebarPane.ts",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_);let scopeChainSidebarPaneInstance,openLinearMemoryInspectorInstance;export class ScopeChainSidebarPane extends UI.Widget.VBox{treeOutline;expandController;linkifier;infoElement;#e=null;constructor(){super(!0),this.treeOutline=new ObjectUI.ObjectPropertiesSection.ObjectPropertiesSectionsTreeOutline,this.treeOutline.setShowSelectionOnKeyboardFocus(!0),this.expandController=new ObjectUI.ObjectPropertiesSection.ObjectPropertiesSectionsTreeExpandController(this.treeOutline),this.linkifier=new Components.Linkifier.Linkifier,this.infoElement=document.createElement("div"),this.infoElement.className="gray-info-message",this.infoElement.tabIndex=-1,SDK.TargetManager.TargetManager.instance().addModelListener(SDK.DebuggerModel.DebuggerModel,SDK.DebuggerModel.Events.DebugInfoAttached,this.debugInfoAttached,this),this.update()}static instance(){return scopeChainSidebarPaneInstance||(scopeChainSidebarPaneInstance=new ScopeChainSidebarPane),scopeChainSidebarPaneInstance}flavorChanged(e){this.update()}focus(){this.hasFocus()||UI.Context.Context.instance().flavor(SDK.DebuggerModel.DebuggerPausedDetails)&&this.treeOutline.forceSelect()}sourceMapAttached(e){e.data.client===this.#e&&this.update()}setScopeSourceMapSubscription(e){const t=this.#e;this.#e=e?.script??null,t?.debuggerModel!==this.#e?.debuggerModel&&(t&&t.debuggerModel.sourceMapManager().removeEventListener(SDK.SourceMapManager.Events.SourceMapAttached,this.sourceMapAttached,this),this.#e&&this.#e.debuggerModel.sourceMapManager().addEventListener(SDK.SourceMapManager.Events.SourceMapAttached,this.sourceMapAttached,this))}debugInfoAttached(e){e.data===this.#e&&this.update()}async update(){this.infoElement.textContent=i18nString(UIStrings.loading),this.contentElement.removeChildren(),this.contentElement.appendChild(this.infoElement),this.linkifier.reset();const e=UI.Context.Context.instance().flavor(SDK.DebuggerModel.CallFrame);this.setScopeSourceMapSubscription(e);const[t,n]=await Promise.all([SourceMapScopes.NamesResolver.resolveThisObject(e),SourceMapScopes.NamesResolver.resolveScopeChain(e)]);if(e===UI.Context.Context.instance().flavor(SDK.DebuggerModel.CallFrame)){const o=UI.Context.Context.instance().flavor(SDK.DebuggerModel.DebuggerPausedDetails);if(this.treeOutline.removeChildren(),!o||!e||!n)return void(this.infoElement.textContent=i18nString(UIStrings.notPaused));this.contentElement.removeChildren(),this.contentElement.appendChild(this.treeOutline.element);let r=!1;for(let i=0;i<n.length;++i){const s=n[i],a=this.extraPropertiesForScope(s,o,e,t,0===i);"local"===s.type()&&(r=!0);const c=this.createScopeSectionTreeElement(s,a);"global"===s.type()?c.collapse():r&&"local"!==s.type()||c.expand(),this.treeOutline.appendChild(c),0===i&&c.select(!0)}this.sidebarPaneUpdatedForTest()}}createScopeSectionTreeElement(e,t){let n=null;e.type(),n=i18nString(UIStrings.noVariables);let o=e.typeName();if("closure"===e.type()){const t=e.name();o=t?i18nString(UIStrings.closureS,{PH1:UI.UIUtils.beautifyFunctionName(t)}):i18nString(UIStrings.closure)}let r=e.description();o&&o!==r||(r=null);const i=e.icon(),s=document.createElement("div");if(s.classList.add("scope-chain-sidebar-pane-section-header"),s.classList.add("tree-element-title"),i){const e=document.createElement("img");e.classList.add("scope-chain-sidebar-pane-section-icon"),e.src=i,s.appendChild(e)}s.createChild("div","scope-chain-sidebar-pane-section-subtitle").textContent=r,s.createChild("div","scope-chain-sidebar-pane-section-title").textContent=o;const a=new ObjectUI.ObjectPropertiesSection.RootElement(SourceMapScopes.NamesResolver.resolveScopeInObject(e),this.linkifier,n,0,t);return a.title=s,a.listItemElement.classList.add("scope-chain-sidebar-pane-section"),a.listItemElement.setAttribute("aria-label",o),this.expandController.watchSection(o+(r?":"+r:""),a),a}extraPropertiesForScope(e,t,n,o,r){if("local"!==e.type()||n.script.isWasm())return[];const i=[];if(o&&i.push(new SDK.RemoteObject.RemoteObjectProperty("this",o,void 0,void 0,void 0,void 0,void 0,!0)),r){const e=t.exception();e&&i.push(new SDK.RemoteObject.RemoteObjectProperty(i18nString(UIStrings.exception),e,void 0,void 0,void 0,void 0,void 0,!0));const o=n.returnValue();o&&i.push(new SDK.RemoteObject.RemoteObjectProperty(i18nString(UIStrings.returnValue),o,void 0,void 0,void 0,void 0,void 0,!0,n.setReturnValue.bind(n)))}return i}sidebarPaneUpdatedForTest(){}wasShown(){super.wasShown(),this.treeOutline.registerCSSFiles([scopeChainSidebarPaneStyles]),this.registerCSSFiles([scopeChainSidebarPaneStyles])}}export class OpenLinearMemoryInspector extends UI.Widget.VBox{static instance(e={forceNew:null}){const{forceNew:t}=e;return openLinearMemoryInspectorInstance&&!t||(openLinearMemoryInspectorInstance=new OpenLinearMemoryInspector),openLinearMemoryInspectorInstance}appendApplicableItems(e,t,n){if(n instanceof ObjectUI.ObjectPropertiesSection.ObjectPropertyTreeElement&&n.property&&n.property.value&&LinearMemoryInspector.LinearMemoryInspectorController.isMemoryObjectProperty(n.property.value)){const e=n.path();t.debugSection().appendItem(i18nString(UIStrings.revealInMemoryInspectorPanel),this.openMemoryInspector.bind(this,e,n.property.value))}}async openMemoryInspector(e,t){const n=LinearMemoryInspector.LinearMemoryInspectorController.LinearMemoryInspectorController.instance();Host.userMetrics.linearMemoryInspectorRevealedFrom(Host.UserMetrics.LinearMemoryInspectorRevealedFrom.ContextMenu),n.openInspectorView(t,void 0,e)}}