mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-08 14:35:03 +00:00
refactor: remove unnecessary parameters and comments in QuickJS VM execution
This commit is contained in:
@@ -158,8 +158,7 @@ class HooksRuntime {
|
|||||||
const result = await executeQuickJsVmAsync({
|
const result = await executeQuickJsVmAsync({
|
||||||
script: hooksFile,
|
script: hooksFile,
|
||||||
context: context,
|
context: context,
|
||||||
collectionPath,
|
collectionPath
|
||||||
persistVm: true // Keep VM alive for hook handler calls
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Register VM cleanup with HookManager so it's disposed when HookManager.dispose() is called
|
// Register VM cleanup with HookManager so it's disposed when HookManager.dispose() is called
|
||||||
|
|||||||
@@ -89,17 +89,6 @@ const executeQuickJsVm = ({ script: externalScript, context: externalContext, sc
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute a script asynchronously in a QuickJS VM
|
|
||||||
* @param {Object} options - Execution options
|
|
||||||
* @param {string} options.script - The script to execute
|
|
||||||
* @param {Object} options.context - Context object with bru, req, res, etc.
|
|
||||||
* @param {string} options.collectionPath - Path to the collection
|
|
||||||
* @param {boolean} options.persistVm - If true, VM persists and cleanup function is returned.
|
|
||||||
* Used for hooks that need to be called later.
|
|
||||||
* If false (default), VM is disposed immediately.
|
|
||||||
* @returns {Promise<Object|undefined>} Returns { cleanup } if persistVm=true, undefined otherwise
|
|
||||||
*/
|
|
||||||
const executeQuickJsVmAsync = async ({ script: externalScript, context: externalContext, collectionPath }) => {
|
const executeQuickJsVmAsync = async ({ script: externalScript, context: externalContext, collectionPath }) => {
|
||||||
if (!externalScript?.length || typeof externalScript !== 'string') {
|
if (!externalScript?.length || typeof externalScript !== 'string') {
|
||||||
return externalScript;
|
return externalScript;
|
||||||
@@ -107,7 +96,6 @@ const executeQuickJsVmAsync = async ({ script: externalScript, context: external
|
|||||||
externalScript = externalScript?.trim();
|
externalScript = externalScript?.trim();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Create new WASM module each time (no memoization)
|
|
||||||
const module = await newQuickJSWASMModule();
|
const module = await newQuickJSWASMModule();
|
||||||
const vm = module.newContext();
|
const vm = module.newContext();
|
||||||
|
|
||||||
@@ -193,6 +181,7 @@ const executeQuickJsVmAsync = async ({ script: externalScript, context: external
|
|||||||
promiseHandle.dispose();
|
promiseHandle.dispose();
|
||||||
const resolvedHandle = vm.unwrapResult(resolvedResult);
|
const resolvedHandle = vm.unwrapResult(resolvedResult);
|
||||||
resolvedHandle.dispose();
|
resolvedHandle.dispose();
|
||||||
|
// vm.dispose();
|
||||||
return;
|
return;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error executing the script!', error);
|
console.error('Error executing the script!', error);
|
||||||
|
|||||||
Reference in New Issue
Block a user