tor-browser

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

truncateToInt32.js (771B)


      1 // vim: set ts=8 sts=4 et sw=4 tw=99:
      2 
      3 function w(y)
      4 {
      5    var x = 23.5;
      6    return x & y;
      7 }
      8 
      9 function f(x, y) {
     10    // Confuse the type analysis to not know the type of x.
     11    var t = 3.5 + x;
     12    t + 3.5;
     13    return x & y;
     14 }
     15 
     16 function g_bool(x, y) {
     17    var t;
     18    if (x + 0)
     19        t = true;
     20    else
     21        t = false;
     22    return t & y;
     23 
     24 }
     25 
     26 function g_null(x) {
     27    return null & x;
     28 }
     29 
     30 var obj = { valueOf: function () { return 5; } }
     31 
     32 assertEq(w(93), 21);
     33 assertEq(g_bool(1, 3), 1);
     34 assertEq(g_bool(0, 3), 0);
     35 assertEq(g_null(2), 0);
     36 
     37 assertEq(f(1, 7), 1);
     38 assertEq(f(true, 7), 1);
     39 assertEq(f(false, 7), 0);
     40 assertEq(f("3", 7), 3);
     41 assertEq(f(obj, 7), 5);
     42 assertEq(f(3.5, 7), 3);
     43 assertEq(f(undefined, 7), 0);
     44 assertEq(f(null, 7), 0);
     45 assertEq(f(Math.NaN, 7), 0);