From 07efa3b8dfa062c7530855823d8271d4b3196d05 Mon Sep 17 00:00:00 2001 From: Boris D Date: Mon, 22 Sep 2025 18:38:21 +0300 Subject: [PATCH] refactor: simplify async function calls in asyncCall and Vm class --- src/vm/modules/async.js | 8 ++++++-- src/vm/vm.class.ts | 4 +--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/vm/modules/async.js b/src/vm/modules/async.js index 3602c85..006d4c8 100644 --- a/src/vm/modules/async.js +++ b/src/vm/modules/async.js @@ -4,9 +4,13 @@ async function asyncCall(reference, args) { args = [args]; } - const resJson = await reference.apply(undefined, args, { + const res = await reference.apply(undefined, args, { result: { promise: true }, }); - return JSON.parse(resJson); + if (typeof res === "string") { + return JSON.parse(res); + } + + return res; } diff --git a/src/vm/vm.class.ts b/src/vm/vm.class.ts index f756160..59befae 100644 --- a/src/vm/vm.class.ts +++ b/src/vm/vm.class.ts @@ -35,9 +35,7 @@ export class Vm { this.jail.setSync( plugin.getName(), new ivm.Reference(async (...args) => { - const res = await plugin.run(...args); - - return res; + return await plugin.run(...args); }) ); }