Add stepping and breakpoints to debugger
This commit is contained in:
@ -134,6 +134,16 @@ class ExecutionController<RS> {
|
||||
return this._result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run a single step of execution
|
||||
* @returns Result of execution
|
||||
*/
|
||||
executeStep(): StepExecutionResult<RS> {
|
||||
this._result = this._engine.executeStep();
|
||||
this._result.signal = "paused";
|
||||
return this._result;
|
||||
}
|
||||
|
||||
/** Asynchronously sleep for a period of time */
|
||||
private async sleep(millis: number) {
|
||||
return new Promise<void>((resolve) => setTimeout(resolve, millis));
|
||||
|
@ -22,6 +22,10 @@ export type WorkerRequestData =
|
||||
type: "Execute";
|
||||
params: { interval?: number };
|
||||
}
|
||||
| {
|
||||
type: "ExecuteStep";
|
||||
params?: null;
|
||||
}
|
||||
| {
|
||||
type: "Pause";
|
||||
params?: null;
|
||||
|
@ -64,7 +64,6 @@ const updateBreakpoints = (points: number[]) => {
|
||||
* and return result of execution.
|
||||
*/
|
||||
const execute = (interval?: number) => {
|
||||
console.info(`Executing at interval ${interval}`);
|
||||
_controller!.executeAll({
|
||||
interval,
|
||||
onResult: (res) => postMessage(resultMessage(res)),
|
||||
@ -79,12 +78,21 @@ const pauseExecution = async () => {
|
||||
postMessage(ackMessage("pause"));
|
||||
};
|
||||
|
||||
/**
|
||||
* Run a single execution step
|
||||
*/
|
||||
const executeStep = () => {
|
||||
const result = _controller!.executeStep();
|
||||
postMessage(resultMessage(result));
|
||||
};
|
||||
|
||||
addEventListener("message", async (ev: MessageEvent<WorkerRequestData>) => {
|
||||
if (ev.data.type === "Init") return initController();
|
||||
if (ev.data.type === "Reset") return resetController();
|
||||
if (ev.data.type === "Prepare") return prepare(ev.data.params);
|
||||
if (ev.data.type === "Execute") return execute(ev.data.params.interval);
|
||||
if (ev.data.type === "Pause") return await pauseExecution();
|
||||
if (ev.data.type === "ExecuteStep") return executeStep();
|
||||
if (ev.data.type === "UpdateBreakpoints")
|
||||
return updateBreakpoints(ev.data.params.points);
|
||||
throw new Error("Invalid worker message type");
|
||||
|
Reference in New Issue
Block a user