feat: improve execute js/py code and collect results (#117)

This commit is contained in:
sigoden
2024-10-23 17:22:11 +08:00
committed by GitHub
parent d499954dbb
commit fbeaa9cb2c
6 changed files with 14 additions and 18 deletions
+5 -1
View File
@@ -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);
}
+1 -1
View File
@@ -3,4 +3,4 @@ def run(code: str):
Args:
code: Python code to execute, such as `print("hello world")`
"""
return exec(code)
return eval(code)