@yuebai008/cli
Version:
Command line interface for rapid qg-minigame development
1 lines • 6.51 kB
JavaScript
import*as Common from"../../core/common/common.js";import*as i18n from"../../core/i18n/i18n.js";const UIStrings={anErrorOccurredWhenACallToMethod:"An error occurred when a call to method ''{PH1}'' was requested"},str_=i18n.i18n.registerUIStrings("panels/profiler/HeapSnapshotProxy.ts",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_);export class HeapSnapshotWorkerProxy extends Common.ObjectWrapper.ObjectWrapper{eventHandler;nextObjectId;nextCallId;callbacks;previousCallbacks;worker;interval;constructor(e){super(),this.eventHandler=e,this.nextObjectId=1,this.nextCallId=1,this.callbacks=new Map,this.previousCallbacks=new Set,this.worker=Common.Worker.WorkerWrapper.fromURL(new URL("../../entrypoints/heap_snapshot_worker/heap_snapshot_worker-legacy.js",import.meta.url)),this.worker.onmessage=this.messageReceived.bind(this)}createLoader(e,t){const s=this.nextObjectId++,o=new HeapSnapshotLoaderProxy(this,s,e,t);return this.postMessage({callId:this.nextCallId++,disposition:"create",objectId:s,methodName:"HeapSnapshotWorker.HeapSnapshotLoader"}),o}dispose(){this.worker.terminate(),this.interval&&clearInterval(this.interval)}disposeObject(e){this.postMessage({callId:this.nextCallId++,disposition:"dispose",objectId:e})}evaluateForTest(e,t){const s=this.nextCallId++;this.callbacks.set(s,t),this.postMessage({callId:s,disposition:"evaluateForTest",source:e})}callFactoryMethod(e,t,s,o){const r=this.nextCallId++,a=Array.prototype.slice.call(arguments,4),i=this.nextObjectId++;return e?(this.callbacks.set(r,(t=>{e(t?new o(this,i):null)})),this.postMessage({callId:r,disposition:"factory",objectId:t,methodName:s,methodArguments:a,newObjectId:i}),null):(this.postMessage({callId:r,disposition:"factory",objectId:t,methodName:s,methodArguments:a,newObjectId:i}),new o(this,i))}callMethod(e,t,s){const o=this.nextCallId++,r=Array.prototype.slice.call(arguments,3);e&&this.callbacks.set(o,e),this.postMessage({callId:o,disposition:"method",objectId:t,methodName:s,methodArguments:r})}startCheckingForLongRunningCalls(){this.interval||(this.checkLongRunningCalls(),this.interval=window.setInterval(this.checkLongRunningCalls.bind(this),300))}checkLongRunningCalls(){for(const e of this.previousCallbacks)this.callbacks.has(e)||this.previousCallbacks.delete(e);const e=Boolean(this.previousCallbacks.size);this.dispatchEventToListeners("Wait",e);for(const e of this.callbacks.keys())this.previousCallbacks.add(e)}messageReceived(e){const t=e.data;if(t.eventName)return void(this.eventHandler&&this.eventHandler(t.eventName,t.data));if(t.error)return t.errorMethodName&&Common.Console.Console.instance().error(i18nString(UIStrings.anErrorOccurredWhenACallToMethod,{PH1:t.errorMethodName})),Common.Console.Console.instance().error(t.errorCallStack),void this.callbacks.delete(t.callId);const s=this.callbacks.get(t.callId);s&&(this.callbacks.delete(t.callId),s(t.result))}postMessage(e){this.worker.postMessage(e)}}export class HeapSnapshotProxyObject{worker;objectId;constructor(e,t){this.worker=e,this.objectId=t}callWorker(e,t){t.splice(1,0,this.objectId);const s=this.worker[e];if(!s)throw new Error(`Could not find worker with name ${e}.`);return s.apply(this.worker,t)}dispose(){this.worker.disposeObject(this.objectId)}disposeWorker(){this.worker.dispose()}callFactoryMethod(e,t,s,...o){return this.callWorker("callFactoryMethod",Array.prototype.slice.call(arguments,0))}callMethodPromise(e,...t){const s=Array.prototype.slice.call(arguments);return new Promise((e=>this.callWorker("callMethod",[e,...s])))}}export class HeapSnapshotLoaderProxy extends HeapSnapshotProxyObject{profileUid;snapshotReceivedCallback;constructor(e,t,s,o){super(e,t),this.profileUid=s,this.snapshotReceivedCallback=o}async write(e){await this.callMethodPromise("write",e)}async close(){await this.callMethodPromise("close");const e=await new Promise((e=>this.callFactoryMethod(e,"buildSnapshot",HeapSnapshotProxy)));this.dispose(),e.setProfileUid(this.profileUid),await e.updateStaticData(),this.snapshotReceivedCallback(e)}}export class HeapSnapshotProxy extends HeapSnapshotProxyObject{staticData;profileUid;constructor(e,t){super(e,t),this.staticData=null}search(e,t){return this.callMethodPromise("search",e,t)}aggregatesWithFilter(e){return this.callMethodPromise("aggregatesWithFilter",e)}aggregatesForDiff(){return this.callMethodPromise("aggregatesForDiff")}calculateSnapshotDiff(e,t){return this.callMethodPromise("calculateSnapshotDiff",e,t)}nodeClassName(e){return this.callMethodPromise("nodeClassName",e)}createEdgesProvider(e){return this.callFactoryMethod(null,"createEdgesProvider",HeapSnapshotProviderProxy,e)}createRetainingEdgesProvider(e){return this.callFactoryMethod(null,"createRetainingEdgesProvider",HeapSnapshotProviderProxy,e)}createAddedNodesProvider(e,t){return this.callFactoryMethod(null,"createAddedNodesProvider",HeapSnapshotProviderProxy,e,t)}createDeletedNodesProvider(e){return this.callFactoryMethod(null,"createDeletedNodesProvider",HeapSnapshotProviderProxy,e)}createNodesProvider(e){return this.callFactoryMethod(null,"createNodesProvider",HeapSnapshotProviderProxy,e)}createNodesProviderForClass(e,t){return this.callFactoryMethod(null,"createNodesProviderForClass",HeapSnapshotProviderProxy,e,t)}allocationTracesTops(){return this.callMethodPromise("allocationTracesTops")}allocationNodeCallers(e){return this.callMethodPromise("allocationNodeCallers",e)}allocationStack(e){return this.callMethodPromise("allocationStack",e)}dispose(){throw new Error("Should never be called")}get nodeCount(){return this.staticData?this.staticData.nodeCount:0}get rootNodeIndex(){return this.staticData?this.staticData.rootNodeIndex:0}async updateStaticData(){this.staticData=await this.callMethodPromise("updateStaticData")}getStatistics(){return this.callMethodPromise("getStatistics")}getLocation(e){return this.callMethodPromise("getLocation",e)}getSamples(){return this.callMethodPromise("getSamples")}get totalSize(){return this.staticData?this.staticData.totalSize:0}get uid(){return this.profileUid}setProfileUid(e){this.profileUid=e}maxJSObjectId(){return this.staticData?this.staticData.maxJSObjectId:0}}export class HeapSnapshotProviderProxy extends HeapSnapshotProxyObject{constructor(e,t){super(e,t)}nodePosition(e){return this.callMethodPromise("nodePosition",e)}isEmpty(){return this.callMethodPromise("isEmpty")}serializeItemsRange(e,t){return this.callMethodPromise("serializeItemsRange",e,t)}async sortAndRewind(e){await this.callMethodPromise("sortAndRewind",e)}}