michael@0: // The following functions use a delay line of length 2 to change the value michael@0: // of the callee without exiting the traced loop. This is obviously tuned to michael@0: // match the current 8 setting of 2. michael@0: function shapelessArgCalleeLoop(f, g, h, a) michael@0: { michael@0: for (var i = 0; i < 10; i++) { michael@0: f(i, a); michael@0: f = g; michael@0: g = h; michael@0: } michael@0: } michael@0: michael@0: function shapelessVarCalleeLoop(f0, g, h, a) michael@0: { michael@0: var f = f0; michael@0: for (var i = 0; i < 10; i++) { michael@0: f(i, a); michael@0: f = g; michael@0: g = h; michael@0: } michael@0: } michael@0: michael@0: function shapelessLetCalleeLoop(f0, g, h, a) michael@0: { michael@0: for (var i = 0; i < 10; i++) { michael@0: let f = f0; michael@0: f(i, a); michael@0: f = g; michael@0: g = h; michael@0: } michael@0: } michael@0: michael@0: function shapelessUnknownCalleeLoop(n, f, g, h, a) michael@0: { michael@0: for (var i = 0; i < 10; i++) { michael@0: (n || f)(i, a); michael@0: f = g; michael@0: g = h; michael@0: } michael@0: } michael@0: michael@0: function shapelessCalleeTest() michael@0: { michael@0: var a = []; michael@0: michael@0: var helper = function (i, a) a[i] = i; michael@0: shapelessArgCalleeLoop(helper, helper, function (i, a) a[i] = -i, a); michael@0: michael@0: helper = function (i, a) a[10 + i] = i; michael@0: shapelessVarCalleeLoop(helper, helper, function (i, a) a[10 + i] = -i, a); michael@0: michael@0: helper = function (i, a) a[20 + i] = i; michael@0: shapelessLetCalleeLoop(helper, helper, function (i, a) a[20 + i] = -i, a); michael@0: michael@0: helper = function (i, a) a[30 + i] = i; michael@0: shapelessUnknownCalleeLoop(null, helper, helper, function (i, a) a[30 + i] = -i, a); michael@0: michael@0: try { michael@0: helper = {hack: 42}; michael@0: shapelessUnknownCalleeLoop(null, helper, helper, helper, a); michael@0: } catch (e) { michael@0: if (e + "" != "TypeError: f is not a function") michael@0: print("shapelessUnknownCalleeLoop: unexpected exception " + e); michael@0: } michael@0: return a.join(""); michael@0: } michael@0: assertEq(shapelessCalleeTest(), "01-2-3-4-5-6-7-8-901-2-3-4-5-6-7-8-9012345678901-2-3-4-5-6-7-8-9");