From 64244e2b32e6fcff5257cbbbf331ee3df0e4085e Mon Sep 17 00:00:00 2001 From: gopu-bruno Date: Tue, 7 Apr 2026 10:55:02 +0530 Subject: [PATCH 1/2] fix: prevent assertions from returning wrong values during large iteration runs --- packages/bruno-js/src/sandbox/quickjs/index.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/bruno-js/src/sandbox/quickjs/index.js b/packages/bruno-js/src/sandbox/quickjs/index.js index aa419b95875..a610e36e551 100644 --- a/packages/bruno-js/src/sandbox/quickjs/index.js +++ b/packages/bruno-js/src/sandbox/quickjs/index.js @@ -14,10 +14,9 @@ const { marshallToVm } = require('./utils'); const addCryptoUtilsShimToContext = require('./shims/lib/crypto-utils'); const { wrapScriptInClosure, SANDBOX } = require('../../utils/sandbox'); -let QuickJSSyncContext; +let QuickJSModule; const loader = memoizePromiseFactory(() => newQuickJSWASMModule()); -const getContext = (opts) => loader().then((mod) => (QuickJSSyncContext = mod.newContext(opts))); -getContext(); +loader().then((mod) => (QuickJSModule = mod)); const toNumber = (value) => { const num = Number(value); @@ -57,7 +56,7 @@ const executeQuickJsVm = ({ script: externalScript, context: externalContext, sc externalScript = removeQuotes(externalScript); } - const vm = QuickJSSyncContext; + const vm = QuickJSModule.newContext(); try { const { bru, req, res, ...variables } = externalContext; @@ -97,7 +96,7 @@ const executeQuickJsVmAsync = async ({ script: externalScript, context: external externalScript = externalScript?.trim(); try { - const module = await newQuickJSWASMModule(); + const module = await loader(); const vm = module.newContext(); // add crypto utilities required by the crypto-js library in bundledCode From ea2cbe92456cf01a46ec4250cb1daf9c2925f9ef Mon Sep 17 00:00:00 2001 From: gopu-bruno Date: Tue, 7 Apr 2026 13:10:23 +0530 Subject: [PATCH 2/2] fix: handle QuickJS context creation inside try block --- packages/bruno-js/src/sandbox/quickjs/index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/bruno-js/src/sandbox/quickjs/index.js b/packages/bruno-js/src/sandbox/quickjs/index.js index a610e36e551..cf454a24b1e 100644 --- a/packages/bruno-js/src/sandbox/quickjs/index.js +++ b/packages/bruno-js/src/sandbox/quickjs/index.js @@ -56,9 +56,8 @@ const executeQuickJsVm = ({ script: externalScript, context: externalContext, sc externalScript = removeQuotes(externalScript); } - const vm = QuickJSModule.newContext(); - try { + const vm = QuickJSModule.newContext(); const { bru, req, res, ...variables } = externalContext; bru && addBruShimToContext(vm, bru);