浏览器 Javascript 堆栈大小限制 [英] Browser Javascript Stack size limit

查看:66
本文介绍了浏览器 Javascript 堆栈大小限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 IE 浏览器中遇到了一些客户端 Javascript 堆栈溢出问题,这发生在第三方库中,该库进行一些函数调用,出于某种原因,它们偶尔会在 IE 中刹车,只是因为它的堆栈限制较低.

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.

然后我编写了一个小型测试 HTML 来测试某些浏览器的堆栈大小限制,发现与在装有 Windows 7 操作系统、8Gb RAM 的笔记本电脑上运行的 FF 7 或 Chrome 14 相比,IE8 实际上具有较小的堆栈限制:

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 在 3200 左右时引发堆栈溢出,与 IE 相比,Firefox 和 Chrome 可以处理非常深的递归.

IE raises stack overflow when the values are around 3200, Firefox and Chrome can handle a very deep recursion if compared to IE.

我想知道是否有办法将堆栈溢出异常与在 IE 或任何其他浏览器中运行时引发它的 Javascript 函数联系起来,以及它是否可以在堆栈中提供带有函数链的堆栈跟踪出现错误的那一刻.

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.

推荐答案

使用简单的测试:

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

  • IE6:1130
  • IE7:2553
  • IE8:1475
  • IE9:20678
  • IE10:20677
  • 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
  • 89:10746
  • 91:26441
  • 14:26177
  • 15:26168
  • 16:26166
  • 25:25090
  • 47:20878
  • 51:41753
  • 93:13903
  • 4:52426
  • 5:65534
  • 9:63444
  • 14:45606
  • 15:7909
  • 10.10:9999
  • 10.62:32631
  • 11:32631
  • 12:32631
  • 78:13908
  • 87:13970
  • 93:13903
  • 21:13909

关于您的问题,请使用浏览器的开发人员工具查看堆栈.在 IE 8+ 中,点击 F12,转到脚本选项卡,然后单击开始调试.抛出异常就会break,可以看到调用栈.您还可以使用 Chrome 的开发者工具,Ctrl+Shift+J.

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.

这篇关于浏览器 Javascript 堆栈大小限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆