SillyTavern/public/scripts/slash-commands/SlashCommandDebugController.js

53 lines
1.3 KiB
JavaScript
Raw Normal View History

2024-06-18 20:29:29 +02:00
import { SlashCommandClosure } from './SlashCommandClosure.js';
import { SlashCommandExecutor } from './SlashCommandExecutor.js';
export class SlashCommandDebugController {
2024-06-20 19:06:58 +02:00
/**@type {SlashCommandClosure[]} */ stack = [];
2024-06-18 20:29:29 +02:00
/**@type {boolean} */ isStepping = false;
/**@type {boolean} */ isSteppingInto = false;
/**@type {Promise<boolean>} */ continuePromise;
/**@type {(boolean)=>void} */ continueResolver;
/**@type {(closure:SlashCommandClosure, executor:SlashCommandExecutor)=>Promise<boolean>} */ onBreakPoint;
2024-06-20 19:06:58 +02:00
down(closure) {
this.stack.push(closure);
}
up() {
this.stack.pop();
}
2024-06-18 20:29:29 +02:00
resume() {
this.continueResolver?.(false);
this.continuePromise = null;
}
step() {
this.continueResolver?.(true);
this.continuePromise = null;
}
stepInto() {
this.isSteppingInto = true;
this.continueResolver?.(true);
this.continuePromise = null;
}
async awaitContinue() {
this.continuePromise ??= new Promise(resolve=>{
this.continueResolver = resolve;
});
this.isStepping = await this.continuePromise;
return this.isStepping;
}
async awaitBreakPoint(closure, executor) {
this.isStepping = await this.onBreakPoint(closure, executor);
return this.isStepping;
}
}