!function(){class e{constructor(){this.__eventListeners={}}addEventListener(e,t){this.__eventListeners[e]||(this.__eventListeners[e]=[]);this.__eventListeners[e].push(t)}removeEventListener(e,t){if(this.__eventListeners[e])for(var n=0;n<this.__eventListeners[e].length;n++)if(this.__eventListeners[e][n]===t){this.__eventListeners[e].splice(n,1);break}}isEventListenerAttached(e,t){if(this.__eventListeners[e]){if(!t)return this.__eventListeners[e].length;for(var n=0;n<this.__eventListeners[e].length;n++)if(this.__eventListeners[e][n]===t)return 1}return 0}removeAllEventListeners(){this.__eventListeners=[]}__fireEvent(e,t){if(this.__eventListeners[e]){let n=this.__eventListeners[e].slice(0);for(let e=0;e<n.length;e++)n[e](t)}}}toolUI=function(){var t={},n=!0,s=0,r={},a=function(n){t.hasOwnProperty(n);var s={isConnected:!1,eventManager:new e},r={name:n,postMessage:function(e){if(!s.isConnected)throw new Error("Cannot postMessage on an unconnected port.");external.sendMessage("OnMessage",this.name,JSON.stringify({type:"message",id:this.name,data:e}))},addEventListener:s.eventManager.addEventListener.bind(s.eventManager),removeEventListener:s.eventManager.removeEventListener.bind(s.eventManager)},a={internalData:s,port:r};t[n]=a;return a},i=new e,o=0;external.addEventListener("message",function(e){switch(e.commandId){case"OnConnect":var s=a(e.portName);s.internalData.isConnected=!0;i.__fireEvent("connect",s.port);break;case"OnMessage":var c=JSON.parse(e.data);if(!t.hasOwnProperty(c.id))throw new Error(`Diagnostics message received for unknown port. e.data = '${e.data}'. e.portName = '${e.portName}'.\n                                         isAttached = ${n}. 'privatePorts is empty' = ${JSON.stringify(t)===JSON.stringify({})};`);t[c.id].internalData.eventManager.__fireEvent("message",{data:c.data});break;case"OnDetach":t={};n=!1;i.__fireEvent("detach",{});break;case"OnBreakpointHit":i.__fireEvent("breakpointhit",{});break;case"OnResumeScriptExecution":i.__fireEvent("resumeScriptExecution",{});break;case"OnGetBreakFlagsResult":o=parseInt(e.breakFlags,10);break;case"OnRemoteScriptError":i.__fireEvent("scripterror",e);break;case"OnETWResult":if(r[e.id]){r[e.id](e.result,e.error);delete r[e.id]}break;case"OnETWMessage":i.__fireEvent("etwmessage",{result:e.result,session:e.data})}});return{engineSupportsES5:!0,createPort:function(e){return a(e).port},connect:function(e){if(!t.hasOwnProperty(e.name))throw new Error("You must use a port created by ScriptedHost.Diagnostics.createPort");external.sendMessage("OnMessage",e.name,JSON.stringify({type:"connect",id:e.name,data:null}));t[e.name].internalData.isConnected=!0},addEventListener:i.addEventListener.bind(i),removeEventListener:i.removeEventListener.bind(i),getBreakFlags:function(){external.sendMessage("GetBreakFlags","empty");return o},takeMemorySnapshot:function(e,t,n){external.sendMessage("TakeMemorySnapshot",e,t,""+n)},startSession:function(e,t,n,a){var i=""+ ++s;r[i]=a;external.sendMessage("StartSession",i,e,t,n?"1":"")},stopSession:function(e,t){var n=++s+":"+e;r[n]=t;external.sendMessage("StopSession",n)},stopCollection:function(e,t){var n=++s+":"+e;r[n]=t;external.sendMessage("StopCollection",n)},getGraphDataUpdate:function(e,t,n){var a=++s+":"+e;r[a]=n;external.sendMessage("GetGraphDataUpdate",a,t)},sendStringToCollectionAgent:function(e,t,n){var a=++s+":"+e;r[a]=n;external.sendMessage("SendStringToCollectionAgent",a,t)}}}()}();
