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.

     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 }
    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 }
    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 }
    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 }
    42 function shapelessCalleeTest()
    43 {
    44   var a = [];
    46   var helper = function (i, a) a[i] = i;
    47   shapelessArgCalleeLoop(helper, helper, function (i, a) a[i] = -i, a);
    49   helper = function (i, a) a[10 + i] = i;
    50   shapelessVarCalleeLoop(helper, helper, function (i, a) a[10 + i] = -i, a);
    52   helper = function (i, a) a[20 + i] = i;
    53   shapelessLetCalleeLoop(helper, helper, function (i, a) a[20 + i] = -i, a);
    55   helper = function (i, a) a[30 + i] = i;
    56   shapelessUnknownCalleeLoop(null, helper, helper, function (i, a) a[30 + i] = -i, a);
    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");

mercurial