1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/jit-test/tests/basic/shapelessCalleeTest.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,67 @@ 1.4 +// The following functions use a delay line of length 2 to change the value 1.5 +// of the callee without exiting the traced loop. This is obviously tuned to 1.6 +// match the current 8 setting of 2. 1.7 +function shapelessArgCalleeLoop(f, g, h, a) 1.8 +{ 1.9 + for (var i = 0; i < 10; i++) { 1.10 + f(i, a); 1.11 + f = g; 1.12 + g = h; 1.13 + } 1.14 +} 1.15 + 1.16 +function shapelessVarCalleeLoop(f0, g, h, a) 1.17 +{ 1.18 + var f = f0; 1.19 + for (var i = 0; i < 10; i++) { 1.20 + f(i, a); 1.21 + f = g; 1.22 + g = h; 1.23 + } 1.24 +} 1.25 + 1.26 +function shapelessLetCalleeLoop(f0, g, h, a) 1.27 +{ 1.28 + for (var i = 0; i < 10; i++) { 1.29 + let f = f0; 1.30 + f(i, a); 1.31 + f = g; 1.32 + g = h; 1.33 + } 1.34 +} 1.35 + 1.36 +function shapelessUnknownCalleeLoop(n, f, g, h, a) 1.37 +{ 1.38 + for (var i = 0; i < 10; i++) { 1.39 + (n || f)(i, a); 1.40 + f = g; 1.41 + g = h; 1.42 + } 1.43 +} 1.44 + 1.45 +function shapelessCalleeTest() 1.46 +{ 1.47 + var a = []; 1.48 + 1.49 + var helper = function (i, a) a[i] = i; 1.50 + shapelessArgCalleeLoop(helper, helper, function (i, a) a[i] = -i, a); 1.51 + 1.52 + helper = function (i, a) a[10 + i] = i; 1.53 + shapelessVarCalleeLoop(helper, helper, function (i, a) a[10 + i] = -i, a); 1.54 + 1.55 + helper = function (i, a) a[20 + i] = i; 1.56 + shapelessLetCalleeLoop(helper, helper, function (i, a) a[20 + i] = -i, a); 1.57 + 1.58 + helper = function (i, a) a[30 + i] = i; 1.59 + shapelessUnknownCalleeLoop(null, helper, helper, function (i, a) a[30 + i] = -i, a); 1.60 + 1.61 + try { 1.62 + helper = {hack: 42}; 1.63 + shapelessUnknownCalleeLoop(null, helper, helper, helper, a); 1.64 + } catch (e) { 1.65 + if (e + "" != "TypeError: f is not a function") 1.66 + print("shapelessUnknownCalleeLoop: unexpected exception " + e); 1.67 + } 1.68 + return a.join(""); 1.69 +} 1.70 +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");