Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions packages/bruno-js/src/sandbox/quickjs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -57,9 +56,8 @@ const executeQuickJsVm = ({ script: externalScript, context: externalContext, sc
externalScript = removeQuotes(externalScript);
}

const vm = QuickJSSyncContext;

try {
const vm = QuickJSModule.newContext();
const { bru, req, res, ...variables } = externalContext;

bru && addBruShimToContext(vm, bru);
Expand Down Expand Up @@ -97,7 +95,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
Expand Down
Loading