From 4aff61b665759bc4cd1f77b544ec2d8fad74afd8 Mon Sep 17 00:00:00 2001 From: lohit Date: Thu, 22 Aug 2024 10:10:15 +0530 Subject: [PATCH] fix: getRequestVar shim, boolean values in vm (#2887) --- packages/bruno-js/src/sandbox/quickjs/shims/bru.js | 6 ++++++ packages/bruno-js/src/sandbox/quickjs/utils/index.js | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/bruno-js/src/sandbox/quickjs/shims/bru.js b/packages/bruno-js/src/sandbox/quickjs/shims/bru.js index 5b1063404..ced639893 100644 --- a/packages/bruno-js/src/sandbox/quickjs/shims/bru.js +++ b/packages/bruno-js/src/sandbox/quickjs/shims/bru.js @@ -63,6 +63,12 @@ const addBruShimToContext = (vm, bru) => { vm.setProp(bruObject, 'getSecretVar', getSecretVar); getSecretVar.dispose(); + let getRequestVar = vm.newFunction('getRequestVar', function (key) { + return marshallToVm(bru.getRequestVar(vm.dump(key)), vm); + }); + vm.setProp(bruObject, 'getRequestVar', getRequestVar); + getRequestVar.dispose(); + const sleep = vm.newFunction('sleep', (timer) => { const t = vm.getString(timer); const promise = vm.newPromise(); diff --git a/packages/bruno-js/src/sandbox/quickjs/utils/index.js b/packages/bruno-js/src/sandbox/quickjs/utils/index.js index ccbd85d82..e376c3252 100644 --- a/packages/bruno-js/src/sandbox/quickjs/utils/index.js +++ b/packages/bruno-js/src/sandbox/quickjs/utils/index.js @@ -10,7 +10,7 @@ const marshallToVm = (value, vm) => { } else if (typeof value === 'number') { return vm.newNumber(value); } else if (typeof value === 'boolean') { - return vm.newBoolean(value); + return value ? vm.true : vm.false; } else if (typeof value === 'object') { if (Array.isArray(value)) { const arr = vm.newArray();