felixhao28 / JSCPP

A simple C++ interpreter written in JavaScript

Home Page:https://felixhao28.github.io/JSCPP/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

empty while loop cause debugger to

billcollis opened this issue · comments

in the following code if the while loop is empty the debugger goes into a loop and cannot be stopped,
I know its not really a big issue but students writing this in their code while learning will find it hangs their browser, if there is anything in the while loop it wont of course hang up

`#include
using namespace std;
int main() {
int a=0;
while(1){

}

}`

I can think of two solutions:

  1. Implement a time limit on program execution. This should be pretty easy to do and not that performance impacting. However, a reasonable timeout (like 1 second) is still long enough for user to experience a moment of freeze on the browser, since the JS engine and UI event handling are usually on one thread.
  2. Put JSCPP in a web worker. This is slower both in terms of executing and loading, but you will have full control over the JSCPP engine. You can abort the worker anytime you want without causing freeze. I haven't tried this yet so I don't have any example code for you.

If you prefer the previous one, I will see how I can add a time limit. Otherwise I am happy to share your web worker solution in the readme file.

I don't think I would want to slow the execution down at all, and this is for only rare occasions. So a small freeze time would ok as it would not be that noticeable.
As a temporary fix for the moment in my environment I insert a dummy line of code between empty {}