Skip to main content

Javascript and infinite recursion

 What happens if there is a stack overflow? But we all fondly ask what (disaster) would have happened if there was no stackoverflow?

 

But I am talking about actual stack overflow happening. When a recursive function goes into an infinite recursion? We all have seen such code and been wiser after them. But I wasn't ready for this disaster when there was a infinite recursion in a javascript. Was there a stack overflow? Was there a memory error? I really could not tell because.... Because the browser stopped working, the mouse stopped working. I was unable to start a terminal to kill the browser. I was not even able to switch terminals using ctrl alt f3 f4 etc.

After switching off the computer - using the power button for nth time, I suspected malfunction by HTML editor. Checked its desktop file. Checked the type of executable - is it some kind of rogue script? No it wasn't. It was the normal ELF file. I checked the config directories. I even checked system logs. Could not find the culprit.

As a last resort I used toast - or its equivalent in Javascript - alert command. I displayed the variable using alert command. There it was there was a double recursion. 


 

So, dear javascript and/or firefox, if there is such an error, you are supposed to crash the program with error message - like Firefox has stopped working. You are not supposed to crash the system.

Another unique twist of javascript I experienced today was if there is a division by zero, there will not be arithmetic exception. Instead, answer is shown as Infinity - not even Nan. Wonderful!! 

(But on the other hand I need to fix that code. )


Comments