1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/jit-test/tests/for-of/decompiler.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,36 @@ 1.4 +// The decompiler correctly handles for-of loops. 1.5 + 1.6 +function tokens(code) { 1.7 + var arr = []; 1.8 + var s = code.replace(/\w+|[^\s]/g, function (tok) { arr.push(tok); return ""; }); 1.9 + assertEq(s.trim(), "", "tokens() should find all tokens in code: " + uneval(code)); 1.10 + return arr; 1.11 +} 1.12 + 1.13 +function test(code) { 1.14 + var before = "function f() { " + code + " }"; 1.15 + var after = eval("(" + before + ")").toString(); 1.16 + assertEq(tokens(before).join(" "), tokens(after).join(" "), "decompiler failed to round-trip"); 1.17 +} 1.18 + 1.19 +// statements 1.20 +test("for (a of b) { f(a); }"); 1.21 +test("for (a of b) { f(a); g(a); }"); 1.22 + 1.23 +// for-of with "in" operator nearby 1.24 +test("for (a of b in c ? c : c.items()) { f(a); }"); 1.25 + 1.26 +// destructuring 1.27 +test("for ([a, b] of c) { a.m(b); }"); 1.28 + 1.29 +// for-let-of 1.30 +test("for (let a of b) { f(a); }"); 1.31 +test("for (let [a, b] of c) { a.m(b); }"); 1.32 + 1.33 +// array comprehensions 1.34 +test("return [a for (a of b)];"); 1.35 +test("return [[b, a] for ([a, b] of c.items())];"); 1.36 + 1.37 +// generator expressions 1.38 +test("return (a for (a of b));"); 1.39 +