tor-browser

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

polymorphic-to-bool.js (1047B)


      1 // |jit-test| --fast-warmup; --no-threads
      2 
      3 function runTest(src, seen, last) {
      4    with ({}) {}
      5 
      6    // Make a fresh script.
      7    var foo = eval(src);
      8 
      9    // Compile it with polymorphic types.
     10    for (var j = 0; j < 100; j++) {
     11 foo(seen[j % seen.length]);
     12    }
     13 
     14    // Now test the type sorted last.
     15    assertEq(foo(last), false);
     16 }
     17 
     18 function runTests(src) {
     19    // Each of these |seen| sets will cause the |last| type to be
     20    // the last type tested in testValueTruthyKernel.
     21    runTest(src, [1n,   Symbol("a"), 1.5,  "",   {}   ],  1);
     22    runTest(src, [1n,   Symbol("a"), 1.5,  "",   true ],  {});
     23    runTest(src, [1n,   Symbol("a"), 1.5,  true, {}   ],  "a");
     24    runTest(src, [1n,   Symbol("a"), true, "",   {}   ],  1.5);
     25    runTest(src, [1n,   true,        1.5,  "",   {}   ],  Symbol("a"));
     26    runTest(src, [true, Symbol("a"), 1.5,  "",   {}   ],  1n);
     27 }
     28 
     29 // JumpIfFalse
     30 runTests("(x) => { if (x) { return false; }}");
     31 
     32 // And
     33 runTests("(x) => x && false");
     34 
     35 // Or
     36 runTests("(x) => !(x || true)");
     37 
     38 // Not
     39 runTests("(x) => !x");