export default class RuntimeModel extends SDK.SDKModel{constructor(target){super(target);this._agent=target.runtimeAgent();this.target().registerRuntimeDispatcher(new RuntimeDispatcher(this));this._agent.enable();this._executionContextById=new Map();this._executionContextComparator=ExecutionContext.comparator;this._hasSideEffectSupport=null;if(Common.moduleSetting('customFormatters').get()){this._agent.setCustomObjectFormatterEnabled(true);} Common.moduleSetting('customFormatters').addChangeListener(this._customFormattersStateChanged.bind(this));} static isSideEffectFailure(response){const exceptionDetails=!response[Protocol.Error]&&response.exceptionDetails;return!!(exceptionDetails&&exceptionDetails.exception&&exceptionDetails.exception.description&&exceptionDetails.exception.description.startsWith('EvalError: Possible side-effect in debug-evaluate'));} debuggerModel(){return(this.target().model(SDK.DebuggerModel));} heapProfilerModel(){return(this.target().model(SDK.HeapProfilerModel));} executionContexts(){return this._executionContextById.valuesArray().sort(this.executionContextComparator());} setExecutionContextComparator(comparator){this._executionContextComparator=comparator;} executionContextComparator(){return this._executionContextComparator;} defaultExecutionContext(){for(const context of this.executionContexts()){if(context.isDefault){return context;}} return null;} executionContext(id){return this._executionContextById.get(id)||null;} _executionContextCreated(context){const data=context.auxData||{isDefault:true};const executionContext=new ExecutionContext(this,context.id,context.name,context.origin,data['isDefault'],data['frameId']);this._executionContextById.set(executionContext.id,executionContext);this.dispatchEventToListeners(Events.ExecutionContextCreated,executionContext);} _executionContextDestroyed(executionContextId){const executionContext=this._executionContextById.get(executionContextId);if(!executionContext){return;} this.debuggerModel().executionContextDestroyed(executionContext);this._executionContextById.delete(executionContextId);this.dispatchEventToListeners(Events.ExecutionContextDestroyed,executionContext);} fireExecutionContextOrderChanged(){this.dispatchEventToListeners(Events.ExecutionContextOrderChanged,this);} _executionContextsCleared(){this.debuggerModel().globalObjectCleared();const contexts=this.executionContexts();this._executionContextById.clear();for(let i=0;i{if(this.runtimeModel.hasSideEffectSupport()){return this._evaluateGlobal(options,userGesture,awaitPromise);} return Promise.resolve(unsupportedError);});} globalObject(objectGroup,generatePreview){return this._evaluateGlobal({expression:'this',objectGroup:objectGroup,includeCommandLineAPI:false,silent:true,returnByValue:false,generatePreview:generatePreview},false,false);} async _evaluateGlobal(options,userGesture,awaitPromise){if(!options.expression){options.expression='this';} const response=await this.runtimeModel._agent.invoke_evaluate({expression:String.escapeInvalidUnicodeCharacters(options.expression),objectGroup:options.objectGroup,includeCommandLineAPI:options.includeCommandLineAPI,silent:options.silent,contextId:this.id,returnByValue:options.returnByValue,generatePreview:options.generatePreview,userGesture:userGesture,awaitPromise:awaitPromise,throwOnSideEffect:options.throwOnSideEffect,timeout:options.timeout,disableBreaks:options.disableBreaks,replMode:options.replMode});const error=response[Protocol.Error];if(error){console.error(error);return{error:error};} return{object:this.runtimeModel.createRemoteObject(response.result),exceptionDetails:response.exceptionDetails};} async globalLexicalScopeNames(){const response=await this.runtimeModel._agent.invoke_globalLexicalScopeNames({executionContextId:this.id});return response[Protocol.Error]?[]:response.names;} label(){return this._label;} setLabel(label){this._setLabel(label);this.runtimeModel.dispatchEventToListeners(Events.ExecutionContextChanged,this);} _setLabel(label){if(label){this._label=label;return;} if(this.name){this._label=this.name;return;} const parsedUrl=this.origin.asParsedURL();this._label=parsedUrl?parsedUrl.lastPathComponentWithFragment():'';}} self.SDK=self.SDK||{};SDK=SDK||{};SDK.RuntimeModel=RuntimeModel;SDK.RuntimeModel.Events=Events;SDK.ExecutionContext=ExecutionContext;SDK.RuntimeModel.CompileScriptResult;SDK.RuntimeModel.EvaluationOptions;SDK.RuntimeModel.EvaluationResult;SDK.RuntimeModel.QueryObjectResult;SDK.RuntimeModel.ConsoleAPICall;SDK.RuntimeModel.ExceptionWithTimestamp;SDK.SDKModel.register(SDK.RuntimeModel,SDK.Target.Capability.JS,true);