tor-browser

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

species-optimize-intrinsic.js (986B)


      1 var canOptimize = getSelfHostedValue("CanOptimizeArraySpecies");
      2 
      3 function test1() {
      4  for (var i = 0; i < 20; i++) {
      5    // If one of these starts failing, we should probably change how
      6    // CanOptimizeArraySpecies is implemented to avoid perf problems!
      7    assertEq(canOptimize([1, 2, 3]), true);
      8    var a = [];
      9    for (var j = 0; j < 10; j++) {
     10      a.push(j);
     11    }
     12    assertEq(canOptimize(a), true);
     13    assertEq(canOptimize(a.slice()), true);
     14    assertEq(canOptimize(a.map(x => x + 1)), true);
     15 
     16    // These aren't plain arrays.
     17    assertEq(canOptimize({}), false);
     18    Object.setPrototypeOf(a, Object.create(Array.prototype));
     19    assertEq(canOptimize(a), false);
     20    a = [];
     21    a.constructor = function() {};
     22    assertEq(canOptimize(a), false);
     23  }
     24 }
     25 test1();
     26 
     27 function test2() {
     28  for (var i = 0; i < 20; i++) {
     29    assertEq(canOptimize([1, 2, 3]), i <= 16);
     30    if (i === 16) {
     31      // Pop the fuse.
     32      Array.prototype.constructor = Object;
     33    }
     34  }
     35 }
     36 test2();