mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-24 13:15:40 +00:00
Merge branch 'feat/safe-mode-quickjs' of github.com:usebruno/bruno into feat/safe-mode-quickjs
This commit is contained in:
@@ -104,6 +104,7 @@ class TestRuntime {
|
||||
log: customLogger('log'),
|
||||
info: customLogger('info'),
|
||||
warn: customLogger('warn'),
|
||||
debug: customLogger('debug'),
|
||||
error: customLogger('error')
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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';
|
||||
})()
|
||||
`;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user