Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
190 views
in Technique[技术] by (71.8m points)

Browser Javascript Stack size limit

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.

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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');
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...