001-drive-proxy-adapter #1
@@ -89,12 +89,13 @@ function loadGlobalVariableFunctions() {
|
|||||||
const code = readFileSync(filePath, "utf-8");
|
const code = readFileSync(filePath, "utf-8");
|
||||||
const script = new vm.Script(code, { filename: file });
|
const script = new vm.Script(code, { filename: file });
|
||||||
|
|
||||||
// Execute in context with crypto and console
|
// Execute in context with all VM globals and previously loaded variables
|
||||||
// Expects file to return an object via IIFE
|
// Allows function modules to access same dependencies as proxy.js
|
||||||
const tempContext = vm.createContext({
|
const tempContext = vm.createContext({
|
||||||
crypto,
|
...globalVMContext,
|
||||||
console: logger,
|
...globalVariableContext,
|
||||||
});
|
});
|
||||||
|
|
||||||
const exportedObject = script.runInContext(tempContext);
|
const exportedObject = script.runInContext(tempContext);
|
||||||
|
|
||||||
globalVariableContext[functionName] = exportedObject;
|
globalVariableContext[functionName] = exportedObject;
|
||||||
|
|||||||
Reference in New Issue
Block a user