Javascript Browser Stack Size Limit

I get some stack overflow problems on the client side Javascript, especially in the IE browser, this happens inside a third-party library that calls some function calls, and for some reason they trade in IE from time to time only because of the low limit stack.

Then I coded a little test HTML to check the stack size limit for some browsers and found that IE8 has a minimal stack limit compared to FF 7 or Chrome 14, which runs on a Windows 7 laptop, with 8 GB RAM:

<html> <body> <!-- begin Script: --> <script type="text/javascript"> function doSomething(){ var i = 3200; doSomethingElse(i); } function doSomethingElse(i){ if (i == 0) return -1; doSomethingElse(i-1); } doSomething(); </script> <!-- END OF PAGE --> </body> </html> 

IE increases stack overflow at around 3200, Firefox and Chrome can handle very deep recursion compared to IE.

I would like to know if there is a way to associate the exception with a Javascript function that raised it at runtime in IE or in any other browser, and if it could give stacktrace with a chain of functions on the stack at the time of the error.

+50
javascript stack browser limit
Oct 19 '11 at 19:29
source share
2 answers

Using a simple test :

 var i=0; function inc() { i++; inc(); } inc(); 

Internet explorer

  • IE6: 1130
  • IE7: 2553
  • IE8: 1475
  • IE9: 20678
  • IE10: 20677

Mozilla firefox

  • 3.6: 3000
  • 4.0: 9015
  • 5.0: 9015
  • 6.0: 9015
  • 7.0: 65533
  • 8b3: 63485
  • 17: 50762
  • 18: 52596
  • 19: 52458
  • 42: 281810

Google chrome

  • 14: 26177
  • 15: 26168
  • 16: 26166
  • 25: 25090
  • 47: 20878
  • 51: 41753

Safari

  • 4: 52426
  • 5: 65534
  • 9: 63444

Opera

  • 10.10: 9999
  • 10.62: 32631
  • 11: 32631
  • 12: 32631



For your question, use the browser developer tools to see the stack. In IE 8+, press F12 , go to the Script tab and click on "Start Debugging". It will be broken when an exception is thrown and you will see a call stack. You can also use the Chrome developer tools, Ctrl + Shift + J.

+87
Oct 19 '11 at
source share

This is a specific browser, not only the size of the stack, but also optimization, such as tail recursion optimization and more. I think the only reliable thing here is to encode in such a way as not to push tons of material onto the stack or manual testing (reading in documents) of each browser. After all, when you see a "too much recursion" error or something similar, you already know that something is really wrong with your code.

+5
Oct 19 '11 at 19:35
source share



All Articles