DebuggerWorkspaceBinding.js 8.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. export default class DebuggerWorkspaceBinding{constructor(targetManager,workspace){this._workspace=workspace;this._sourceMappings=[];this._debuggerModelToData=new Map();targetManager.addModelListener(SDK.DebuggerModel,SDK.DebuggerModel.Events.GlobalObjectCleared,this._globalObjectCleared,this);targetManager.addModelListener(SDK.DebuggerModel,SDK.DebuggerModel.Events.DebuggerResumed,this._debuggerResumed,this);targetManager.observeModels(SDK.DebuggerModel,this);}
  2. addSourceMapping(sourceMapping){this._sourceMappings.push(sourceMapping);}
  3. modelAdded(debuggerModel){this._debuggerModelToData.set(debuggerModel,new ModelData(debuggerModel,this));}
  4. modelRemoved(debuggerModel){const modelData=this._debuggerModelToData.get(debuggerModel);modelData._dispose();this._debuggerModelToData.remove(debuggerModel);}
  5. updateLocations(script){const modelData=this._debuggerModelToData.get(script.debuggerModel);if(modelData){modelData._updateLocations(script);}}
  6. createLiveLocation(rawLocation,updateDelegate,locationPool){const modelData=this._debuggerModelToData.get(rawLocation.script().debuggerModel);return modelData._createLiveLocation(rawLocation,updateDelegate,locationPool);}
  7. createStackTraceTopFrameLiveLocation(rawLocations,updateDelegate,locationPool){console.assert(rawLocations.length);const location=new StackTraceTopFrameLocation(rawLocations,this,updateDelegate,locationPool);location.update();return location;}
  8. createCallFrameLiveLocation(location,updateDelegate,locationPool){const script=location.script();if(!script){return null;}
  9. const debuggerModel=location.debuggerModel;const liveLocation=this.createLiveLocation(location,updateDelegate,locationPool);this._registerCallFrameLiveLocation(debuggerModel,liveLocation);return liveLocation;}
  10. rawLocationToUILocation(rawLocation){for(let i=0;i<this._sourceMappings.length;++i){const uiLocation=this._sourceMappings[i].rawLocationToUILocation(rawLocation);if(uiLocation){return uiLocation;}}
  11. const modelData=this._debuggerModelToData.get(rawLocation.debuggerModel);return modelData._rawLocationToUILocation(rawLocation);}
  12. uiSourceCodeForSourceMapSourceURL(debuggerModel,url,isContentScript){const modelData=this._debuggerModelToData.get(debuggerModel);if(!modelData){return null;}
  13. return modelData._compilerMapping.uiSourceCodeForURL(url,isContentScript);}
  14. uiLocationToRawLocations(uiSourceCode,lineNumber,columnNumber){let locations=[];for(let i=0;i<this._sourceMappings.length&&!locations.length;++i){locations=this._sourceMappings[i].uiLocationToRawLocations(uiSourceCode,lineNumber,columnNumber);}
  15. if(locations.length){return locations;}
  16. for(const modelData of this._debuggerModelToData.values()){locations.push(...modelData._uiLocationToRawLocations(uiSourceCode,lineNumber,columnNumber));}
  17. return locations;}
  18. normalizeUILocation(uiLocation){const rawLocations=this.uiLocationToRawLocations(uiLocation.uiSourceCode,uiLocation.lineNumber,uiLocation.columnNumber);for(const location of rawLocations){const uiLocationCandidate=this.rawLocationToUILocation(location);if(uiLocationCandidate){return uiLocationCandidate;}}
  19. return uiLocation;}
  20. scriptFile(uiSourceCode,debuggerModel){const modelData=this._debuggerModelToData.get(debuggerModel);return modelData?modelData._resourceMapping.scriptFile(uiSourceCode):null;}
  21. sourceMapForScript(script){const modelData=this._debuggerModelToData.get(script.debuggerModel);if(!modelData){return null;}
  22. return modelData._compilerMapping.sourceMapForScript(script);}
  23. _globalObjectCleared(event){const debuggerModel=(event.data);this._reset(debuggerModel);}
  24. _reset(debuggerModel){const modelData=this._debuggerModelToData.get(debuggerModel);modelData.callFrameLocations.valuesArray().forEach(location=>this._removeLiveLocation(location));modelData.callFrameLocations.clear();}
  25. _resetForTest(target){const debuggerModel=(target.model(SDK.DebuggerModel));const modelData=this._debuggerModelToData.get(debuggerModel);modelData._resourceMapping.resetForTest();}
  26. _registerCallFrameLiveLocation(debuggerModel,location){const locations=this._debuggerModelToData.get(debuggerModel).callFrameLocations;locations.add(location);}
  27. _removeLiveLocation(location){const modelData=this._debuggerModelToData.get(location._script.debuggerModel);if(modelData){modelData._disposeLocation(location);}}
  28. _debuggerResumed(event){const debuggerModel=(event.data);this._reset(debuggerModel);}}
  29. class ModelData{constructor(debuggerModel,debuggerWorkspaceBinding){this._debuggerModel=debuggerModel;this._debuggerWorkspaceBinding=debuggerWorkspaceBinding;this.callFrameLocations=new Set();const workspace=debuggerWorkspaceBinding._workspace;this._defaultMapping=new Bindings.DefaultScriptMapping(debuggerModel,workspace,debuggerWorkspaceBinding);this._resourceMapping=new Bindings.ResourceScriptMapping(debuggerModel,workspace,debuggerWorkspaceBinding);this._compilerMapping=new Bindings.CompilerScriptMapping(debuggerModel,workspace,debuggerWorkspaceBinding);this._locations=new Platform.Multimap();debuggerModel.setBeforePausedCallback(this._beforePaused.bind(this));}
  30. _createLiveLocation(rawLocation,updateDelegate,locationPool){const script=(rawLocation.script());console.assert(script);const location=new Location(script,rawLocation,this._debuggerWorkspaceBinding,updateDelegate,locationPool);this._locations.set(script,location);location.update();return location;}
  31. _disposeLocation(location){this._locations.delete(location._script,location);}
  32. _updateLocations(script){for(const location of this._locations.get(script)){location.update();}}
  33. _rawLocationToUILocation(rawLocation){let uiLocation=null;uiLocation=uiLocation||this._compilerMapping.rawLocationToUILocation(rawLocation);uiLocation=uiLocation||this._resourceMapping.rawLocationToUILocation(rawLocation);uiLocation=uiLocation||Bindings.resourceMapping.jsLocationToUILocation(rawLocation);uiLocation=uiLocation||this._defaultMapping.rawLocationToUILocation(rawLocation);return(uiLocation);}
  34. _uiLocationToRawLocations(uiSourceCode,lineNumber,columnNumber){let locations=this._compilerMapping.uiLocationToRawLocations(uiSourceCode,lineNumber,columnNumber);locations=locations.length?locations:this._resourceMapping.uiLocationToRawLocations(uiSourceCode,lineNumber,columnNumber);locations=locations.length?locations:Bindings.resourceMapping.uiLocationToJSLocations(uiSourceCode,lineNumber,columnNumber);locations=locations.length?locations:this._defaultMapping.uiLocationToRawLocations(uiSourceCode,lineNumber,columnNumber);return locations;}
  35. _beforePaused(debuggerPausedDetails){const callFrame=debuggerPausedDetails.callFrames[0];if(callFrame.script.sourceMapURL!==SDK.WasmSourceMap.FAKE_URL&&!Root.Runtime.experiments.isEnabled('emptySourceMapAutoStepping')){return true;}
  36. return!!this._compilerMapping.mapsToSourceCode(callFrame.location());}
  37. _dispose(){this._debuggerModel.setBeforePausedCallback(null);this._compilerMapping.dispose();this._resourceMapping.dispose();this._defaultMapping.dispose();}}
  38. class Location extends Bindings.LiveLocationWithPool{constructor(script,rawLocation,binding,updateDelegate,locationPool){super(updateDelegate,locationPool);this._script=script;this._rawLocation=rawLocation;this._binding=binding;}
  39. uiLocation(){const debuggerModelLocation=this._rawLocation;return this._binding.rawLocationToUILocation(debuggerModelLocation);}
  40. dispose(){super.dispose();this._binding._removeLiveLocation(this);}
  41. isBlackboxed(){const uiLocation=this.uiLocation();return uiLocation?Bindings.blackboxManager.isBlackboxedUISourceCode(uiLocation.uiSourceCode):false;}}
  42. class StackTraceTopFrameLocation extends Bindings.LiveLocationWithPool{constructor(rawLocations,binding,updateDelegate,locationPool){super(updateDelegate,locationPool);this._updateScheduled=true;this._current=null;this._locations=rawLocations.map(location=>binding.createLiveLocation(location,this._scheduleUpdate.bind(this),locationPool));this._updateLocation();}
  43. uiLocation(){return this._current.uiLocation();}
  44. isBlackboxed(){return this._current.isBlackboxed();}
  45. dispose(){super.dispose();for(const location of this._locations){location.dispose();}
  46. this._locations=null;this._current=null;}
  47. _scheduleUpdate(){if(this._updateScheduled){return;}
  48. this._updateScheduled=true;setImmediate(this._updateLocation.bind(this));}
  49. _updateLocation(){this._updateScheduled=false;if(!this._locations){return;}
  50. this._current=this._locations.find(location=>!location.isBlackboxed())||this._locations[0];this.update();}}
  51. export class DebuggerSourceMapping{rawLocationToUILocation(rawLocation){}
  52. uiLocationToRawLocations(uiSourceCode,lineNumber,columnNumber){}}
  53. self.Bindings=self.Bindings||{};Bindings=Bindings||{};Bindings.DebuggerWorkspaceBinding=DebuggerWorkspaceBinding;Bindings.DebuggerSourceMapping=DebuggerSourceMapping;Bindings.debuggerWorkspaceBinding;