Merge branch 'feat/safe-mode-quickjs' of github.com:usebruno/bruno into feat/safe-mode-quickjs

This commit is contained in:
Anoop M D
2024-08-19 11:36:51 +05:30
3 changed files with 12 additions and 10 deletions

View File

@@ -104,6 +104,7 @@ class TestRuntime {
log: customLogger('log'),
info: customLogger('info'),
warn: customLogger('warn'),
debug: customLogger('debug'),
error: customLogger('error')
};
}

View File

@@ -55,10 +55,7 @@ const executeQuickJsVm = ({ script: externalScript, context: externalContext, sc
}
};
const executeQuickJsVmAsync = async ({
script: externalScript,
context: externalContext
}) => {
const executeQuickJsVmAsync = async ({ script: externalScript, context: externalContext }) => {
if (!isNaN(Number(externalScript))) {
return toNumber(externalScript);
}
@@ -96,12 +93,14 @@ const executeQuickJsVmAsync = async ({
fn.apply();
}
await sleep(0);
console?.debug?.('quick-js:execution-start:');
try {
${externalScript}
}
catch(error) {
console?.debug && console.debug('quick-js:execution-end:with-error', error?.message);
console?.debug?.('quick-js:execution-end:with-error', error?.message);
}
console?.debug?.('quick-js:execution-end:');
return 'done';
})()
`;

View File

@@ -1,29 +1,31 @@
const addConsoleShimToContext = (vm, console) => {
if (!console) return;
const consoleHandle = vm.newObject();
const logHandle = vm.newFunction('log', (...args) => {
const nativeArgs = args.map(vm.dump);
console?.log && console.log(...nativeArgs);
console?.log?.(...nativeArgs);
});
const debugHandle = vm.newFunction('debug', (...args) => {
const nativeArgs = args.map(vm.dump);
console?.debug && console.debug(...nativeArgs);
console?.debug?.(...nativeArgs);
});
const infoHandle = vm.newFunction('info', (...args) => {
const nativeArgs = args.map(vm.dump);
console?.info && console.info(...nativeArgs);
console?.info?.(...nativeArgs);
});
const warnHandle = vm.newFunction('warn', (...args) => {
const nativeArgs = args.map(vm.dump);
console?.warn && console.warn(...nativeArgs);
console?.warn?.(...nativeArgs);
});
const errorHandle = vm.newFunction('error', (...args) => {
const nativeArgs = args.map(vm.dump);
console?.error && console.error(...nativeArgs);
console?.error?.(...nativeArgs);
});
vm.setProp(consoleHandle, 'log', logHandle);