我正在使用直接Web Remoting (DWR) JavaScript库文件,只在Safari(桌面和iPad)中得到一个错误

它说

超过最大调用堆栈大小。

这个错误到底是什么意思,它是否完全停止处理?

Safari浏览器也有任何修复(实际上是在iPad Safari上,它说

JS:执行超时

我认为这是相同的调用堆栈问题)


当前回答

如果您正在使用谷歌地图,那么检查lat lng是否被传递到新的google.maps. latlng是正确的格式。在我的例子中,它们被传递为未定义的。

其他回答

在你的代码中有一个递归循环(例如,一个函数最终会一次又一次地调用自己,直到堆栈满为止)。

其他浏览器要么有更大的堆栈(所以您会得到一个超时),要么因为某种原因(可能是放置错误的try-catch)而忽略错误。

发生错误时,使用调试器检查调用堆栈。

有时是因为转换数据类型,例如你有一个对象,你认为是字符串。

套接字。以nodejs客户端的Id为例,它不是一个字符串。要将它作为字符串使用,你必须在前面添加单词string:

String(socket.id);

这也会导致最大调用堆栈大小超过错误:

var items = [];
[].push.apply(items, new Array(1000000)); //Bad

我也一样:

items.push(...new Array(1000000)); //Bad

来自Mozilla文档:

But beware: in using apply this way, you run the risk of exceeding the JavaScript engine's argument length limit. 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. Some engines will throw an exception. More perniciously, others will arbitrarily limit the number of arguments actually passed to the applied function. To illustrate this latter case: if such an engine had a limit of four arguments (actual limits are of course significantly higher), it would be as if the arguments 5, 6, 2, 3 had been passed to apply in the examples above, rather than the full array.

所以尝试:

var items = [];
var newItems = new Array(1000000);
for(var i = 0; i < newItems.length; i++){
  items.push(newItems[i]);
}

发送输入元素而不是它们的值很可能会像FK提到的那样解决它

你可以在crome浏览器中找到你的递归函数,按ctrl+shift+j,然后source选项卡,它会给你代码编译流程,你可以在代码中使用断点。