Cancel infinite loop execution in jsfiddle

前端 未结 8 1989
北荒
北荒 2020-12-13 08:46

When you get an infinite loop in jsfiddle in Chrome, your only choice (that I know of) is to close the tab. Of course, this means you lose all your work in the current wind

8条回答
  •  一向
    一向 (楼主)
    2020-12-13 09:12

    One way of breaking the infinite loop is to throw an unhandled exception, which will stop the execution of current call stack. To do so:

    1. pause the debbuger
    2. find a promising statement inside the loop, for example a function call: foo.bar(args)
    3. in console, overwrite the function to throw : foo.bar=function(){throw 42;}
    4. unpause the debugger

    worked for me. I haven't tried, but I believe that by overloading getter or setter you can use the trick described above also for assignments and reads, not only for function calls. Also, by setting a variable to undefined, you may cause fatal error (and thus break the loop) if the field of this variable is used in the loop. For example delete foo.tab will break foo.tab[42] or foo.tab.bar. For some reason, simply writting foo=undefined in the console, will not do (perhaps it defines a variable local to the console window named foo).

提交回复
热议问题