How do I safely “eval” user code in a webpage?
问题 I'm working on a webapp to teach programming concepts. Webpages have some text about a programming concept, then let the user type in javascript code into a text editor window to try to answer a programming problem. When the user clicks "submit", I analyse the text they've typed to see if they have solved the problem. For example, I ask them to "write a function named f that adds three to its argument". Here's what I'm doing to analyse the user's text: Run JSLint on the text with strict