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

它说

超过最大调用堆栈大小。

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

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

JS:执行超时

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


当前回答

在Angular中,如果你使用mat-select并且有400多个选项,可能会出现这个错误 https://github.com/angular/components/issues/12504

你必须更新@angular/material版本

其他回答

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

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

遇到同样的问题,不知道怎么回事,开始责怪巴别塔;)

在浏览器中不返回任何异常的代码:

if (typeof document.body.onpointerdown !== ('undefined' || null)) {

问题是严重创建||(或)部分Babel创建自己的类型检查:

function _typeof(obj){if(typeof Symbol==="function"&&_typeof(Symbol.iterator)==="symbol")

所以删除

|| null

让巴别塔翻译起作用了。

我知道这个帖子很旧了,但我认为值得一提的是我发现这个问题的场景,所以它可以帮助其他人。

假设你有这样的嵌套元素:

<a href="#" id="profile-avatar-picker">
    <span class="fa fa-camera fa-2x"></span>
    <input id="avatar-file" name="avatar-file" type="file" style="display: none;" />
</a>

您不能在其父元素的事件内操作子元素事件,因为它会传播到自身,进行递归调用,直到抛出异常。

所以这段代码会失败:

$('#profile-avatar-picker').on('click', (e) => {
    e.preventDefault();

    $('#profilePictureFile').trigger("click");
});

你有两个选择来避免这种情况:

将子对象移动到父对象的外部。 将stopPropagation函数应用于子元素。

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

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

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

我们最近添加了一个字段的管理网站,我们正在工作- contact_type…简单的对吧?好吧,如果你调用select“type”,并试图通过jquery ajax调用发送它,它会失败,这个错误深埋在jquery.js中。

$.ajax({
    dataType: "json",
    type: "POST",
    url: "/some_function.php",
    data: { contact_uid:contact_uid, type:type }
});

问题是,type:type -我相信是我们将参数命名为“type”-有一个名为type的值变量不是问题。我们将其更改为:

$.ajax({
    dataType: "json",
    type: "POST",
    url: "/some_function.php",
    data: { contact_uid:contact_uid, contact_type:type }
});

并相应地重写了some_function.php——问题解决了。