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

它说

超过最大调用堆栈大小。

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

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

JS:执行超时

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


当前回答

对于我这个TypeScript初学者来说,这是_var1的getter和setter的问题。

class Point2{
    
    constructor(private _var1?: number, private y?: number){}

    set var1(num: number){
        this._var1 = num  // problem was here, it was this.var1 = num
    }
    get var1(){
        return this._var1 // this was return this.var1
    }
}

其他回答

以下相同代码的调用如果减少1,在我的计算机上的Chrome 32中工作,例如17905 vs 17904。如果按原样运行,它们将产生错误“RangeError:最大调用堆栈大小超出”。这个限制似乎不是硬编码的,而是取决于您机器的硬件。如果作为函数调用,这种自我施加的限制似乎比作为方法调用要高,也就是说,当作为函数调用时,这个特定的代码使用更少的内存。

作为方法调用:

var ninja = {
    chirp: function(n) {
        return n > 1 ? ninja.chirp(n-1) + "-chirp" : "chirp";
    }
};

ninja.chirp(17905);

作为函数调用:

function chirp(n) {
    return n > 1 ? chirp( n - 1 ) + "-chirp" : "chirp";
}

chirp(20889);

检查Chrome dev工具栏控制台中的错误细节,这将为您提供调用堆栈中的函数,并指导您找到导致错误的递归。

我在express/nodejs应用程序中得到了这个错误,当MongoDB数据库的模式和我们创建的模型不匹配时。

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

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

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