tor-browser

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

testApplyArrayInline.js (1769B)


      1 // |jit-test| skip-if: !this.getJitCompilerOptions() || !getJitCompilerOptions()['ion.enable']; --ion-warmup-threshold=50
      2 
      3 // Test inlining in Ion of fun.apply(..., array).
      4 
      5 setJitCompilerOption("offthread-compilation.enable", 0);
      6 gcPreserveCode();
      7 
      8 var itercount = 1000;
      9 var warmup = 100;
     10 
     11 // Force Ion to do something predictable without having to wait
     12 // forever for it.
     13 
     14 if (getJitCompilerOptions()["ion.warmup.trigger"] > warmup)
     15    setJitCompilerOption("ion.warmup.trigger", warmup);
     16 
     17 setJitCompilerOption("offthread-compilation.enable", 0);
     18 
     19 function g(a, b, c, d) {
     20    return a + b + c + (d === undefined);
     21 }
     22 
     23 var g_inIonInLoop = false;
     24 var g_inIonAtEnd = false;
     25 
     26 function f(xs) {
     27    var sum = 0;
     28    var inIonInLoop = 0;
     29    for ( var i=0 ; i < itercount ; i++ ) {
     30 inIonInLoop |= inIon();
     31 sum += g.apply(null, xs);
     32    }
     33    g_ionAtEnd = inIon();
     34    g_inIonInLoop = !!inIonInLoop;
     35    return sum;
     36 }
     37 
     38 // Basic test
     39 
     40 assertEq(f([1,2,3,4]), 6*itercount);
     41 
     42 // Attempt to detect a botched optimization: either we ion-compiled
     43 // the loop, or we did not ion-compile the function (ion not actually
     44 // effective at all, this can happen).
     45 
     46 assertEq(g_inIonInLoop || !g_inIonAtEnd, true);
     47 
     48 // If Ion is inert just leave.
     49 
     50 if (!g_inIonInLoop) {
     51    print("Leaving early - ion not kicking in at all");
     52    quit(0);
     53 }
     54 
     55 // Test that we get the correct argument value even if the array has
     56 // fewer initialized members than its length.
     57 
     58 var headroom = [1,2,3];
     59 headroom.length = 13;
     60 assertEq(f(headroom), 7*itercount);
     61 
     62 // Test that we throw when the array is too long.
     63 
     64 var thrown = false;
     65 try {
     66    var long = [];
     67    long.length = getMaxArgs() + 1;
     68    f(long);
     69 }
     70 catch (e) {
     71    thrown = true;
     72    assertEq(e instanceof RangeError, true);
     73 }
     74 assertEq(thrown, true);