js/src/jit-test/tests/basic/shapelessCalleeTest.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // The following functions use a delay line of length 2 to change the value
michael@0 2 // of the callee without exiting the traced loop. This is obviously tuned to
michael@0 3 // match the current 8 setting of 2.
michael@0 4 function shapelessArgCalleeLoop(f, g, h, a)
michael@0 5 {
michael@0 6 for (var i = 0; i < 10; i++) {
michael@0 7 f(i, a);
michael@0 8 f = g;
michael@0 9 g = h;
michael@0 10 }
michael@0 11 }
michael@0 12
michael@0 13 function shapelessVarCalleeLoop(f0, g, h, a)
michael@0 14 {
michael@0 15 var f = f0;
michael@0 16 for (var i = 0; i < 10; i++) {
michael@0 17 f(i, a);
michael@0 18 f = g;
michael@0 19 g = h;
michael@0 20 }
michael@0 21 }
michael@0 22
michael@0 23 function shapelessLetCalleeLoop(f0, g, h, a)
michael@0 24 {
michael@0 25 for (var i = 0; i < 10; i++) {
michael@0 26 let f = f0;
michael@0 27 f(i, a);
michael@0 28 f = g;
michael@0 29 g = h;
michael@0 30 }
michael@0 31 }
michael@0 32
michael@0 33 function shapelessUnknownCalleeLoop(n, f, g, h, a)
michael@0 34 {
michael@0 35 for (var i = 0; i < 10; i++) {
michael@0 36 (n || f)(i, a);
michael@0 37 f = g;
michael@0 38 g = h;
michael@0 39 }
michael@0 40 }
michael@0 41
michael@0 42 function shapelessCalleeTest()
michael@0 43 {
michael@0 44 var a = [];
michael@0 45
michael@0 46 var helper = function (i, a) a[i] = i;
michael@0 47 shapelessArgCalleeLoop(helper, helper, function (i, a) a[i] = -i, a);
michael@0 48
michael@0 49 helper = function (i, a) a[10 + i] = i;
michael@0 50 shapelessVarCalleeLoop(helper, helper, function (i, a) a[10 + i] = -i, a);
michael@0 51
michael@0 52 helper = function (i, a) a[20 + i] = i;
michael@0 53 shapelessLetCalleeLoop(helper, helper, function (i, a) a[20 + i] = -i, a);
michael@0 54
michael@0 55 helper = function (i, a) a[30 + i] = i;
michael@0 56 shapelessUnknownCalleeLoop(null, helper, helper, function (i, a) a[30 + i] = -i, a);
michael@0 57
michael@0 58 try {
michael@0 59 helper = {hack: 42};
michael@0 60 shapelessUnknownCalleeLoop(null, helper, helper, helper, a);
michael@0 61 } catch (e) {
michael@0 62 if (e + "" != "TypeError: f is not a function")
michael@0 63 print("shapelessUnknownCalleeLoop: unexpected exception " + e);
michael@0 64 }
michael@0 65 return a.join("");
michael@0 66 }
michael@0 67 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");

mercurial