tor-browser

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

bigint-compare-null-or-undef.js (1776B)


      1 // Test relational comparison when one operand is null or undefined.
      2 
      3 function test(xs) {
      4  for (let i = 0; i < 200; ++i) {
      5    let x = xs[i % xs.length];
      6 
      7    // The result is equal when compared to the result with explicit ToNumber conversions.
      8 
      9    // Test when null-or-undefined is on the right-hand side.
     10    assertEq(x < nullOrUndef, x < (+nullOrUndef));
     11    assertEq(x <= nullOrUndef, x <= (+nullOrUndef));
     12    assertEq(x >= nullOrUndef, x >= (+nullOrUndef));
     13    assertEq(x > nullOrUndef, x > (+nullOrUndef));
     14 
     15    // Test when null-or-undefined is on the left-hand side.
     16    assertEq(nullOrUndef < x, (+nullOrUndef) < x);
     17    assertEq(nullOrUndef <= x, (+nullOrUndef) <= x);
     18    assertEq(nullOrUndef >= x, (+nullOrUndef) >= x);
     19    assertEq(nullOrUndef > x, (+nullOrUndef) > x);
     20  }
     21 }
     22 
     23 function runTest(inputs) {
     24  let fNull = Function(`return ${test}`.replaceAll("nullOrUndef", "null"))();
     25  fNull(inputs);
     26 
     27  let fUndefined = Function(`return ${test}`.replaceAll("nullOrUndef", "undefined"))();
     28  fUndefined(inputs);
     29 }
     30 
     31 // BigInt inputs
     32 runTest([
     33  // Definitely heap digits.
     34  -(2n ** 1000n),
     35 
     36  // -(2n**64n)
     37  -18446744073709551617n,
     38  -18446744073709551616n,
     39  -18446744073709551615n,
     40 
     41  // -(2n**63n)
     42  -9223372036854775809n,
     43  -9223372036854775808n,
     44  -9223372036854775807n,
     45 
     46  // -(2**32)
     47  -4294967297n,
     48  -4294967296n,
     49  -4294967295n,
     50 
     51  // -(2**31)
     52  -2147483649n,
     53  -2147483648n,
     54  -2147483647n,
     55 
     56  -1n,
     57  0n,
     58  1n,
     59 
     60  // 2**31
     61  2147483647n,
     62  2147483648n,
     63  2147483649n,
     64 
     65  // 2**32
     66  4294967295n,
     67  4294967296n,
     68  4294967297n,
     69 
     70  // 2n**63n
     71  9223372036854775807n,
     72  9223372036854775808n,
     73  9223372036854775809n,
     74 
     75  // 2n**64n
     76  18446744073709551615n,
     77  18446744073709551616n,
     78  18446744073709551617n,
     79 
     80  // Definitely heap digits.
     81  2n ** 1000n,
     82 ]);