I am getting some client-side Javascript stack overflow issues specifically in IE browser, this is happening inside a third party library that makes some function calls and for some reason they occasionally brake in IE only due to it's low stack limit.
I then coded a small test HTML to test the stack size limit for some browsers and found that IE8 has actually a small stack limit if compared to FF 7 or Chrome 14 running on a Laptop with Windows 7 OS, 8Gb 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 raises stack overflow when the values are around 3200, Firefox and Chrome can handle a very deep recursion if compared to IE.
I would like to know if there's a way to tie the stack-overflow exception with the Javascript function that raised it during runtime in IE or any other browser and if it could give the stacktrace with the chain of function in the stack at the moment the error was raised.
The consequences of applying a function with too many arguments (think more than tens of thousands of arguments) vary across engines (JavaScriptCore has hard-coded argument limit of 65536), because the limit (indeed even the nature of any excessively-large-stack behavior) is unspecified.
The stack size limit is the maximum size of the stack for a process, in units of 1024 bytes. The stack is a per-thread resource that has unlimited hard and soft limits.
The call stack is limited in size, and when it's exceeded, the RangeError is thrown. This can happen when a deeply nested function is called, or when a lot of new variables are created. The most common way to fix this error is to reduce the number of function calls, or to limit the number of variables that are created.
The "RangeError: Maximum call stack size exceeded" error occurs when a function is called so many times that the invocations exceed the call stack limit. To solve the error, specify a base case that has to be met to exit the recursion.
Using a simple test:
var i = 0; function inc() { i++; inc(); } try { inc(); } catch(e) { // The StackOverflow sandbox adds one frame that is not being counted by this code // Incrementing once manually i++; console.log('Maximum stack size is', i, 'in your current browser'); }
In regard to your question, use your browser's developer tools to see the stack. In IE 8+, hit F12, go to the Script tab, and click Start Debugging. It will break when an exception is thrown, and you can see the call stack. You can also use Chrome's developer tools, Ctrl+Shift+J.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With