Monday, September 26, 2011

Firefox fails on nested closures at 16 layers

How deep do you think you can nest your closures in JavaScript? Yes, we know there is no tail-recursion, probably no inlining either, we know we should not do this, but sometimes we still do. Before today I expected something like 64-128 levels of nesting to work out fine. In fact, Chrome chokes only at level 512 or so, due to stack overflow - fine.

EDIT: There is Bug #517781 reported 2009-09-20, and STILL NOT ADDRESSED. Please upvote it if you can.

But Firefox.. At level 16! Reference error: x16 is not defined

/// generated JavaScript for k=16
function bind(x,f) {return f(x)}
function test(x0) {
var k0;
k0 = function (x1) {
var k1;
k1 = function (x2) {
var k2;
k2 = function (x3) {
var k3;
k3 = function (x4) {
var k4;
k4 = function (x5) {
var k5;
k5 = function (x6) {
var k6;
k6 = function (x7) {
var k7;
k7 = function (x8) {
var k8;
k8 = function (x9) {
var k9;
k9 = function (x10) {
var k10;
k10 = function (x11) {
var k11;
k11 = function (x12) {
var k12;
k12 = function (x13) {
var k13;
k13 = function (x14) {
var k14;
k14 = function (x15) {
var k15;
k15 = function (x16) {
var k16;
k16 = function (x17) {
return x16 + 1;
};
return bind(x16,k16)
};
return bind(x15,k15)
};
return bind(x14,k14)
};
return bind(x13,k13)
};
return bind(x12,k12)
};
return bind(x11,k11)
};
return bind(x10,k10)
};
return bind(x9,k9)
};
return bind(x8,k8)
};
return bind(x7,k7)
};
return bind(x6,k6)
};
return bind(x5,k5)
};
return bind(x4,k4)
};
return bind(x3,k3)
};
return bind(x2,k2)
};
return bind(x1,k1)
};
return bind(x0,k0)
}
view raw generated.js hosted with ❤ by GitHub


This is on 6.0.2. Shame.

No comments:

Post a Comment