tor-browser

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

bug1992316.js (1325B)


      1 // |jit-test| skip-if: !isAsmJSCompilationAvailable()
      2 
      3 // Generate a function with many parameters and local variables.
      4 // We want to test the limits and this module should fail validation.
      5 function build_asm_code(num_params, num_locals_decl_extra) {
      6  let params = [];
      7  let param_annots = [];
      8  for (let i = 0; i < num_params; ++i) {
      9    params.push(`p${i}`);
     10    param_annots.push(`  p${i} = p${i} | 0;`);
     11  }
     12  let local_inits = [];
     13  local_inits.push(`x = 0`);
     14  for (let i = 0; i < num_locals_decl_extra; ++i) {
     15    let name = `l${i}`;
     16    local_inits.push(`${name} = 0`);
     17  }
     18  if (local_inits.length > 0) {
     19    local_decl = `  var ${local_inits.join()};`;
     20  }
     21  const body = `
     22    x = p0 | 0;
     23    switch (x | 0) {
     24      case 0:
     25        return 1;
     26      case 1:
     27        return 2;
     28      default:
     29        return 3;
     30    }
     31    return 0;
     32  `;
     33  const code = `
     34 function Module(stdlib, foreign, buffer) {
     35  "use asm";
     36  // No stdlib imports needed
     37 
     38  // Function 'f' with specified parameters and locals
     39  function f(${params.join()}) {
     40    ${param_annots.join("")}
     41    ${local_decl}
     42    ${body}
     43  }
     44 
     45  // Export function 'f'
     46  return { f: f };
     47 }
     48 `;
     49  return code;
     50 }
     51 const num_params = 10;
     52 const num_locals_decl_extra = 49997;
     53 const code = build_asm_code(num_params, num_locals_decl_extra);
     54 
     55 const module = eval(`(${code})`);