I'm using Ace Editor in a project, and I was wondering on how to run the code the user inputs into the editor. I was thinking I could use something like this:
var editor = ace.edit("editor");
editor.setTheme("ace/theme/chaos");
editor.session.setMode("ace/mode/javascript");
function runProgram() {
var code = editor.getValue();
var display = document.getElementById("display");
try {
var result = eval(code);
display.innerHTML = result;
} catch(e) {
alert('Error' + e);
}
}
But I'm not sure about using eval() due to security. I was hoping to find some way to safely execute and display the users code. Please note that I'm a beginner in javascript.