JS Bin's loop protection implementation.
Note that this does not solve the halting problem but simply rewrites JavaScript (without an AST) wrapping loops with a conditional break.
With loop protection in place, it means that a user can enter the code as follows on JS Bin, and the final console.log
will still work.
while (true) {
doSomething();
}
console.log('All finished');
The loop protection can be used both on the client side and server side. It supports AMD and CommonJS module loading, or can be included as vanilla JavaScript (as it is in JS Bin).
- loopProtect.method
- loopProtect.hit