DebuggerModel.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. export default class DebuggerModel extends SDK.SDKModel{constructor(target){super(target);target.registerDebuggerDispatcher(new DebuggerDispatcher(this));this._agent=target.debuggerAgent();this._runtimeModel=(target.model(SDK.RuntimeModel));this._sourceMapManager=new SDK.SourceMapManager(target);this._sourceMapIdToScript=new Map();this._debuggerPausedDetails=null;this._scripts=new Map();this._scriptsBySourceURL=new Map();this._discardableScripts=[];this._breakpointResolvedEventTarget=new Common.Object();this._autoStepOver=false;this._isPausing=false;Common.moduleSetting('pauseOnExceptionEnabled').addChangeListener(this._pauseOnExceptionStateChanged,this);Common.moduleSetting('pauseOnCaughtException').addChangeListener(this._pauseOnExceptionStateChanged,this);Common.moduleSetting('disableAsyncStackTraces').addChangeListener(this._asyncStackTracesStateChanged,this);Common.moduleSetting('breakpointsActive').addChangeListener(this._breakpointsActiveChanged,this);if(!target.suspended()){this._enableDebugger();}
  2. this._stringMap=new Map();this._sourceMapManager.setEnabled(Common.moduleSetting('jsSourceMapsEnabled').get());Common.moduleSetting('jsSourceMapsEnabled').addChangeListener(event=>this._sourceMapManager.setEnabled((event.data)));}
  3. static _sourceMapId(executionContextId,sourceURL,sourceMapURL){if(!sourceMapURL){return null;}
  4. return executionContextId+':'+sourceURL+':'+sourceMapURL;}
  5. sourceMapManager(){return this._sourceMapManager;}
  6. runtimeModel(){return this._runtimeModel;}
  7. debuggerEnabled(){return!!this._debuggerEnabled;}
  8. _enableDebugger(){if(this._debuggerEnabled){return Promise.resolve();}
  9. this._debuggerEnabled=true;const isRemoteFrontend=Root.Runtime.queryParam('remoteFrontend')||Root.Runtime.queryParam('ws');const maxScriptsCacheSize=isRemoteFrontend?10e6:100e6;const enablePromise=this._agent.enable(maxScriptsCacheSize);enablePromise.then(this._registerDebugger.bind(this));this._pauseOnExceptionStateChanged();this._asyncStackTracesStateChanged();if(!Common.moduleSetting('breakpointsActive').get()){this._breakpointsActiveChanged();}
  10. if(SDK.DebuggerModel._scheduledPauseOnAsyncCall){this._pauseOnAsyncCall(SDK.DebuggerModel._scheduledPauseOnAsyncCall);}
  11. this.dispatchEventToListeners(Events.DebuggerWasEnabled,this);return enablePromise;}
  12. _registerDebugger(debuggerId){if(!debuggerId){return;}
  13. SDK.DebuggerModel._debuggerIdToModel.set(debuggerId,this);this._debuggerId=debuggerId;this.dispatchEventToListeners(Events.DebuggerIsReadyToPause,this);}
  14. isReadyToPause(){return!!this._debuggerId;}
  15. static modelForDebuggerId(debuggerId){return SDK.DebuggerModel._debuggerIdToModel.get(debuggerId)||null;}
  16. _disableDebugger(){if(!this._debuggerEnabled){return Promise.resolve();}
  17. this._debuggerEnabled=false;const disablePromise=this._agent.disable();this._isPausing=false;this._asyncStackTracesStateChanged();this.globalObjectCleared();this.dispatchEventToListeners(Events.DebuggerWasDisabled);SDK.DebuggerModel._debuggerIdToModel.delete(this._debuggerId);return disablePromise;}
  18. _skipAllPauses(skip){if(this._skipAllPausesTimeout){clearTimeout(this._skipAllPausesTimeout);delete this._skipAllPausesTimeout;}
  19. this._agent.setSkipAllPauses(skip);}
  20. skipAllPausesUntilReloadOrTimeout(timeout){if(this._skipAllPausesTimeout){clearTimeout(this._skipAllPausesTimeout);}
  21. this._agent.setSkipAllPauses(true);this._skipAllPausesTimeout=setTimeout(this._skipAllPauses.bind(this,false),timeout);}
  22. _pauseOnExceptionStateChanged(){let state;if(!Common.moduleSetting('pauseOnExceptionEnabled').get()){state=PauseOnExceptionsState.DontPauseOnExceptions;}else if(Common.moduleSetting('pauseOnCaughtException').get()){state=PauseOnExceptionsState.PauseOnAllExceptions;}else{state=PauseOnExceptionsState.PauseOnUncaughtExceptions;}
  23. this._agent.setPauseOnExceptions(state);}
  24. _asyncStackTracesStateChanged(){const maxAsyncStackChainDepth=32;const enabled=!Common.moduleSetting('disableAsyncStackTraces').get()&&this._debuggerEnabled;this._agent.setAsyncCallStackDepth(enabled?maxAsyncStackChainDepth:0);}
  25. _breakpointsActiveChanged(){this._agent.setBreakpointsActive(Common.moduleSetting('breakpointsActive').get());}
  26. stepInto(){this._agent.stepInto();}
  27. stepOver(){this._autoStepOver=true;this._agent.stepOver();}
  28. stepOut(){this._agent.stepOut();}
  29. scheduleStepIntoAsync(){this._agent.invoke_stepInto({breakOnAsyncCall:true});}
  30. resume(){this._agent.resume();this._isPausing=false;}
  31. pause(){this._isPausing=true;this._skipAllPauses(false);this._agent.pause();}
  32. _pauseOnAsyncCall(parentStackTraceId){return this._agent.invoke_pauseOnAsyncCall({parentStackTraceId:parentStackTraceId});}
  33. async setBreakpointByURL(url,lineNumber,columnNumber,condition){let urlRegex;if(this.target().type()===SDK.Target.Type.Node){const platformPath=Common.ParsedURL.urlToPlatformPath(url,Host.isWin());urlRegex=`${platformPath.escapeForRegExp()}|${url.escapeForRegExp()}`;}
  34. let minColumnNumber=0;const scripts=this._scriptsBySourceURL.get(url)||[];for(let i=0,l=scripts.length;i<l;++i){const script=scripts[i];if(lineNumber===script.lineOffset){minColumnNumber=minColumnNumber?Math.min(minColumnNumber,script.columnOffset):script.columnOffset;}}
  35. columnNumber=Math.max(columnNumber,minColumnNumber);const response=await this._agent.invoke_setBreakpointByUrl({lineNumber:lineNumber,url:urlRegex?undefined:url,urlRegex:urlRegex,columnNumber:columnNumber,condition:condition});if(response[Protocol.Error]){return{locations:[],breakpointId:null};}
  36. let locations=[];if(response.locations){locations=response.locations.map(payload=>Location.fromPayload(this,payload));}
  37. return{locations:locations,breakpointId:response.breakpointId};}
  38. async setBreakpointInAnonymousScript(scriptId,scriptHash,lineNumber,columnNumber,condition){const response=await this._agent.invoke_setBreakpointByUrl({lineNumber:lineNumber,scriptHash:scriptHash,columnNumber:columnNumber,condition:condition});const error=response[Protocol.Error];if(error){if(error!=='Either url or urlRegex must be specified.'){return{locations:[],breakpointId:null};}
  39. return this._setBreakpointBySourceId(scriptId,lineNumber,columnNumber,condition);}
  40. let locations=[];if(response.locations){locations=response.locations.map(payload=>Location.fromPayload(this,payload));}
  41. return{locations:locations,breakpointId:response.breakpointId};}
  42. async _setBreakpointBySourceId(scriptId,lineNumber,columnNumber,condition){const response=await this._agent.invoke_setBreakpoint({location:{scriptId:scriptId,lineNumber:lineNumber,columnNumber:columnNumber},condition:condition});if(response[Protocol.Error]){return{breakpointId:null,locations:[]};}
  43. let actualLocation=[];if(response.actualLocation){actualLocation=[Location.fromPayload(this,response.actualLocation)];}
  44. return{locations:actualLocation,breakpointId:response.breakpointId};}
  45. async removeBreakpoint(breakpointId){const response=await this._agent.invoke_removeBreakpoint({breakpointId});if(response[Protocol.Error]){console.error('Failed to remove breakpoint: '+response[Protocol.Error]);}}
  46. async getPossibleBreakpoints(startLocation,endLocation,restrictToFunction){const response=await this._agent.invoke_getPossibleBreakpoints({start:startLocation.payload(),end:endLocation?endLocation.payload():undefined,restrictToFunction:restrictToFunction});if(response[Protocol.Error]||!response.locations){return[];}
  47. return response.locations.map(location=>BreakLocation.fromPayload(this,location));}
  48. async fetchAsyncStackTrace(stackId){const response=await this._agent.invoke_getStackTrace({stackTraceId:stackId});return response[Protocol.Error]?null:response.stackTrace;}
  49. _breakpointResolved(breakpointId,location){this._breakpointResolvedEventTarget.dispatchEventToListeners(breakpointId,Location.fromPayload(this,location));}
  50. globalObjectCleared(){this._setDebuggerPausedDetails(null);this._reset();this.dispatchEventToListeners(Events.GlobalObjectCleared,this);}
  51. _reset(){for(const scriptWithSourceMap of this._sourceMapIdToScript.values()){this._sourceMapManager.detachSourceMap(scriptWithSourceMap);}
  52. this._sourceMapIdToScript.clear();this._scripts.clear();this._scriptsBySourceURL.clear();this._stringMap.clear();this._discardableScripts=[];this._autoStepOver=false;}
  53. scripts(){return Array.from(this._scripts.values());}
  54. scriptForId(scriptId){return this._scripts.get(scriptId)||null;}
  55. scriptsForSourceURL(sourceURL){if(!sourceURL){return[];}
  56. return this._scriptsBySourceURL.get(sourceURL)||[];}
  57. scriptsForExecutionContext(executionContext){const result=[];for(const script of this._scripts.values()){if(script.executionContextId===executionContext.id){result.push(script);}}
  58. return result;}
  59. setScriptSource(scriptId,newSource,callback){this._scripts.get(scriptId).editSource(newSource,this._didEditScriptSource.bind(this,scriptId,newSource,callback));}
  60. _didEditScriptSource(scriptId,newSource,callback,error,exceptionDetails,callFrames,asyncStackTrace,asyncStackTraceId,needsStepIn){callback(error,exceptionDetails);if(needsStepIn){this.stepInto();return;}
  61. if(!error&&callFrames&&callFrames.length){this._pausedScript(callFrames,this._debuggerPausedDetails.reason,this._debuggerPausedDetails.auxData,this._debuggerPausedDetails.breakpointIds,asyncStackTrace,asyncStackTraceId);}}
  62. get callFrames(){return this._debuggerPausedDetails?this._debuggerPausedDetails.callFrames:null;}
  63. debuggerPausedDetails(){return this._debuggerPausedDetails;}
  64. _setDebuggerPausedDetails(debuggerPausedDetails){this._isPausing=false;this._debuggerPausedDetails=debuggerPausedDetails;if(this._debuggerPausedDetails){if(this._beforePausedCallback){if(!this._beforePausedCallback.call(null,this._debuggerPausedDetails)){return false;}}
  65. this._autoStepOver=false;this.dispatchEventToListeners(Events.DebuggerPaused,this);}
  66. if(debuggerPausedDetails){this.setSelectedCallFrame(debuggerPausedDetails.callFrames[0]);}else{this.setSelectedCallFrame(null);}
  67. return true;}
  68. setBeforePausedCallback(callback){this._beforePausedCallback=callback;}
  69. async _pausedScript(callFrames,reason,auxData,breakpointIds,asyncStackTrace,asyncStackTraceId,asyncCallStackTraceId){if(asyncCallStackTraceId){SDK.DebuggerModel._scheduledPauseOnAsyncCall=asyncCallStackTraceId;const promises=[];for(const model of SDK.DebuggerModel._debuggerIdToModel.values()){promises.push(model._pauseOnAsyncCall(asyncCallStackTraceId));}
  70. await Promise.all(promises);this.resume();return;}
  71. const pausedDetails=new DebuggerPausedDetails(this,callFrames,reason,auxData,breakpointIds,asyncStackTrace,asyncStackTraceId);if(pausedDetails&&this._continueToLocationCallback){const callback=this._continueToLocationCallback;delete this._continueToLocationCallback;if(callback(pausedDetails)){return;}}
  72. if(!this._setDebuggerPausedDetails(pausedDetails)){if(this._autoStepOver){this._agent.stepOver();}else{this._agent.stepInto();}}
  73. SDK.DebuggerModel._scheduledPauseOnAsyncCall=null;}
  74. _resumedScript(){this._setDebuggerPausedDetails(null);this.dispatchEventToListeners(Events.DebuggerResumed,this);}
  75. _parsedScriptSource(scriptId,sourceURL,startLine,startColumn,endLine,endColumn,executionContextId,hash,executionContextAuxData,isLiveEdit,sourceMapURL,hasSourceURLComment,hasSyntaxError,length,originStackTrace){if(this._scripts.has(scriptId)){return this._scripts.get(scriptId);}
  76. let isContentScript=false;if(executionContextAuxData&&('isDefault'in executionContextAuxData)){isContentScript=!executionContextAuxData['isDefault'];}
  77. sourceURL=this._internString(sourceURL);const script=new SDK.Script(this,scriptId,sourceURL,startLine,startColumn,endLine,endColumn,executionContextId,this._internString(hash),isContentScript,isLiveEdit,sourceMapURL,hasSourceURLComment,length,originStackTrace);this._registerScript(script);this.dispatchEventToListeners(Events.ParsedScriptSource,script);const sourceMapId=SDK.DebuggerModel._sourceMapId(script.executionContextId,script.sourceURL,script.sourceMapURL);if(sourceMapId&&!hasSyntaxError){const previousScript=this._sourceMapIdToScript.get(sourceMapId);if(previousScript){this._sourceMapManager.detachSourceMap(previousScript);}
  78. this._sourceMapIdToScript.set(sourceMapId,script);this._sourceMapManager.attachSourceMap(script,script.sourceURL,script.sourceMapURL);}
  79. const isDiscardable=hasSyntaxError&&script.isAnonymousScript();if(isDiscardable){this._discardableScripts.push(script);this._collectDiscardedScripts();}
  80. return script;}
  81. setSourceMapURL(script,newSourceMapURL){let sourceMapId=SDK.DebuggerModel._sourceMapId(script.executionContextId,script.sourceURL,script.sourceMapURL);if(sourceMapId&&this._sourceMapIdToScript.get(sourceMapId)===script){this._sourceMapIdToScript.delete(sourceMapId);}
  82. this._sourceMapManager.detachSourceMap(script);script.sourceMapURL=newSourceMapURL;sourceMapId=SDK.DebuggerModel._sourceMapId(script.executionContextId,script.sourceURL,script.sourceMapURL);if(!sourceMapId){return;}
  83. this._sourceMapIdToScript.set(sourceMapId,script);this._sourceMapManager.attachSourceMap(script,script.sourceURL,script.sourceMapURL);}
  84. executionContextDestroyed(executionContext){const sourceMapIds=Array.from(this._sourceMapIdToScript.keys());for(const sourceMapId of sourceMapIds){const script=this._sourceMapIdToScript.get(sourceMapId);if(script.executionContextId===executionContext.id){this._sourceMapIdToScript.delete(sourceMapId);this._sourceMapManager.detachSourceMap(script);}}}
  85. _registerScript(script){this._scripts.set(script.scriptId,script);if(script.isAnonymousScript()){return;}
  86. let scripts=this._scriptsBySourceURL.get(script.sourceURL);if(!scripts){scripts=[];this._scriptsBySourceURL.set(script.sourceURL,scripts);}
  87. scripts.push(script);}
  88. _unregisterScript(script){console.assert(script.isAnonymousScript());this._scripts.delete(script.scriptId);}
  89. _collectDiscardedScripts(){if(this._discardableScripts.length<1000){return;}
  90. const scriptsToDiscard=this._discardableScripts.splice(0,100);for(const script of scriptsToDiscard){this._unregisterScript(script);this.dispatchEventToListeners(Events.DiscardedAnonymousScriptSource,script);}}
  91. createRawLocation(script,lineNumber,columnNumber){return new Location(this,script.scriptId,lineNumber,columnNumber);}
  92. createRawLocationByURL(sourceURL,lineNumber,columnNumber){let closestScript=null;const scripts=this._scriptsBySourceURL.get(sourceURL)||[];for(let i=0,l=scripts.length;i<l;++i){const script=scripts[i];if(!closestScript){closestScript=script;}
  93. if(script.lineOffset>lineNumber||(script.lineOffset===lineNumber&&script.columnOffset>columnNumber)){continue;}
  94. if(script.endLine<lineNumber||(script.endLine===lineNumber&&script.endColumn<=columnNumber)){continue;}
  95. closestScript=script;break;}
  96. return closestScript?new Location(this,closestScript.scriptId,lineNumber,columnNumber):null;}
  97. createRawLocationByScriptId(scriptId,lineNumber,columnNumber){const script=this.scriptForId(scriptId);return script?this.createRawLocation(script,lineNumber,columnNumber):null;}
  98. createRawLocationsByStackTrace(stackTrace){const frames=[];while(stackTrace){for(const frame of stackTrace.callFrames){frames.push(frame);}
  99. stackTrace=stackTrace.parent;}
  100. const rawLocations=[];for(const frame of frames){const rawLocation=this.createRawLocationByScriptId(frame.scriptId,frame.lineNumber,frame.columnNumber);if(rawLocation){rawLocations.push(rawLocation);}}
  101. return rawLocations;}
  102. isPaused(){return!!this.debuggerPausedDetails();}
  103. isPausing(){return this._isPausing;}
  104. setSelectedCallFrame(callFrame){if(this._selectedCallFrame===callFrame){return;}
  105. this._selectedCallFrame=callFrame;this.dispatchEventToListeners(Events.CallFrameSelected,this);}
  106. selectedCallFrame(){return this._selectedCallFrame;}
  107. evaluateOnSelectedCallFrame(options){return this.selectedCallFrame().evaluate(options);}
  108. functionDetailsPromise(remoteObject){return remoteObject.getAllProperties(false,false).then(buildDetails.bind(this));function buildDetails(response){if(!response){return null;}
  109. let location=null;if(response.internalProperties){for(const prop of response.internalProperties){if(prop.name==='[[FunctionLocation]]'){location=prop.value;}}}
  110. let functionName=null;if(response.properties){for(const prop of response.properties){if(prop.name==='name'&&prop.value&&prop.value.type==='string'){functionName=prop.value;}
  111. if(prop.name==='displayName'&&prop.value&&prop.value.type==='string'){functionName=prop.value;break;}}}
  112. let debuggerLocation=null;if(location){debuggerLocation=this.createRawLocationByScriptId(location.value.scriptId,location.value.lineNumber,location.value.columnNumber);}
  113. return{location:debuggerLocation,functionName:functionName?functionName.value:''};}}
  114. async setVariableValue(scopeNumber,variableName,newValue,callFrameId){const response=await this._agent.invoke_setVariableValue({scopeNumber,variableName,newValue,callFrameId});const error=response[Protocol.Error];if(error){console.error(error);}
  115. return error;}
  116. addBreakpointListener(breakpointId,listener,thisObject){this._breakpointResolvedEventTarget.addEventListener(breakpointId,listener,thisObject);}
  117. removeBreakpointListener(breakpointId,listener,thisObject){this._breakpointResolvedEventTarget.removeEventListener(breakpointId,listener,thisObject);}
  118. async setBlackboxPatterns(patterns){const response=await this._agent.invoke_setBlackboxPatterns({patterns});const error=response[Protocol.Error];if(error){console.error(error);}
  119. return!error;}
  120. dispose(){this._sourceMapManager.dispose();SDK.DebuggerModel._debuggerIdToModel.delete(this._debuggerId);Common.moduleSetting('pauseOnExceptionEnabled').removeChangeListener(this._pauseOnExceptionStateChanged,this);Common.moduleSetting('pauseOnCaughtException').removeChangeListener(this._pauseOnExceptionStateChanged,this);Common.moduleSetting('disableAsyncStackTraces').removeChangeListener(this._asyncStackTracesStateChanged,this);}
  121. async suspendModel(){await this._disableDebugger();}
  122. async resumeModel(){await this._enableDebugger();}
  123. _internString(string){if(!this._stringMap.has(string)){this._stringMap.set(string,string);}
  124. return this._stringMap.get(string);}}
  125. export const _debuggerIdToModel=new Map();export const _scheduledPauseOnAsyncCall=null;export const PauseOnExceptionsState={DontPauseOnExceptions:'none',PauseOnAllExceptions:'all',PauseOnUncaughtExceptions:'uncaught'};export const Events={DebuggerWasEnabled:Symbol('DebuggerWasEnabled'),DebuggerWasDisabled:Symbol('DebuggerWasDisabled'),DebuggerPaused:Symbol('DebuggerPaused'),DebuggerResumed:Symbol('DebuggerResumed'),ParsedScriptSource:Symbol('ParsedScriptSource'),FailedToParseScriptSource:Symbol('FailedToParseScriptSource'),DiscardedAnonymousScriptSource:Symbol('DiscardedAnonymousScriptSource'),GlobalObjectCleared:Symbol('GlobalObjectCleared'),CallFrameSelected:Symbol('CallFrameSelected'),ConsoleCommandEvaluatedInSelectedCallFrame:Symbol('ConsoleCommandEvaluatedInSelectedCallFrame'),DebuggerIsReadyToPause:Symbol('DebuggerIsReadyToPause'),};export const BreakReason={DOM:'DOM',EventListener:'EventListener',XHR:'XHR',Exception:'exception',PromiseRejection:'promiseRejection',Assert:'assert',DebugCommand:'debugCommand',OOM:'OOM',Other:'other'};const ContinueToLocationTargetCallFrames={Any:'any',Current:'current'};class DebuggerDispatcher{constructor(debuggerModel){this._debuggerModel=debuggerModel;}
  126. paused(callFrames,reason,auxData,breakpointIds,asyncStackTrace,asyncStackTraceId,asyncCallStackTraceId){this._debuggerModel._pausedScript(callFrames,reason,auxData,breakpointIds||[],asyncStackTrace,asyncStackTraceId,asyncCallStackTraceId);}
  127. resumed(){this._debuggerModel._resumedScript();}
  128. scriptParsed(scriptId,sourceURL,startLine,startColumn,endLine,endColumn,executionContextId,hash,executionContextAuxData,isLiveEdit,sourceMapURL,hasSourceURL,isModule,length,stackTrace){this._debuggerModel._parsedScriptSource(scriptId,sourceURL,startLine,startColumn,endLine,endColumn,executionContextId,hash,executionContextAuxData,!!isLiveEdit,sourceMapURL,!!hasSourceURL,false,length||0,stackTrace||null);}
  129. scriptFailedToParse(scriptId,sourceURL,startLine,startColumn,endLine,endColumn,executionContextId,hash,executionContextAuxData,sourceMapURL,hasSourceURL,isModule,length,stackTrace){this._debuggerModel._parsedScriptSource(scriptId,sourceURL,startLine,startColumn,endLine,endColumn,executionContextId,hash,executionContextAuxData,false,sourceMapURL,!!hasSourceURL,true,length||0,stackTrace||null);}
  130. breakpointResolved(breakpointId,location){this._debuggerModel._breakpointResolved(breakpointId,location);}}
  131. export class Location{constructor(debuggerModel,scriptId,lineNumber,columnNumber){this.debuggerModel=debuggerModel;this.scriptId=scriptId;this.lineNumber=lineNumber;this.columnNumber=columnNumber||0;}
  132. static fromPayload(debuggerModel,payload){return new Location(debuggerModel,payload.scriptId,payload.lineNumber,payload.columnNumber);}
  133. payload(){return{scriptId:this.scriptId,lineNumber:this.lineNumber,columnNumber:this.columnNumber};}
  134. script(){return this.debuggerModel.scriptForId(this.scriptId);}
  135. continueToLocation(pausedCallback){if(pausedCallback){this.debuggerModel._continueToLocationCallback=this._paused.bind(this,pausedCallback);}
  136. this.debuggerModel._agent.continueToLocation(this.payload(),ContinueToLocationTargetCallFrames.Current);}
  137. _paused(pausedCallback,debuggerPausedDetails){const location=debuggerPausedDetails.callFrames[0].location();if(location.scriptId===this.scriptId&&location.lineNumber===this.lineNumber&&location.columnNumber===this.columnNumber){pausedCallback();return true;}
  138. return false;}
  139. id(){return this.debuggerModel.target().id()+':'+this.scriptId+':'+this.lineNumber+':'+this.columnNumber;}}
  140. export class BreakLocation extends Location{constructor(debuggerModel,scriptId,lineNumber,columnNumber,type){super(debuggerModel,scriptId,lineNumber,columnNumber);if(type){this.type=type;}}
  141. static fromPayload(debuggerModel,payload){return new BreakLocation(debuggerModel,payload.scriptId,payload.lineNumber,payload.columnNumber,payload.type);}}
  142. export class CallFrame{constructor(debuggerModel,script,payload){this.debuggerModel=debuggerModel;this._script=script;this._payload=payload;this._location=Location.fromPayload(debuggerModel,payload.location);this._scopeChain=[];this._localScope=null;for(let i=0;i<payload.scopeChain.length;++i){const scope=new Scope(this,i);this._scopeChain.push(scope);if(scope.type()===Protocol.Debugger.ScopeType.Local){this._localScope=scope;}}
  143. if(payload.functionLocation){this._functionLocation=Location.fromPayload(debuggerModel,payload.functionLocation);}
  144. this._returnValue=payload.returnValue?this.debuggerModel._runtimeModel.createRemoteObject(payload.returnValue):null;}
  145. static fromPayloadArray(debuggerModel,callFrames){const result=[];for(let i=0;i<callFrames.length;++i){const callFrame=callFrames[i];const script=debuggerModel.scriptForId(callFrame.location.scriptId);if(script){result.push(new CallFrame(debuggerModel,script,callFrame));}}
  146. return result;}
  147. get script(){return this._script;}
  148. get id(){return this._payload.callFrameId;}
  149. scopeChain(){return this._scopeChain;}
  150. localScope(){return this._localScope;}
  151. thisObject(){return this._payload.this?this.debuggerModel._runtimeModel.createRemoteObject(this._payload.this):null;}
  152. returnValue(){return this._returnValue;}
  153. async setReturnValue(expression){if(!this._returnValue){return null;}
  154. const evaluateResponse=await this.debuggerModel._agent.invoke_evaluateOnCallFrame({callFrameId:this.id,expression:expression,silent:true,objectGroup:'backtrace'});if(evaluateResponse[Protocol.Error]||evaluateResponse.exceptionDetails){return null;}
  155. const response=await this.debuggerModel._agent.invoke_setReturnValue({newValue:evaluateResponse.result});if(response[Protocol.Error]){return null;}
  156. this._returnValue=this.debuggerModel._runtimeModel.createRemoteObject(evaluateResponse.result);return this._returnValue;}
  157. get functionName(){return this._payload.functionName;}
  158. location(){return this._location;}
  159. functionLocation(){return this._functionLocation||null;}
  160. async evaluate(options){const runtimeModel=this.debuggerModel.runtimeModel();const needsTerminationOptions=!!options.throwOnSideEffect||options.timeout!==undefined;if(needsTerminationOptions&&(runtimeModel.hasSideEffectSupport()===false||(runtimeModel.hasSideEffectSupport()===null&&!await runtimeModel.checkSideEffectSupport()))){return{error:'Side-effect checks not supported by backend.'};}
  161. const response=await this.debuggerModel._agent.invoke_evaluateOnCallFrame({callFrameId:this.id,expression:options.expression,objectGroup:options.objectGroup,includeCommandLineAPI:options.includeCommandLineAPI,silent:options.silent,returnByValue:options.returnByValue,generatePreview:options.generatePreview,throwOnSideEffect:options.throwOnSideEffect,timeout:options.timeout});const error=response[Protocol.Error];if(error){console.error(error);return{error:error};}
  162. return{object:runtimeModel.createRemoteObject(response.result),exceptionDetails:response.exceptionDetails};}
  163. async restart(){const response=await this.debuggerModel._agent.invoke_restartFrame({callFrameId:this._payload.callFrameId});if(!response[Protocol.Error]){this.debuggerModel.stepInto();}}}
  164. export class Scope{constructor(callFrame,ordinal){this._callFrame=callFrame;this._payload=callFrame._payload.scopeChain[ordinal];this._type=this._payload.type;this._name=this._payload.name;this._ordinal=ordinal;this._startLocation=this._payload.startLocation?Location.fromPayload(callFrame.debuggerModel,this._payload.startLocation):null;this._endLocation=this._payload.endLocation?Location.fromPayload(callFrame.debuggerModel,this._payload.endLocation):null;}
  165. callFrame(){return this._callFrame;}
  166. type(){return this._type;}
  167. typeName(){switch(this._type){case Protocol.Debugger.ScopeType.Local:return Common.UIString('Local');case Protocol.Debugger.ScopeType.Closure:return Common.UIString('Closure');case Protocol.Debugger.ScopeType.Catch:return Common.UIString('Catch');case Protocol.Debugger.ScopeType.Block:return Common.UIString('Block');case Protocol.Debugger.ScopeType.Script:return Common.UIString('Script');case Protocol.Debugger.ScopeType.With:return Common.UIString('With Block');case Protocol.Debugger.ScopeType.Global:return Common.UIString('Global');case Protocol.Debugger.ScopeType.Module:return Common.UIString('Module');}
  168. return'';}
  169. name(){return this._name;}
  170. startLocation(){return this._startLocation;}
  171. endLocation(){return this._endLocation;}
  172. object(){if(this._object){return this._object;}
  173. const runtimeModel=this._callFrame.debuggerModel._runtimeModel;const declarativeScope=this._type!==Protocol.Debugger.ScopeType.With&&this._type!==Protocol.Debugger.ScopeType.Global;if(declarativeScope){this._object=runtimeModel.createScopeRemoteObject(this._payload.object,new SDK.ScopeRef(this._ordinal,this._callFrame.id));}else{this._object=runtimeModel.createRemoteObject(this._payload.object);}
  174. return this._object;}
  175. description(){const declarativeScope=this._type!==Protocol.Debugger.ScopeType.With&&this._type!==Protocol.Debugger.ScopeType.Global;return declarativeScope?'':(this._payload.object.description||'');}}
  176. export class DebuggerPausedDetails{constructor(debuggerModel,callFrames,reason,auxData,breakpointIds,asyncStackTrace,asyncStackTraceId){this.debuggerModel=debuggerModel;this.callFrames=CallFrame.fromPayloadArray(debuggerModel,callFrames);this.reason=reason;this.auxData=auxData;this.breakpointIds=breakpointIds;if(asyncStackTrace){this.asyncStackTrace=this._cleanRedundantFrames(asyncStackTrace);}
  177. this.asyncStackTraceId=asyncStackTraceId;}
  178. exception(){if(this.reason!==BreakReason.Exception&&this.reason!==BreakReason.PromiseRejection){return null;}
  179. return this.debuggerModel._runtimeModel.createRemoteObject((this.auxData));}
  180. _cleanRedundantFrames(asyncStackTrace){let stack=asyncStackTrace;let previous=null;while(stack){if(stack.description==='async function'&&stack.callFrames.length){stack.callFrames.shift();}
  181. if(previous&&!stack.callFrames.length){previous.parent=stack.parent;}else{previous=stack;}
  182. stack=stack.parent;}
  183. return asyncStackTrace;}}
  184. self.SDK=self.SDK||{};SDK=SDK||{};SDK.DebuggerModel=DebuggerModel;SDK.DebuggerModel.PauseOnExceptionsState=PauseOnExceptionsState;SDK.DebuggerModel.Events=Events;SDK.DebuggerModel.BreakReason=BreakReason;SDK.DebuggerModel.Location=Location;SDK.DebuggerModel.BreakLocation=BreakLocation;SDK.DebuggerModel.CallFrame=CallFrame;SDK.DebuggerModel.Scope=Scope;SDK.DebuggerPausedDetails=DebuggerPausedDetails;SDK.SDKModel.register(SDK.DebuggerModel,SDK.Target.Capability.JS,true);SDK.DebuggerModel.FunctionDetails;SDK.DebuggerModel.SetBreakpointResult;SDK.DebuggerModel._debuggerIdToModel=_debuggerIdToModel;SDK.DebuggerModel._scheduledPauseOnAsyncCall=_scheduledPauseOnAsyncCall;