I am writing a language for educational purpose, which should run in web browsers. The language compiles to JavaScript.
So there is the problem of endless loops and recursion. Until that moment I thought the solution would be to have the runtime implemented as a WebWorker and a button on the ui, to terminate it if it runs to long.
I just found out, while testing my language, that the web worker isn't really terminated, by calling : runtime.terminate()
;
At least not until his last job has finished, i haven't tested what happens if it would be finished. Even in the documentation I found so far, its stated that it stops execution immediately.
So even if the user can continue working that way, the running worker in the background can use up resources and lead to at least a not responding browser.
So I need any way to terminate the execution in case of an endless loop or recursion, in response to a user event. As I din't find any way to put a thread to sleep in JavaScript, this doesn't work either, or is there something like sleep for web workers?
Have you got any suggestions what I could do?