tor-browser

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

from-int32-const.js (1012B)


      1 // Int32 values, including minimum, maximum, and values around zero.
      2 const values = [
      3  [0x8000_0000|0, -0x80000000n],
      4  [0x8000_0001|0, -0x7fffffffn],
      5  [0x8000_0002|0, -0x7ffffffen],
      6  [0x8000_0003|0, -0x7ffffffdn],
      7  [-3, -3n],
      8  [-2, -2n],
      9  [-1, -1n],
     10  [0, 0n],
     11  [1, 1n],
     12  [2, 2n],
     13  [3, 3n],
     14  [0x7fff_fffd, 0x7fff_fffdn],
     15  [0x7fff_fffe, 0x7fff_fffen],
     16  [0x7fff_ffff, 0x7fff_ffffn],
     17 ];
     18 
     19 const m = new WebAssembly.Module(wasmTextToBinary(`(module
     20  (func (export "toInt32") (param i64) (result i32)
     21    local.get 0
     22    i32.wrap_i64
     23  )
     24  (func (export "toInt64") (param i64) (result i64)
     25    local.get 0
     26  )
     27 )`));
     28 
     29 const {
     30  toInt32,
     31  toInt64,
     32 } = new WebAssembly.Instance(m).exports;
     33 
     34 function test() {
     35  for (let i = 0; i < 100; ++i) {
     36    assertEq(toInt32(BigInt(INT32)), INT32);
     37    assertEq(toInt64(BigInt(INT32)), INT64);
     38  }
     39 }
     40 
     41 for (let [int32, int64] of values) {
     42  let fn = Function(
     43    `return ${test}`
     44    .replaceAll("INT32", int32)
     45    .replaceAll("INT64", int64 + "n")
     46  )();
     47  fn();
     48 }