aboutsummaryrefslogtreecommitdiffstats
path: root/tools/execute_js_code.js
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2024-10-23 17:22:11 +0800
committerGitHub <noreply@github.com>2024-10-23 17:22:11 +0800
commitfbeaa9cb2c5b7a8e0d9114a62c270c6fe8024c31 (patch)
treec25b91f61ec2816b4425decedfd451967a003f49 /tools/execute_js_code.js
parentd499954dbbfd9e4d9911d179092385ac0d161e56 (diff)
downloadllm-functions-docker-fbeaa9cb2c5b7a8e0d9114a62c270c6fe8024c31.tar.gz
feat: improve execute js/py code and collect results (#117)
Diffstat (limited to 'tools/execute_js_code.js')
-rw-r--r--tools/execute_js_code.js6
1 files changed, 5 insertions, 1 deletions
diff --git a/tools/execute_js_code.js b/tools/execute_js_code.js
index 853ccab..6bad67a 100644
--- a/tools/execute_js_code.js
+++ b/tools/execute_js_code.js
@@ -1,3 +1,5 @@
+const vm = require('vm');
+
/**
* Execute the javascript code in node.js.
* @typedef {Object} Args
@@ -5,5 +7,7 @@
* @param {Args} args
*/
exports.run = function run({ code }) {
- return eval(code);
+ const context = vm.createContext({});
+ const script = new vm.Script(code);
+ return script.runInContext(context);
}