tor-browser

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

decompiler.js (847B)


      1 // The decompiler correctly handles for-of loops.
      2 
      3 function tokens(code) {
      4    var arr = [];
      5    var s = code.replace(/\w+|[^\s]/g, function (tok) { arr.push(tok); return ""; });
      6    assertEq(s.trim(), "", "tokens() should find all tokens in code: " + JSON.stringify(code));
      7    return arr;
      8 }
      9 
     10 function test(code) {
     11    var before = "function f() { " + code + " }";
     12    var after = eval("(" + before + ")").toString();
     13    assertEq(tokens(before).join(" "), tokens(after).join(" "), "decompiler failed to round-trip");
     14 }
     15 
     16 // statements
     17 test("for (a of b) { f(a); }");
     18 test("for (a of b) { f(a); g(a); }");
     19 
     20 // for-of with "in" operator nearby
     21 test("for (a of b in c ? c : c.items()) { f(a); }");
     22 
     23 // destructuring
     24 test("for ([a, b] of c) { a.m(b); }");
     25 
     26 // for-let-of
     27 test("for (let a of b) { f(a); }");
     28 test("for (let [a, b] of c) { a.m(b); }");