Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 load(libdir + 'bytecode-cache.js');
2 var test = "";
3 var checkAfter;
5 // code a function which has both used and unused inner functions.
6 test = (function () {
7 function f(x) {
8 function ifTrue() {
9 return true;
10 };
11 function ifFalse() {
12 return false;
13 };
15 if (x) return ifTrue();
16 else return ifFalse();
17 }
19 return f.toSource() + "; f(true)";
20 })();
21 evalWithCache(test, { assertEqBytecode: true, assertEqResult : true });
23 // code a function which uses different inner functions based on the generation.
24 test = (function () {
25 function f(x) {
26 function ifTrue() {
27 return true;
28 };
29 function ifFalse() {
30 return false;
31 };
33 if (x) return ifTrue();
34 else return ifFalse();
35 }
37 return f.toSource() + "; f((generation % 2) == 0)";
38 })();
39 evalWithCache(test, { });
41 // Code a function which has an enclosing scope.
42 test = (function () {
43 function f() {
44 var upvar = "";
45 function g() { upvar += ""; return upvar; }
46 return g;
47 }
49 return f.toSource() + "; f()();";
50 })();
51 evalWithCache(test, { assertEqBytecode: true, assertEqResult : true });
53 // Code a lazy function which has an enclosing scope.
54 test = (function () {
55 function f() {
56 var upvar = "";
57 function g() { upvar += ""; return upvar; }
58 return g;
59 }
61 return f.toSource() + "; f();";
62 })();
63 evalWithCache(test, { assertEqBytecode: true });
65 // (basic/bug535930) Code an enclosing scope which is a Call object.
66 test = (function () {
67 return "(" + (function () {
68 p = function () {
69 Set()
70 };
71 var Set = function () {};
72 for (var x = 0; x < 5; x++) {
73 Set = function (z) {
74 return function () {
75 [z]
76 }
77 } (x)
78 }
79 }).toSource() + ")()";
80 })();
81 evalWithCache(test, { assertEqBytecode: true });
83 // Code an arrow function, and execute it.
84 test = (function () {
85 function f() {
86 var g = (a) => a + a;
87 return g;
88 }
90 return f.toSource() + "; f()(1);";
91 })();
92 evalWithCache(test, { assertEqBytecode: true, assertEqResult : true });
94 // Code an arrow function, and do not execute it.
95 test = (function () {
96 function f() {
97 var g = (a) => a + a;
98 return g;
99 }
101 return f.toSource() + "; f();";
102 })();
103 evalWithCache(test, { assertEqBytecode: true });
105 // Ensure that decoded functions can be relazified.
106 test = "function f() { }; f();"
107 + "assertEq(isLazyFunction(f), false);"
108 + "var expect = isRelazifiableFunction(f);";
109 checkAfter = function (ctx) {
110 gc(ctx.global.f); // relazify f, if possible.
111 evaluate("assertEq(isLazyFunction(f), expect);", ctx);
112 };
113 evalWithCache(test, {
114 assertEqBytecode: true, // Check that we re-encode the same thing.
115 assertEqResult: true, // The function should remain relazifiable, if it was
116 // during the first run.
117 checkAfter: checkAfter // Check that relazifying the restored function works
118 // if the original was relazifiable.
119 });
121 // Ensure that decoded functions can be relazified, even if they have free
122 // variables.
123 test = "function f() { return isRelazifiableFunction(f) }; var expect = f();"
124 + "assertEq(isLazyFunction(f), false);"
125 + "expect";
126 checkAfter = function (ctx) {
127 gc(ctx.global.f); // relazify f, if possible.
128 evaluate("assertEq(isLazyFunction(f), expect);", ctx);
129 };
130 evalWithCache(test, {
131 assertEqBytecode: true, // Check that we re-encode the same thing.
132 assertEqResult: true, // The function should remain relazifiable, if it was
133 // during the first run.
134 checkAfter: checkAfter // Check that relazifying the restored function works
135 // if the original was relazifiable.
136 });