js/src/jit-test/tests/for-of/decompiler.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial