tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

shapelessCalleeTest.js (1656B)


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