{"size": 8542, "ext": "js", "max_stars_repo_path": "public/front_end/bindings/DebuggerWorkspaceBinding.js", "max_stars_repo_name": "xueduany/chii", "max_stars_repo_stars_event_min_datetime": "2021-03-04T09:24:45.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-04T09:24:45.000Z", "max_issues_repo_path": "public/front_end/bindings/DebuggerWorkspaceBinding.js", "max_issues_repo_name": "xueduany/chii", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "public/front_end/bindings/DebuggerWorkspaceBinding.js", "max_forks_repo_name": "xueduany/chii", "max_forks_repo_forks_event_min_datetime": "2021-03-04T09:25:23.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-07T03:48:28.000Z"}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": 2, "avg_line_length": 8542.0, "max_line_length": 8542, "alphanum_fraction": 0.8331772419}
import*as Common from"../common/common.js";import*as SDK from"../sdk/sdk.js";import*as Workspace from"../workspace/workspace.js";import{BlackboxManager}from"./BlackboxManager.js";import{CompilerScriptMapping}from"./CompilerScriptMapping.js";import{DebuggerLanguagePluginManager}from"./DebuggerLanguagePlugins.js";import{DefaultScriptMapping}from"./DefaultScriptMapping.js";import{CXXDWARFLanguagePlugin}from"./language_plugins/CXXDWARFLanguagePlugin.js";import{LiveLocation,LiveLocationPool,LiveLocationWithPool}from"./LiveLocation.js";import{ResourceMapping}from"./ResourceMapping.js";import{ResourceScriptFile,ResourceScriptMapping}from"./ResourceScriptMapping.js";let debuggerWorkspaceBindingInstance;export class DebuggerWorkspaceBinding{constructor(e,o){this._workspace=o,this._sourceMappings=[],this._debuggerModelToData=new Map,e.addModelListener(SDK.DebuggerModel.DebuggerModel,SDK.DebuggerModel.Events.GlobalObjectCleared,this._globalObjectCleared,this),e.addModelListener(SDK.DebuggerModel.DebuggerModel,SDK.DebuggerModel.Events.DebuggerResumed,this._debuggerResumed,this),e.observeModels(SDK.DebuggerModel.DebuggerModel,this),this._liveLocationPromises=new Set}static instance(e={forceNew:null,targetManager:null,workspace:null}){const{forceNew:o,targetManager:t,workspace:a}=e;if(!debuggerWorkspaceBindingInstance||o){if(!t||!a)throw new Error("Unable to create settings: targetManager and workspace must be provided: "+(new Error).stack);debuggerWorkspaceBindingInstance=new DebuggerWorkspaceBinding(t,a)}return debuggerWorkspaceBindingInstance}addSourceMapping(e){this._sourceMappings.push(e)}modelAdded(e){this._debuggerModelToData.set(e,new ModelData(e,this))}modelRemoved(e){this._debuggerModelToData.get(e)._dispose(),this._debuggerModelToData.delete(e)}getLanguagePluginManager(e){const o=this._debuggerModelToData.get(e);return o?o.pluginManager:null}pendingLiveLocationChangesPromise(){return Promise.all(this._liveLocationPromises)}_recordLiveLocationChange(e){e.then(()=>{this._liveLocationPromises.delete(e)}),this._liveLocationPromises.add(e)}async updateLocations(e){const o=this._debuggerModelToData.get(e.debuggerModel);if(o){const t=o._updateLocations(e);this._recordLiveLocationChange(t),await t}}createLiveLocation(e,o,t){const a=this._debuggerModelToData.get(e.script().debuggerModel)._createLiveLocation(e,o,t);return this._recordLiveLocationChange(a),a}async createStackTraceTopFrameLiveLocation(e,o,t){console.assert(e.length);const a=StackTraceTopFrameLocation.createStackTraceTopFrameLocation(e,this,o,t);return this._recordLiveLocationChange(a),a}async createCallFrameLiveLocation(e,o,t){if(!e.script())return null;const a=e.debuggerModel,i=this.createLiveLocation(e,o,t);this._recordLiveLocationChange(i);const n=await i;return this._registerCallFrameLiveLocation(a,n),n}async rawLocationToUILocation(e){for(const o of this._sourceMappings){const t=o.rawLocationToUILocation(e);if(t)return t}const o=this._debuggerModelToData.get(e.debuggerModel);return o?o._rawLocationToUILocation(e):null}uiSourceCodeForSourceMapSourceURL(e,o,t){const a=this._debuggerModelToData.get(e);return a?a._compilerMapping.uiSourceCodeForURL(o,t):null}async uiLocationToRawLocations(e,o,t){for(const a of this._sourceMappings){const i=a.uiLocationToRawLocations(e,o,t);if(i.length)return i}const a=[];for(const i of this._debuggerModelToData.values())a.push(i._uiLocationToRawLocations(e,o,t));return(await Promise.all(a)).flat()}uiLocationToRawLocationsForUnformattedJavaScript(e,o,t){console.assert(e.contentType().isScript());const a=[];for(const i of this._debuggerModelToData.values())a.push(...i._uiLocationToRawLocationsExcludeAsync(e,o,t));return a}async normalizeUILocation(e){const o=await this.uiLocationToRawLocations(e.uiSourceCode,e.lineNumber,e.columnNumber);for(const e of o){const o=await this.rawLocationToUILocation(e);if(o)return o}return e}scriptFile(e,o){const t=this._debuggerModelToData.get(o);return t?t._resourceMapping.scriptFile(e):null}sourceMapForScript(e){const o=this._debuggerModelToData.get(e.debuggerModel);return o?o._compilerMapping.sourceMapForScript(e):null}_globalObjectCleared(e){const o=e.data;this._reset(o)}_reset(e){const o=this._debuggerModelToData.get(e);for(const e of o.callFrameLocations.values())this._removeLiveLocation(e);o.callFrameLocations.clear()}_resetForTest(e){const o=e.model(SDK.DebuggerModel.DebuggerModel);this._debuggerModelToData.get(o)._resourceMapping.resetForTest()}_registerCallFrameLiveLocation(e,o){this._debuggerModelToData.get(e).callFrameLocations.add(o)}_removeLiveLocation(e){const o=this._debuggerModelToData.get(e._script.debuggerModel);o&&o._disposeLocation(e)}_debuggerResumed(e){const o=e.data;this._reset(o)}}class ModelData{constructor(e,o){this._debuggerModel=e,this._debuggerWorkspaceBinding=o,this.callFrameLocations=new Set;const t=o._workspace;Root.Runtime.experiments.isEnabled("wasmDWARFDebugging")&&(this._pluginManager=new DebuggerLanguagePluginManager(e,t,o),this._pluginManager.addPlugin(new CXXDWARFLanguagePlugin)),this._defaultMapping=new DefaultScriptMapping(e,t,o),this._resourceMapping=new ResourceScriptMapping(e,t,o),this._compilerMapping=new CompilerScriptMapping(e,t,o),this._locations=new Platform.Multimap,e.setBeforePausedCallback(this._beforePaused.bind(this))}get pluginManager(){return this._pluginManager||null}async _createLiveLocation(e,o,t){const a=e.script();console.assert(a);const i=new Location(a,e,this._debuggerWorkspaceBinding,o,t);return this._locations.set(a,i),await i.update(),i}_disposeLocation(e){this._locations.delete(e._script,e)}async _updateLocations(e){const o=[];for(const t of this._locations.get(e))o.push(t.update());return Promise.all(o)}async _rawLocationToUILocation(e){let o=null;return Root.Runtime.experiments.isEnabled("wasmDWARFDebugging")&&(o=await this._pluginManager.rawLocationToUILocation(e)),o=o||this._compilerMapping.rawLocationToUILocation(e),o=o||this._resourceMapping.rawLocationToUILocation(e),o=o||ResourceMapping.instance().jsLocationToUILocation(e),o=o||this._defaultMapping.rawLocationToUILocation(e),o}async _uiLocationToRawLocations(e,o,t){let a=null;return Root.Runtime.experiments.isEnabled("wasmDWARFDebugging")&&(a=await this._pluginManager.uiLocationToRawLocations(e,o,t)),a=a||this._uiLocationToRawLocationsExcludeAsync(e,o,t),a}_uiLocationToRawLocationsExcludeAsync(e,o,t){let a=this._compilerMapping.uiLocationToRawLocations(e,o,t);return a=a.length?a:this._resourceMapping.uiLocationToRawLocations(e,o,t),a=a.length?a:ResourceMapping.instance().uiLocationToJSLocations(e,o,t),a=a.length?a:this._defaultMapping.uiLocationToRawLocations(e,o,t),a}_beforePaused(e){const o=e.callFrames[0];return o.script.sourceMapURL!==SDK.SourceMap.WasmSourceMap.FAKE_URL&&!Root.Runtime.experiments.isEnabled("emptySourceMapAutoStepping")||!!this._compilerMapping.mapsToSourceCode(o.location())}_dispose(){this._debuggerModel.setBeforePausedCallback(null),this._compilerMapping.dispose(),this._resourceMapping.dispose(),this._defaultMapping.dispose()}}class Location extends LiveLocationWithPool{constructor(e,o,t,a,i){super(a,i),this._script=e,this._rawLocation=o,this._binding=t}async uiLocation(){const e=this._rawLocation;return this._binding.rawLocationToUILocation(e)}dispose(){super.dispose(),this._binding._removeLiveLocation(this)}async isBlackboxed(){const e=await this.uiLocation();return!!e&&BlackboxManager.instance().isBlackboxedUISourceCode(e.uiSourceCode)}}class StackTraceTopFrameLocation extends LiveLocationWithPool{constructor(e,o){super(e,o),this._updateScheduled=!0,this._current=null,this._locations=null}static async createStackTraceTopFrameLocation(e,o,t,a){const i=new StackTraceTopFrameLocation(t,a),n=e.map(e=>o.createLiveLocation(e,i._scheduleUpdate.bind(i),a));return i._locations=await Promise.all(n),await i._updateLocation(),i}async uiLocation(){return this._current?this._current.uiLocation():null}async isBlackboxed(){return!!this._current&&this._current.isBlackboxed()}dispose(){if(super.dispose(),this._locations)for(const e of this._locations)e.dispose();this._locations=null,this._current=null}_scheduleUpdate(){this._updateScheduled||(this._updateScheduled=!0,setImmediate(this._updateLocation.bind(this)))}async _updateLocation(){if(this._updateScheduled=!1,this._locations&&0!==this._locations.length){this._current=this._locations[0];for(const e of this._locations)if(!await e.isBlackboxed()){this._current=e;break}this.update()}}}export class DebuggerSourceMapping{rawLocationToUILocation(e){}uiLocationToRawLocations(e,o,t){}}