tor-browser

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

arguments-object-load-arg.js (2936B)


      1 // Test transpiling of LoadArgumentsObjectArgResult and cover all possible bailout conditions.
      2 
      3 function blackhole() {
      4  // Direct eval prevents any compile-time optimisations.
      5  eval("");
      6 }
      7 
      8 function testConstantArgAccess() {
      9  blackhole(arguments); // Create an arguments object.
     10 
     11  for (var i = 0; i < 50; ++i) {
     12    assertEq(arguments[0], 1);
     13  }
     14 }
     15 for (var i = 0; i < 20; ++i) testConstantArgAccess(1);
     16 
     17 function testDynamicArgAccess() {
     18  blackhole(arguments); // Create an arguments object.
     19 
     20  for (var i = 0; i < 50; ++i) {
     21    assertEq(arguments[i & 1], 1 + (i & 1));
     22  }
     23 }
     24 for (var i = 0; i < 20; ++i) testDynamicArgAccess(1, 2);
     25 
     26 function markElementOveriddenIf(args, cond, value) {
     27  with ({}) ; // Don't Warp compile to avoid cold code bailouts.
     28  if (cond) {
     29    Object.defineProperty(args, 0, {value});
     30  }
     31 }
     32 
     33 function testBailoutElementReified() {
     34  blackhole(arguments); // Create an arguments object.
     35 
     36  for (var i = 0; i < 50; ++i) {
     37    markElementOveriddenIf(arguments, i === 25, 2);
     38 
     39    var expected = 1 + (i >= 25);
     40    assertEq(arguments[0], expected);
     41  }
     42 }
     43 for (var i = 0; i < 20; ++i) testBailoutElementReified(1);
     44 
     45 function markLengthOveriddenIf(args, cond, value) {
     46  with ({}) ; // Don't Warp compile to avoid cold code bailouts.
     47  if (cond) {
     48    args.length = value;
     49  }
     50 }
     51 
     52 function testBailoutLengthReified() {
     53  blackhole(arguments); // Create an arguments object.
     54 
     55  for (var i = 0; i < 50; ++i) {
     56    markLengthOveriddenIf(arguments, i === 25, 0);
     57 
     58    assertEq(arguments[0], 1);
     59  }
     60 }
     61 for (var i = 0; i < 20; ++i) testBailoutLengthReified(1);
     62 
     63 function deleteElementIf(args, cond) {
     64  with ({}) ; // Don't Warp compile to avoid cold code bailouts.
     65  if (cond) {
     66    delete args[0];
     67  }
     68 }
     69 
     70 function testBailoutElementDeleted() {
     71  blackhole(arguments); // Create an arguments object.
     72 
     73  // Load expected values from an array to avoid possible cold code bailouts.
     74  var values = [1, undefined];
     75 
     76  for (var i = 0; i < 50; ++i) {
     77    deleteElementIf(arguments, i === 25);
     78 
     79    var expected = values[0 + (i >= 25)];
     80    assertEq(arguments[0], expected);
     81  }
     82 }
     83 for (var i = 0; i < 20; ++i) testBailoutElementDeleted(1);
     84 
     85 function testBailoutOutOfBounds() {
     86  blackhole(arguments); // Create an arguments object.
     87 
     88  // Load expected values from an array to avoid possible cold code bailouts.
     89  var values = [1, undefined];
     90 
     91  for (var i = 0; i < 50; ++i) {
     92    var index = 0 + (i >= 25);
     93    var expected = values[index];
     94    assertEq(arguments[index], expected);
     95  }
     96 }
     97 for (var i = 0; i < 20; ++i) testBailoutOutOfBounds(1);
     98 
     99 function testBailoutArgForwarded(arg1, arg2) {
    100  blackhole(arguments); // Create an arguments object.
    101  blackhole(() => arg2); // Ensure |arg2| is marked as "forwarded".
    102 
    103  for (var i = 0; i < 50; ++i) {
    104    var index = 0 + (i >= 25);
    105    var expected = 1 + (i >= 25);
    106    assertEq(arguments[index], expected);
    107  }
    108 }
    109 for (var i = 0; i < 20; ++i) testBailoutArgForwarded(1, 2);