tor-browser

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

entryOverflowBailout.js (6512B)


      1 var o;
      2 var f1;
      3 var counter = 0;
      4 
      5 function f2(a) {
      6    bailout();
      7    return f2.arguments;
      8 };
      9 
     10 var restartCode = "counter = 0; " + f2.toString();
     11 
     12 // We need to reevaluate this function everytime, otherwise it is flagged as
     13 // having an argument object and it would not be re-entered.
     14 
     15 // This test case is checking that f.arguments reflects the overflow or the
     16 // underflow of arguments after a bailout.  Due to the way bailouts are
     17 // recovered we need to check for the intial frame and for any other JS frame
     18 // below.
     19 //
     20 // To produce a JSFrame, we need to avoid the 'Hot' counters of f1 to be the
     21 // same as f2, because IonMonkey will try to inline f2 in f1, and not
     22 // compiling/calling f2 separately. This explain why we ignore the 5 first call
     23 // of f1 by returning immediately.
     24 //
     25 // Bailouts are caused by calling an object function, which is expected to be a
     26 // function by IonMonkey.  So bailout() cause a bailout in the currently
     27 // compiled function.
     28 //
     29 // To avoid any preventive effect to re-enter f2, we re-evaluate it before every
     30 // test.
     31 
     32 // Check bailouts of the initial frame.
     33 
     34 eval(restartCode);
     35 while (counter++ < 50) {
     36    o = f2();
     37    assertEq(o.length, 0);
     38 }
     39 
     40 eval(restartCode);
     41 while (counter++ < 50) {
     42    o = f2(21);
     43    assertEq(o.length, 1);
     44    assertEq(o[0], 21);
     45 }
     46 
     47 eval(restartCode);
     48 while (counter++ < 50) {
     49    o = f2(21,42);
     50    assertEq(o.length, 2);
     51    assertEq(o[0], 21);
     52    assertEq(o[1], 42);
     53 }
     54 
     55 // 100 arguments.
     56 eval(restartCode);
     57 while (counter++ < 50) {
     58    o = f2(0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
     59           0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
     60           0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
     61           0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
     62           0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9);
     63    assertEq(o.length, 100);
     64    for (var i in o)
     65        assertEq(o[i], i % 10);
     66 }
     67 
     68 // 200 arguments.
     69 eval(restartCode);
     70 while (counter++ < 50) {
     71    o = f2(0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
     72           0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
     73           0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
     74           0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
     75           0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
     76 
     77           0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
     78           0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
     79           0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
     80           0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
     81           0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9);
     82    assertEq(o.length, 200);
     83    for (var i in o)
     84        assertEq(o[i], i % 10);
     85 }
     86 
     87 // 300 arguments.
     88 eval(restartCode);
     89 while (counter++ < 50) {
     90    o = f2(0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
     91           0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
     92           0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
     93           0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
     94           0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
     95 
     96           0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
     97           0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
     98           0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
     99           0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
    100           0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
    101 
    102           0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
    103           0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
    104           0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
    105           0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
    106           0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9);
    107    assertEq(o.length, 300);
    108    for (var i in o)
    109        assertEq(o[i], i % 10);
    110 }
    111 
    112 // Check bailouts of one frame which is not the initial frame.
    113 
    114 eval(restartCode);
    115 f1 = function() {
    116    if (counter < 5) return 0;
    117    return f2();
    118 };
    119 while (counter++ < 50) {
    120    o = f1();
    121    if (counter < 5) continue;
    122    assertEq(o.length, 0);
    123 }
    124 
    125 eval(restartCode);
    126 f1 = function() {
    127    if (counter < 5) return 0;
    128    return f2(21);
    129 };
    130 while (counter++ < 50) {
    131    o = f1();
    132    if (counter < 5) continue;
    133    assertEq(o.length, 1);
    134    assertEq(o[0], 21);
    135 }
    136 
    137 eval(restartCode);
    138 f1 = function() {
    139    if (counter < 5) return 0;
    140    return f2(21,42);
    141 };
    142 while (counter++ < 50) {
    143    o = f1();
    144    if (counter < 5) continue;
    145    assertEq(o.length, 2);
    146    assertEq(o[0], 21);
    147    assertEq(o[1], 42);
    148 }
    149 
    150 // 100 arguments.
    151 eval(restartCode);
    152 f1 = function() {
    153    if (counter < 5) return 0;
    154    return f2(0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
    155              0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
    156              0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
    157              0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
    158              0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9);
    159 };
    160 while (counter++ < 50) {
    161    o = f1();
    162    if (counter < 5) continue;
    163    assertEq(o.length, 100);
    164    for (var i in o)
    165        assertEq(o[i], i % 10);
    166 }
    167 
    168 // 200 arguments.
    169 eval(restartCode);
    170 f1 = function() {
    171    if (counter < 5) return 0;
    172    return f2(0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
    173              0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
    174              0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
    175              0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
    176              0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
    177 
    178              0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
    179              0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
    180              0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
    181              0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
    182              0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9);
    183 };
    184 while (counter++ < 50) {
    185    o = f1();
    186    if (counter < 5) continue;
    187    assertEq(o.length, 200);
    188    for (var i in o)
    189        assertEq(o[i], i % 10);
    190 }
    191 
    192 // 300 arguments.
    193 eval(restartCode);
    194 f1 = function() {
    195  if (counter < 5) return 0;
    196  return f2(0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
    197            0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
    198            0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
    199            0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
    200            0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
    201 
    202            0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
    203            0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
    204            0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
    205            0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
    206            0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
    207 
    208            0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
    209            0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
    210            0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
    211            0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,
    212            0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9);
    213 };
    214 while (counter++ < 500) {
    215    o = f1();
    216    if (counter < 5) continue;
    217    assertEq(o.length, 300);
    218    for (var i in o)
    219        assertEq(o[i], i % 10);
    220 }