From d1d005dbbc74efb9a3a016a3b83250f18a0d6bb4 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 8 Feb 2024 11:26:51 +0100 Subject: [PATCH] DRY --- packages/server/src/jsRunner/vm/index.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/server/src/jsRunner/vm/index.ts b/packages/server/src/jsRunner/vm/index.ts index 2bacf5f133..45e2ebcf09 100644 --- a/packages/server/src/jsRunner/vm/index.ts +++ b/packages/server/src/jsRunner/vm/index.ts @@ -205,8 +205,8 @@ export class IsolatedVM implements VM { script.evaluateSync({ timeout: this.#timeout }) - const result = this.#getResult() - return result + const result = this.#getFromContext(this.#resultKey) + return result.out } #registerCallbacks(functions: Record) { @@ -241,13 +241,9 @@ export class IsolatedVM implements VM { } #getFromContext(key: string) { - return this.#jail.getSync(key) - } - - #getResult() { - const ref = this.#vm.global.getSync(this.#resultKey, { reference: true }) + const ref = this.#vm.global.getSync(key, { reference: true }) const result = ref.copySync() ref.release() - return result.out + return result } }