How can I protect against while (true) loops in javascript?

I am working on teaching children programming in Javascript using a combination of an online and a standalone environment.

At some stage, most children are faced with a time when they create an endless cycle. In the past days. an infinite loop is expected to be a child of the first program with

10 PRINT "Mike is cool"
20 GOTO 10

Writing something like this in JavaScript is problematic

while(true) {
   print("Mike is cool");
}

It doesn’t work due to the synchronization of JavaScript and something that they will have to learn. The problem is not that their program does not work as expected, but when they launch their program, the whole world stops!

Some browsers have enough control to close the window, and some have Lock. If you use the environment in the browser (for example, jsfiddle, jsbin, etc.), you do not have enough control to stop the "task" of the rogue

You cannot pre-check the code (this is literally a stopping problem), but is there any reasonable way to alleviate the symptoms?

The software environment at Khan Academy seems to achieve this.

http://www.khanacademy.org/cs/breaking/480495199898988288

What does he do to handle excessive runtime? How can this be done while time is still running?

+4
source share
1 answer

-, -, -. -.

Web - HTML5, . -, , Chrome Safari. - :

http://www.html5rocks.com/en/tutorials/workers/basics/

0

Source: https://habr.com/ru/post/1532388/


All Articles