Hi prashant,
As far as I know there's no simple way to do this with eval, but luckily there is still a solution! You're going to want to take a look at the
JS Interpreter.
So what you're going to do will depend a bit on whether you want to /stop/ execution or /pause/ execution.
1. Run the code on a timeout, either like
this where it runs each "step" on a timeout, or like
this where it waits until it hits an async call within the code (
demo), and then waits for a timeout.
2a. If you want to simply /stop/ the code execution (so if someone were to hit play again it would start from the beginning) I believe all you need to do is
reset the interpreter and it should stop.
2b. If you want to /pause/ the code execution (if someone were to hit play again it would start from where it was paused) you'll need to reset &
serialize/deserialize the interpreter (
demo,
docs).
This is a good reference for doing the asyncronous execution (
demo).
It can be tricky, but the interpreter is really cool once you get it set up!
Beka