DB
This commit is contained in:
@ -28,13 +28,17 @@ export class Vm {
|
||||
this.jail.set("global", this.jail.derefInto());
|
||||
|
||||
for (const mod of this.modules) {
|
||||
this.jail.setSync(mod.getName(), mod.getSource());
|
||||
await this.context.eval(mod.getSource());
|
||||
}
|
||||
|
||||
for (const plugin of this.plugins) {
|
||||
this.jail.setSync(
|
||||
plugin.getName(),
|
||||
new ivm.Reference(plugin.run.bind(plugin))
|
||||
new ivm.Reference(async (...args) => {
|
||||
const res = await plugin.run(...args);
|
||||
|
||||
return res;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@ -61,6 +65,9 @@ export class Vm {
|
||||
});
|
||||
|
||||
// TODO: log
|
||||
this.setFunction("log", (...args) => {
|
||||
console.log("vm log:", args);
|
||||
});
|
||||
|
||||
this.setFunction("error", (error: any) => {
|
||||
console.error("Script error:", error);
|
||||
@ -82,9 +89,12 @@ export class Vm {
|
||||
const compiledScript = await this.isolate.compileScript(scriptWithResult);
|
||||
|
||||
compiledScript.run(this.context);
|
||||
this.onFinish();
|
||||
|
||||
return await resultPromise;
|
||||
try {
|
||||
return await resultPromise;
|
||||
} finally {
|
||||
this.onFinish();
|
||||
}
|
||||
}
|
||||
|
||||
onFinish() {
|
||||
|
||||
Reference in New Issue
Block a user