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

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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