diff options
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/execute_js_code.js | 6 | ||||
| -rw-r--r-- | tools/execute_py_code.py | 2 |
2 files changed, 6 insertions, 2 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); } diff --git a/tools/execute_py_code.py b/tools/execute_py_code.py index a774e82..3c6beb4 100644 --- a/tools/execute_py_code.py +++ b/tools/execute_py_code.py @@ -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)
\ No newline at end of file |
