summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/closures
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/jit-test/tests/closures')
-rw-r--r--js/src/jit-test/tests/closures/bug496922.js21
-rw-r--r--js/src/jit-test/tests/closures/bug540131-2.js13
-rw-r--r--js/src/jit-test/tests/closures/bug540131.js5
-rw-r--r--js/src/jit-test/tests/closures/bug540242.js17
-rw-r--r--js/src/jit-test/tests/closures/bug540243.js10
-rw-r--r--js/src/jit-test/tests/closures/bug540528.js4
-rw-r--r--js/src/jit-test/tests/closures/bug541239.js16
-rw-r--r--js/src/jit-test/tests/closures/bug543565.js7
-rw-r--r--js/src/jit-test/tests/closures/bug684178.js9
-rw-r--r--js/src/jit-test/tests/closures/bug684489.js2
-rw-r--r--js/src/jit-test/tests/closures/closure-pluseq.js31
-rw-r--r--js/src/jit-test/tests/closures/closure-pluseq2.js30
-rw-r--r--js/src/jit-test/tests/closures/closure-plusplus.js31
-rw-r--r--js/src/jit-test/tests/closures/closure-tests.js6
-rw-r--r--js/src/jit-test/tests/closures/flat-closure-1.js18
-rw-r--r--js/src/jit-test/tests/closures/flat-closure-7.js15
-rw-r--r--js/src/jit-test/tests/closures/flat-closure-8.js19
-rw-r--r--js/src/jit-test/tests/closures/lambda-inner-heavy.js32
-rw-r--r--js/src/jit-test/tests/closures/lambda-light-returned.js25
-rw-r--r--js/src/jit-test/tests/closures/lambda-light.js19
-rw-r--r--js/src/jit-test/tests/closures/lambda.js22
-rw-r--r--js/src/jit-test/tests/closures/lambdafc.js25
-rw-r--r--js/src/jit-test/tests/closures/name-both-hvy.js28
-rw-r--r--js/src/jit-test/tests/closures/name-inactive-missing.js14
-rw-r--r--js/src/jit-test/tests/closures/name.js25
-rw-r--r--js/src/jit-test/tests/closures/name2.js23
-rw-r--r--js/src/jit-test/tests/closures/name2a.js23
-rw-r--r--js/src/jit-test/tests/closures/name2b.js23
-rw-r--r--js/src/jit-test/tests/closures/name3.js24
-rw-r--r--js/src/jit-test/tests/closures/name4.js22
-rw-r--r--js/src/jit-test/tests/closures/namedLambda.js17
-rw-r--r--js/src/jit-test/tests/closures/nameinc-loop-2.js26
-rw-r--r--js/src/jit-test/tests/closures/nameinc-loop-3.js33
-rw-r--r--js/src/jit-test/tests/closures/nameinc-loop-missing-2.js19
-rw-r--r--js/src/jit-test/tests/closures/nameinc-loop-missing.js21
-rw-r--r--js/src/jit-test/tests/closures/nameinc-loop.js24
-rw-r--r--js/src/jit-test/tests/closures/nameinc.js21
-rw-r--r--js/src/jit-test/tests/closures/set-outer-trace-1.js24
-rw-r--r--js/src/jit-test/tests/closures/set-outer-trace-2.js23
-rw-r--r--js/src/jit-test/tests/closures/set-outer-trace-3.js23
-rw-r--r--js/src/jit-test/tests/closures/set-outer-trace-4.js23
-rw-r--r--js/src/jit-test/tests/closures/set-outer-trace.js23
-rw-r--r--js/src/jit-test/tests/closures/setname-1.js26
-rw-r--r--js/src/jit-test/tests/closures/setname-closure-2.js27
-rw-r--r--js/src/jit-test/tests/closures/setname-closure.js25
-rw-r--r--js/src/jit-test/tests/closures/setname-inner-heavy.js18
-rw-r--r--js/src/jit-test/tests/closures/setname-loop-2.js29
-rw-r--r--js/src/jit-test/tests/closures/setname-loop.js26
-rw-r--r--js/src/jit-test/tests/closures/setname-no-pop.js16
-rw-r--r--js/src/jit-test/tests/closures/t001.js21
-rw-r--r--js/src/jit-test/tests/closures/t002.js21
-rw-r--r--js/src/jit-test/tests/closures/t003.js21
-rw-r--r--js/src/jit-test/tests/closures/t004.js21
-rw-r--r--js/src/jit-test/tests/closures/t005.js24
-rw-r--r--js/src/jit-test/tests/closures/t006.js22
-rw-r--r--js/src/jit-test/tests/closures/t007.js23
-rw-r--r--js/src/jit-test/tests/closures/t008.js26
-rw-r--r--js/src/jit-test/tests/closures/t009.js18
-rw-r--r--js/src/jit-test/tests/closures/t010.js21
-rw-r--r--js/src/jit-test/tests/closures/t011.js18
-rw-r--r--js/src/jit-test/tests/closures/t012.js19
-rw-r--r--js/src/jit-test/tests/closures/t013.js21
-rw-r--r--js/src/jit-test/tests/closures/t014.js21
-rw-r--r--js/src/jit-test/tests/closures/t015.js21
-rw-r--r--js/src/jit-test/tests/closures/t016.js23
-rw-r--r--js/src/jit-test/tests/closures/t017.js23
-rw-r--r--js/src/jit-test/tests/closures/t020.js17
-rw-r--r--js/src/jit-test/tests/closures/t021.js18
-rw-r--r--js/src/jit-test/tests/closures/t022.js24
-rw-r--r--js/src/jit-test/tests/closures/t023.js17
-rw-r--r--js/src/jit-test/tests/closures/t024.js19
-rw-r--r--js/src/jit-test/tests/closures/t025.js26
-rw-r--r--js/src/jit-test/tests/closures/t026.js22
-rw-r--r--js/src/jit-test/tests/closures/t027.js21
-rw-r--r--js/src/jit-test/tests/closures/t028.js23
-rw-r--r--js/src/jit-test/tests/closures/t029.js21
-rw-r--r--js/src/jit-test/tests/closures/t030.js21
-rw-r--r--js/src/jit-test/tests/closures/t031.js21
-rw-r--r--js/src/jit-test/tests/closures/t032.js24
-rw-r--r--js/src/jit-test/tests/closures/t033.js19
-rw-r--r--js/src/jit-test/tests/closures/t034.js20
-rw-r--r--js/src/jit-test/tests/closures/t035.js18
-rw-r--r--js/src/jit-test/tests/closures/t036.js24
-rw-r--r--js/src/jit-test/tests/closures/t037.js14
-rw-r--r--js/src/jit-test/tests/closures/test-inner-imports.js22
-rw-r--r--js/src/jit-test/tests/closures/upvar-nest.js24
86 files changed, 1782 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/closures/bug496922.js b/js/src/jit-test/tests/closures/bug496922.js
new file mode 100644
index 0000000000..a0aeca1d26
--- /dev/null
+++ b/js/src/jit-test/tests/closures/bug496922.js
@@ -0,0 +1,21 @@
+actual = '';
+expected = '0,0,1,1,2,2,3,3,';
+
+v = 0
+{
+let f = function() {
+ for (let x = 0; x < 4; ++x) {
+ v >> x;
+ (function() {
+ for (let y = 0; y < 2; ++y) {
+ appendToActual(x)
+ }
+ })()
+ }
+};
+(function() {})()
+ f(v)
+}
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/bug540131-2.js b/js/src/jit-test/tests/closures/bug540131-2.js
new file mode 100644
index 0000000000..ebd3e0203a
--- /dev/null
+++ b/js/src/jit-test/tests/closures/bug540131-2.js
@@ -0,0 +1,13 @@
+// |jit-test| error: TypeError
+(function() {
+ for (let z in [true]) {
+ (new(eval("for(l in[0,0,0,0]){}"))
+ (((function f(a, b) {
+ if (a.length == b) {
+ return (z)
+ }
+ f(a, b + 1)
+ })([,,], 0)), []))
+ }
+})()
+
diff --git a/js/src/jit-test/tests/closures/bug540131.js b/js/src/jit-test/tests/closures/bug540131.js
new file mode 100644
index 0000000000..4584ac350a
--- /dev/null
+++ b/js/src/jit-test/tests/closures/bug540131.js
@@ -0,0 +1,5 @@
+try {
+ (function() {
+ { let x = (eval("for(y in[0,0,0,0]){}")); }
+ })()
+} catch(e) {}
diff --git a/js/src/jit-test/tests/closures/bug540242.js b/js/src/jit-test/tests/closures/bug540242.js
new file mode 100644
index 0000000000..56c1a5a314
--- /dev/null
+++ b/js/src/jit-test/tests/closures/bug540242.js
@@ -0,0 +1,17 @@
+for (j = 0; j < 1; j++) {
+ var f = eval("\
+ (function() {\
+ for (var a = 0; a < 8; ++a) {\
+ if (a % 3 == 2) {\
+ eval(\"\
+ for(b in[0,0,0,0]) {\
+ print()\
+ }\
+ \")\
+ }\
+ gc()\
+ }\
+ })\
+ ");
+ f()
+}
diff --git a/js/src/jit-test/tests/closures/bug540243.js b/js/src/jit-test/tests/closures/bug540243.js
new file mode 100644
index 0000000000..67b65c6346
--- /dev/null
+++ b/js/src/jit-test/tests/closures/bug540243.js
@@ -0,0 +1,10 @@
+for (a of (eval("\
+ (function() {\
+ return function*() {\
+ yield ((function() {\
+ return d\
+ })())\
+ } ();\
+ var d = []\
+ })\
+"))());
diff --git a/js/src/jit-test/tests/closures/bug540528.js b/js/src/jit-test/tests/closures/bug540528.js
new file mode 100644
index 0000000000..419d33eb5f
--- /dev/null
+++ b/js/src/jit-test/tests/closures/bug540528.js
@@ -0,0 +1,4 @@
+(function() {
+ var a
+ eval("for(b in[0,0,0,0]){}[a=0]")
+})()
diff --git a/js/src/jit-test/tests/closures/bug541239.js b/js/src/jit-test/tests/closures/bug541239.js
new file mode 100644
index 0000000000..389aa9d28f
--- /dev/null
+++ b/js/src/jit-test/tests/closures/bug541239.js
@@ -0,0 +1,16 @@
+function m() {
+ var d = 73;
+
+ return (eval("\n\
+ (function() {\n\
+ return function*() {\n\
+ yield ((function() {\n\
+ print(d);\n\
+ return d\n\
+ })())\n\
+ } ();\n\
+ })\n\
+ "))();
+}
+
+m().next();
diff --git a/js/src/jit-test/tests/closures/bug543565.js b/js/src/jit-test/tests/closures/bug543565.js
new file mode 100644
index 0000000000..828688b3a8
--- /dev/null
+++ b/js/src/jit-test/tests/closures/bug543565.js
@@ -0,0 +1,7 @@
+function C() {
+ var k = 3;
+ this.x = function () { return k; };
+ for (var i = 0; i < 9; i++)
+ ;
+}
+new C;
diff --git a/js/src/jit-test/tests/closures/bug684178.js b/js/src/jit-test/tests/closures/bug684178.js
new file mode 100644
index 0000000000..34a59c5fb4
--- /dev/null
+++ b/js/src/jit-test/tests/closures/bug684178.js
@@ -0,0 +1,9 @@
+var obj = {};
+(function() {
+ if (obj) {
+ function f() { obj.x = 1; }
+ obj.m = function() { f(); };
+ }
+})();
+obj.m();
+assertEq(obj.x, 1);
diff --git a/js/src/jit-test/tests/closures/bug684489.js b/js/src/jit-test/tests/closures/bug684489.js
new file mode 100644
index 0000000000..ab44d5850f
--- /dev/null
+++ b/js/src/jit-test/tests/closures/bug684489.js
@@ -0,0 +1,2 @@
+"use strict";
+eval("var x = {}; ({p: function() { x.m; }}).p();");
diff --git a/js/src/jit-test/tests/closures/closure-pluseq.js b/js/src/jit-test/tests/closures/closure-pluseq.js
new file mode 100644
index 0000000000..ccf5c82709
--- /dev/null
+++ b/js/src/jit-test/tests/closures/closure-pluseq.js
@@ -0,0 +1,31 @@
+actual = '';
+expected = '3,6,9,12,15,18,';
+
+function slice(a, b)
+{
+ //return { x: a + ':' + b };
+ return b;
+}
+
+function f()
+{
+ var length = 20;
+ var index = 0;
+
+ function get3() {
+ //appendToActual("get3 " + index);
+ if (length - index < 3)
+ return null;
+ return slice(index, index += 3);
+ }
+
+ var bytes = null;
+ while (bytes = get3()) {
+ appendToActual(bytes);
+ }
+}
+
+f();
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/closure-pluseq2.js b/js/src/jit-test/tests/closures/closure-pluseq2.js
new file mode 100644
index 0000000000..bab2df6d8a
--- /dev/null
+++ b/js/src/jit-test/tests/closures/closure-pluseq2.js
@@ -0,0 +1,30 @@
+actual = '';
+expected = '3,6,9,12,15,18,';
+
+function slice(a, b)
+{
+ //return { x: a + ':' + b };
+ return b;
+}
+
+function f(index)
+{
+ var length = 20;
+
+ function get3() {
+ //appendToActual("get3 " + index);
+ if (length - index < 3)
+ return null;
+ return slice(index, index += 3);
+ }
+
+ var bytes = null;
+ while (bytes = get3()) {
+ appendToActual(bytes);
+ }
+}
+
+f(0);
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/closure-plusplus.js b/js/src/jit-test/tests/closures/closure-plusplus.js
new file mode 100644
index 0000000000..c6f35352d8
--- /dev/null
+++ b/js/src/jit-test/tests/closures/closure-plusplus.js
@@ -0,0 +1,31 @@
+actual = '';
+expected = '1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,';
+
+function slice(a, b)
+{
+ //return { x: a + ':' + b };
+ return b;
+}
+
+function f()
+{
+ var length = 20;
+ var index = 0;
+
+ function get3() {
+ //appendToActual("get3 " + index);
+ if (length - index < 3)
+ return null;
+ return slice(index, ++index);
+ }
+
+ var bytes = null;
+ while (bytes = get3()) {
+ appendToActual(bytes);
+ }
+}
+
+f();
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/closure-tests.js b/js/src/jit-test/tests/closures/closure-tests.js
new file mode 100644
index 0000000000..4ec09e9f79
--- /dev/null
+++ b/js/src/jit-test/tests/closures/closure-tests.js
@@ -0,0 +1,6 @@
+actual = '';
+expected = '';
+
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/flat-closure-1.js b/js/src/jit-test/tests/closures/flat-closure-1.js
new file mode 100644
index 0000000000..3ac9b5ad11
--- /dev/null
+++ b/js/src/jit-test/tests/closures/flat-closure-1.js
@@ -0,0 +1,18 @@
+actual = '';
+expected = '0,1,2,3,4,';
+
+function g(a) {
+}
+
+function f(y) {
+ var q;
+ q = function() { appendToActual(y); };
+ q();
+}
+
+for (var i = 0; i < 5; ++i) {
+ f(i);
+ }
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/flat-closure-7.js b/js/src/jit-test/tests/closures/flat-closure-7.js
new file mode 100644
index 0000000000..5e2a7be3b7
--- /dev/null
+++ b/js/src/jit-test/tests/closures/flat-closure-7.js
@@ -0,0 +1,15 @@
+actual = '';
+expected = '0 0 0 0 0 0 0 0 0,';
+
+ var o = [];
+ for (var a = 0; a < 9; ++a) {
+ var unused = 0;
+ let zero = 0;
+ for (var ee = 0; ee < 1; ++ee) {
+ o.push((function () { return zero; })());
+ }
+ }
+ appendToActual(o.join(" "));
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/flat-closure-8.js b/js/src/jit-test/tests/closures/flat-closure-8.js
new file mode 100644
index 0000000000..fb719b0f2a
--- /dev/null
+++ b/js/src/jit-test/tests/closures/flat-closure-8.js
@@ -0,0 +1,19 @@
+actual = '';
+expected = 'nocrash,';
+
+function b(a) {
+}
+
+function f(y) {
+ function q() { b(y); };
+ q();
+}
+
+for (var i = 0; i < 1000; ++i) {
+ f(i);
+ }
+
+appendToActual('nocrash')
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/lambda-inner-heavy.js b/js/src/jit-test/tests/closures/lambda-inner-heavy.js
new file mode 100644
index 0000000000..eba73cb645
--- /dev/null
+++ b/js/src/jit-test/tests/closures/lambda-inner-heavy.js
@@ -0,0 +1,32 @@
+actual = '';
+expected = '0,0,0,0,0,0,0,1,1,1,1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,3,3,3,4,4,4,4,4,4,4,';
+
+function g(a) {
+ a();
+}
+
+function n() {
+}
+
+function f(y) {
+ for (var i = 0; i < 7; ++i) {
+ var q;
+ q = function() {
+ appendToActual(y);
+
+ var m = 1;
+ var z = function() {
+ appendToActual(m);
+ }
+ m = 2;
+ };
+ g(q);
+ }
+}
+
+for (var i = 0; i < 5; ++i) {
+ f(i);
+ }
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/lambda-light-returned.js b/js/src/jit-test/tests/closures/lambda-light-returned.js
new file mode 100644
index 0000000000..75541baab8
--- /dev/null
+++ b/js/src/jit-test/tests/closures/lambda-light-returned.js
@@ -0,0 +1,25 @@
+actual = '';
+expected = '1,';
+
+function createCounter() {
+ var i = 0;
+
+ var counter = function() {
+ return ++i;
+ }
+
+ return counter;
+}
+
+function f() {
+ var counter;
+ for (var i = 0; i < 100; ++i) {
+ counter = createCounter();
+ }
+ appendToActual(counter());
+}
+
+f();
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/lambda-light.js b/js/src/jit-test/tests/closures/lambda-light.js
new file mode 100644
index 0000000000..933da605ee
--- /dev/null
+++ b/js/src/jit-test/tests/closures/lambda-light.js
@@ -0,0 +1,19 @@
+actual = '';
+expected = '10,';
+
+function f(x) {
+ {
+ let x2 = 10;
+ for (var i = 0; i < 5; ++i) {
+ var g = function () {
+ appendToActual(x2);
+ };
+ }
+ g();
+ }
+}
+
+f(1);
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/lambda.js b/js/src/jit-test/tests/closures/lambda.js
new file mode 100644
index 0000000000..7a90fdf77f
--- /dev/null
+++ b/js/src/jit-test/tests/closures/lambda.js
@@ -0,0 +1,22 @@
+function f() {
+ var k = 0;
+
+ var g = function() {
+ return ++k;
+ }
+
+ return g;
+}
+
+function h() {
+ for (var i = 0; i < 10; ++i) {
+ var vf = f();
+ assertEq(vf(), 1);
+ assertEq(vf(), 2);
+ for (var j = 0; j < 10; ++j) {
+ assertEq(vf(), j + 3);
+ }
+ }
+}
+
+h();
diff --git a/js/src/jit-test/tests/closures/lambdafc.js b/js/src/jit-test/tests/closures/lambdafc.js
new file mode 100644
index 0000000000..03fc5ed2c0
--- /dev/null
+++ b/js/src/jit-test/tests/closures/lambdafc.js
@@ -0,0 +1,25 @@
+actual = '';
+expected = '99,';
+
+function g(p) {
+ appendToActual(p());
+}
+
+function d(k) {
+ return function() { return k; }
+}
+
+function f(k) {
+ var p;
+
+ for (var i = 0; i < 1000; ++i) {
+ p = d(k);
+ }
+
+ g(p);
+}
+
+f(99);
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/name-both-hvy.js b/js/src/jit-test/tests/closures/name-both-hvy.js
new file mode 100644
index 0000000000..6943e64d60
--- /dev/null
+++ b/js/src/jit-test/tests/closures/name-both-hvy.js
@@ -0,0 +1,28 @@
+actual = '';
+expected = '';
+
+// do not crash
+
+function q() {
+}
+
+function f() {
+ var j = 12;
+
+ function g() {
+ eval(""); // makes |g| heavyweight
+ for (var i = 0; i < 3; ++i) {
+ j;
+ }
+ }
+
+ j = 13;
+ q(g); // escaping |g| makes |f| heavyweight
+ g();
+ j = 14;
+}
+
+f();
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/name-inactive-missing.js b/js/src/jit-test/tests/closures/name-inactive-missing.js
new file mode 100644
index 0000000000..a0f68486a7
--- /dev/null
+++ b/js/src/jit-test/tests/closures/name-inactive-missing.js
@@ -0,0 +1,14 @@
+// |jit-test| error: ReferenceError
+
+function f(k) {
+ function g(j) {
+ return j + q;
+ }
+ return g;
+}
+
+g = f(10);
+var ans = '';
+for (var i = 0; i < 5; ++i) {
+ ans += g(i) + ',';
+}
diff --git a/js/src/jit-test/tests/closures/name.js b/js/src/jit-test/tests/closures/name.js
new file mode 100644
index 0000000000..498083f941
--- /dev/null
+++ b/js/src/jit-test/tests/closures/name.js
@@ -0,0 +1,25 @@
+actual = '';
+expected = '2,5,';
+
+function loop(f) {
+ var p;
+ for (var i = 0; i < 10; ++i) {
+ p = f();
+ }
+ return p;
+}
+
+function f(i, k) {
+ var g = function() { return k; }
+
+ k = 2;
+ appendToActual(loop(g));
+ k = 5;
+ appendToActual(loop(g));
+}
+
+f(0, 0);
+
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/name2.js b/js/src/jit-test/tests/closures/name2.js
new file mode 100644
index 0000000000..127b097dc0
--- /dev/null
+++ b/js/src/jit-test/tests/closures/name2.js
@@ -0,0 +1,23 @@
+actual = '';
+expected = '0,1,2,3,4,';
+
+function loop(f) {
+ var p;
+ for (var i = 0; i < 10; ++i) {
+ p = f();
+ }
+ return p;
+}
+
+function f(j, k) {
+ var g = function() { return k; }
+
+ for (k = 0; k < 5; ++k) {
+ appendToActual(loop(g));
+ }
+}
+
+f();
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/name2a.js b/js/src/jit-test/tests/closures/name2a.js
new file mode 100644
index 0000000000..34f1d0ea41
--- /dev/null
+++ b/js/src/jit-test/tests/closures/name2a.js
@@ -0,0 +1,23 @@
+actual = '';
+expected = '0,1,2,3,4,';
+
+function loop(f) {
+ var p;
+ for (var i = 0; i < 10; ++i) {
+ p = f(1, 2, 3);
+ }
+ return p;
+}
+
+function f(j, k) {
+ var g = function(a, b, c) { return k; }
+
+ for (k = 0; k < 5; ++k) {
+ appendToActual(loop(g));
+ }
+}
+
+f();
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/name2b.js b/js/src/jit-test/tests/closures/name2b.js
new file mode 100644
index 0000000000..b07b02b057
--- /dev/null
+++ b/js/src/jit-test/tests/closures/name2b.js
@@ -0,0 +1,23 @@
+actual = '';
+expected = '0,1,2,3,4,';
+
+function loop(f) {
+ var p;
+ for (var i = 0; i < 10; ++i) {
+ p = f(1, 2, 3);
+ }
+ return p;
+}
+
+function f(j, k) {
+ var g = function(a, b, c) { return k; }
+
+ for (k = 0; k < 5; ++k) {
+ appendToActual(loop(g));
+ }
+}
+
+f(1);
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/name3.js b/js/src/jit-test/tests/closures/name3.js
new file mode 100644
index 0000000000..228dfaac41
--- /dev/null
+++ b/js/src/jit-test/tests/closures/name3.js
@@ -0,0 +1,24 @@
+actual = '';
+expected = '0,1,2,3,4,';
+
+function loop(f) {
+ var p;
+ for (var i = 0; i < 10; ++i) {
+ p = f();
+ }
+ return p;
+}
+
+function f(j, k) {
+ var g = function() { return k; }
+
+ k = j;
+ appendToActual(loop(g));
+}
+
+for (var i = 0; i < 5; ++i) {
+ f(i);
+}
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/name4.js b/js/src/jit-test/tests/closures/name4.js
new file mode 100644
index 0000000000..596028e593
--- /dev/null
+++ b/js/src/jit-test/tests/closures/name4.js
@@ -0,0 +1,22 @@
+actual = '';
+expected = 'undefined,';
+
+function loop(f) {
+ var p;
+ for (var i = 0; i < 10; ++i) {
+ p = f();
+ }
+ return p;
+}
+
+function make(k, j) {
+ var g = function() { return k; }
+ k = j;
+ return g;
+}
+
+var f = make();
+appendToActual(loop(f));
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/namedLambda.js b/js/src/jit-test/tests/closures/namedLambda.js
new file mode 100644
index 0000000000..4be0c44c4c
--- /dev/null
+++ b/js/src/jit-test/tests/closures/namedLambda.js
@@ -0,0 +1,17 @@
+// This just tests that named lambdas don't crash in the tracer.
+
+var f = function ff() {
+ var k = 0;
+ var counter = function q() {
+ return ++k;
+ }
+ return counter;
+}
+
+function g() {
+ for (var i = 0; i < 10; ++i) {
+ f();
+ }
+}
+
+g();
diff --git a/js/src/jit-test/tests/closures/nameinc-loop-2.js b/js/src/jit-test/tests/closures/nameinc-loop-2.js
new file mode 100644
index 0000000000..1753f26899
--- /dev/null
+++ b/js/src/jit-test/tests/closures/nameinc-loop-2.js
@@ -0,0 +1,26 @@
+actual = '';
+expected = '1,2,3,4,5,5,undefined,1,2,3,4,5,5,undefined,1,2,3,4,5,5,undefined,1,2,3,4,5,5,undefined,1,2,3,4,5,5,undefined,';
+
+var f = function() {
+ var p = 0;
+
+ function g() {
+ for (var i = 0; i < 5; ++i) {
+ p++;
+ appendToActual(p);
+ }
+ }
+
+ g();
+
+ appendToActual(p);
+}
+
+for (var i = 0; i < 5; ++i) {
+ f();
+ appendToActual();
+}
+
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/nameinc-loop-3.js b/js/src/jit-test/tests/closures/nameinc-loop-3.js
new file mode 100644
index 0000000000..08a7d56ff2
--- /dev/null
+++ b/js/src/jit-test/tests/closures/nameinc-loop-3.js
@@ -0,0 +1,33 @@
+actual = '';
+expected = 'g 1 0,g 2 -1,g 3 -2,g 4 -3,g 5 -4,h 5 -5,f 5,undefined,g 1 0,g 2 -1,g 3 -2,g 4 -3,g 5 -4,h 5 -5,f 5,undefined,g 1 0,g 2 -1,g 3 -2,g 4 -3,g 5 -4,h 5 -5,f 5,undefined,g 1 0,g 2 -1,g 3 -2,g 4 -3,g 5 -4,h 5 -5,f 5,undefined,g 1 0,g 2 -1,g 3 -2,g 4 -3,g 5 -4,h 5 -5,f 5,undefined,';
+
+var f = function() {
+ var p = 0;
+
+ function h() {
+ var q = 0;
+
+ function g() {
+ for (var i = 0; i < 5; ++i) {
+ p++;
+ appendToActual('g ' + p + ' ' + q);
+ q--;
+ }
+ }
+ g();
+ appendToActual('h ' + p + ' ' + q);
+ }
+
+ h();
+
+ appendToActual('f ' + p);
+}
+
+for (var i = 0; i < 5; ++i) {
+ f();
+ appendToActual();
+}
+
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/nameinc-loop-missing-2.js b/js/src/jit-test/tests/closures/nameinc-loop-missing-2.js
new file mode 100644
index 0000000000..c37b3cc659
--- /dev/null
+++ b/js/src/jit-test/tests/closures/nameinc-loop-missing-2.js
@@ -0,0 +1,19 @@
+// |jit-test| error: ReferenceError
+
+for (var i = 0; i < 10; ++i) {
+ var f = function() {
+ var p = 0;
+
+ function g() {
+ for (var i = 0; i < 5; ++i) {
+ x += 5;
+ }
+ }
+
+ g();
+
+ print(p);
+ }
+ f();
+}
+
diff --git a/js/src/jit-test/tests/closures/nameinc-loop-missing.js b/js/src/jit-test/tests/closures/nameinc-loop-missing.js
new file mode 100644
index 0000000000..72eae0e40d
--- /dev/null
+++ b/js/src/jit-test/tests/closures/nameinc-loop-missing.js
@@ -0,0 +1,21 @@
+// |jit-test| error: ReferenceError
+
+for (var i = 0; i < 10; ++i) {
+ var f = function() {
+ var p = 0;
+
+ function g() {
+ for (var i = 0; i < 5; ++i) {
+ p++;
+ x++;
+ print(p);
+ }
+ }
+
+ g();
+
+ print(p);
+ }
+ f();
+}
+
diff --git a/js/src/jit-test/tests/closures/nameinc-loop.js b/js/src/jit-test/tests/closures/nameinc-loop.js
new file mode 100644
index 0000000000..33c89d12e5
--- /dev/null
+++ b/js/src/jit-test/tests/closures/nameinc-loop.js
@@ -0,0 +1,24 @@
+actual = '';
+expected = '1,2,3,4,5,5,1,2,3,4,5,5,1,2,3,4,5,5,1,2,3,4,5,5,1,2,3,4,5,5,1,2,3,4,5,5,1,2,3,4,5,5,1,2,3,4,5,5,1,2,3,4,5,5,1,2,3,4,5,5,';
+
+for (var i = 0; i < 10; ++i) {
+ var f = function() {
+ var p = 0;
+
+ function g() {
+ for (var i = 0; i < 5; ++i) {
+ p++;
+ appendToActual(p);
+ }
+ }
+
+ g();
+
+ appendToActual(p);
+ }
+ f();
+}
+
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/nameinc.js b/js/src/jit-test/tests/closures/nameinc.js
new file mode 100644
index 0000000000..6909908913
--- /dev/null
+++ b/js/src/jit-test/tests/closures/nameinc.js
@@ -0,0 +1,21 @@
+actual = '';
+expected = '5,';
+
+function f() {
+ var p = 0;
+
+ function g() {
+ for (var i = 0; i < 5; ++i) {
+ p++;
+ }
+ }
+
+ g();
+
+ appendToActual(p);
+}
+
+f();
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/set-outer-trace-1.js b/js/src/jit-test/tests/closures/set-outer-trace-1.js
new file mode 100644
index 0000000000..034a0e1974
--- /dev/null
+++ b/js/src/jit-test/tests/closures/set-outer-trace-1.js
@@ -0,0 +1,24 @@
+actual = '';
+expected = '10,19,128,337,646,1055,1564,2173,2882,3691,4600,';
+
+function f() {
+ var x = 10;
+
+ var g = function(p) {
+ for (var i = 0; i < 10; ++i) {
+ x = p + i;
+ }
+ }
+
+ for (var i = 0; i < 10; ++i) {
+ appendToActual(x);
+ g(100 * i + x);
+ }
+
+ appendToActual(x);
+}
+
+f();
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/set-outer-trace-2.js b/js/src/jit-test/tests/closures/set-outer-trace-2.js
new file mode 100644
index 0000000000..49b98aa9e4
--- /dev/null
+++ b/js/src/jit-test/tests/closures/set-outer-trace-2.js
@@ -0,0 +1,23 @@
+actual = '';
+expected = '10,19,100199,2001001999,30020010019999,400300200100199999,5004003002001001999999,60050040030020010019999999,700600500400300200100199999999,8007006005004003002001001999999999,90080070060050040030020010019999999999,';
+
+function f() {
+ var x = 10;
+
+ var g = function(p) {
+ for (var i = 0; i < 10; ++i)
+ x = p + i + '';
+ }
+
+ for (var i = 0; i < 10; ++i) {
+ appendToActual(x);
+ g(100 * i + x);
+ }
+
+ appendToActual(x);
+}
+
+f();
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/set-outer-trace-3.js b/js/src/jit-test/tests/closures/set-outer-trace-3.js
new file mode 100644
index 0000000000..458968fb38
--- /dev/null
+++ b/js/src/jit-test/tests/closures/set-outer-trace-3.js
@@ -0,0 +1,23 @@
+actual = '';
+expected = '10.5,19.5,128.5,337.5,646.5,1055.5,1564.5,2173.5,2882.5,3691.5,4600.5,';
+
+function f() {
+ var x = 10.5;
+
+ var g = function(p) {
+ for (var i = 0; i < 10; ++i)
+ x = p + i;
+ }
+
+ for (var i = 0; i < 10; ++i) {
+ appendToActual(x);
+ g(100 * i + x);
+ }
+
+ appendToActual(x);
+}
+
+f();
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/set-outer-trace-4.js b/js/src/jit-test/tests/closures/set-outer-trace-4.js
new file mode 100644
index 0000000000..c15f3c2e16
--- /dev/null
+++ b/js/src/jit-test/tests/closures/set-outer-trace-4.js
@@ -0,0 +1,23 @@
+actual = '';
+expected = '10,19,1000028,3000037,6000046,10000055,15000064,21000073,28000082,36000091,45000100,';
+
+function f() {
+ var x = 10;
+
+ var g = function(p) {
+ for (var i = 0; i < 10; ++i)
+ x = p + i;
+ }
+
+ for (var i = 0; i < 10; ++i) {
+ appendToActual(x);
+ g(1000000 * i + x);
+ }
+
+ appendToActual(x);
+}
+
+f();
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/set-outer-trace.js b/js/src/jit-test/tests/closures/set-outer-trace.js
new file mode 100644
index 0000000000..f3eb8b8f5d
--- /dev/null
+++ b/js/src/jit-test/tests/closures/set-outer-trace.js
@@ -0,0 +1,23 @@
+actual = '';
+expected = '10,20,30,40,50,60,70,80,90,100,110,';
+
+function f() {
+ var x = 10;
+
+ var g = function(p) {
+ for (var i = 0; i < 10; ++i)
+ x++;
+ }
+
+ for (var i = 0; i < 10; ++i) {
+ appendToActual(x);
+ g(100 * i + x);
+ }
+
+ appendToActual(x);
+}
+
+f();
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/setname-1.js b/js/src/jit-test/tests/closures/setname-1.js
new file mode 100644
index 0000000000..63e3be3f4a
--- /dev/null
+++ b/js/src/jit-test/tests/closures/setname-1.js
@@ -0,0 +1,26 @@
+actual = '';
+expected = '4,4,4,4,4,';
+
+function f() {
+ var k = 0;
+
+ function g() {
+ for (var i = 0; i < 5; ++i) {
+ k = i;
+ }
+ }
+
+ function h() {
+ for (var i = 0; i < 5; ++i) {
+ appendToActual(k);
+ }
+ }
+
+ g();
+ h();
+}
+
+f();
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/setname-closure-2.js b/js/src/jit-test/tests/closures/setname-closure-2.js
new file mode 100644
index 0000000000..b5e30ab2c4
--- /dev/null
+++ b/js/src/jit-test/tests/closures/setname-closure-2.js
@@ -0,0 +1,27 @@
+actual = '';
+expected = '16,';
+
+var f = function() {
+ var p = 1;
+
+ function g() {
+ for (var i = 0; i < 5; ++i) {
+ p = i * i;
+ }
+ }
+
+ function h() {
+ appendToActual(p);
+ }
+
+ return [g, h];
+};
+
+var [ g,h ] = f();
+for (var i = 0; i < 5; ++i) {
+ g();
+}
+h();
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/setname-closure.js b/js/src/jit-test/tests/closures/setname-closure.js
new file mode 100644
index 0000000000..fd450dd843
--- /dev/null
+++ b/js/src/jit-test/tests/closures/setname-closure.js
@@ -0,0 +1,25 @@
+actual = '';
+expected = '2,4,8,16,32,undefined,64,128,256,512,1024,undefined,2048,4096,8192,16384,32768,undefined,65536,131072,262144,524288,1048576,undefined,2097152,4194304,8388608,16777216,33554432,undefined,';
+
+var f = function() {
+ var p = 1;
+
+ function g() {
+ for (var i = 0; i < 5; ++i) {
+ p = p * 2;
+ appendToActual(p);
+ }
+ }
+
+ return g;
+}
+
+var g = f();
+for (var i = 0; i < 5; ++i) {
+ g();
+ appendToActual();
+}
+
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/setname-inner-heavy.js b/js/src/jit-test/tests/closures/setname-inner-heavy.js
new file mode 100644
index 0000000000..cf66c61d39
--- /dev/null
+++ b/js/src/jit-test/tests/closures/setname-inner-heavy.js
@@ -0,0 +1,18 @@
+actual = '';
+expected = 'undefined,';
+
+function f() {
+ (eval("\
+ (function () {\
+ for (var z = 0; z < 2; ++z) {\
+ x = ''\
+ }\
+ })\
+ "))();
+}
+this.__defineSetter__("x", eval)
+f()
+appendToActual(x);
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/setname-loop-2.js b/js/src/jit-test/tests/closures/setname-loop-2.js
new file mode 100644
index 0000000000..82adb07fd9
--- /dev/null
+++ b/js/src/jit-test/tests/closures/setname-loop-2.js
@@ -0,0 +1,29 @@
+actual = '';
+expected = '2,4,8,16,32,32,undefined,2,4,8,16,32,32,undefined,2,4,8,16,32,32,undefined,2,4,8,16,32,32,undefined,2,4,8,16,32,32,undefined,';
+
+var f = function() {
+ var p = 1;
+
+ function h() {
+ function g() {
+ for (var i = 0; i < 5; ++i) {
+ p = p * 2;
+ appendToActual(p);
+ }
+ }
+ g();
+ }
+
+ h();
+
+ appendToActual(p);
+}
+
+for (var i = 0; i < 5; ++i) {
+ f();
+ appendToActual();
+}
+
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/setname-loop.js b/js/src/jit-test/tests/closures/setname-loop.js
new file mode 100644
index 0000000000..5aa3b17d01
--- /dev/null
+++ b/js/src/jit-test/tests/closures/setname-loop.js
@@ -0,0 +1,26 @@
+actual = '';
+expected = '2,4,8,16,32,32,undefined,2,4,8,16,32,32,undefined,2,4,8,16,32,32,undefined,2,4,8,16,32,32,undefined,2,4,8,16,32,32,undefined,';
+
+var f = function() {
+ var p = 1;
+
+ function g() {
+ for (var i = 0; i < 5; ++i) {
+ p = p * 2;
+ appendToActual(p);
+ }
+ }
+
+ g();
+
+ appendToActual(p);
+}
+
+for (var i = 0; i < 5; ++i) {
+ f();
+ appendToActual();
+}
+
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/setname-no-pop.js b/js/src/jit-test/tests/closures/setname-no-pop.js
new file mode 100644
index 0000000000..c07d81b8a9
--- /dev/null
+++ b/js/src/jit-test/tests/closures/setname-no-pop.js
@@ -0,0 +1,16 @@
+actual = '';
+expected = '';
+
+(function () {
+ var y;
+ (eval("(function () {\
+ for (var x = 0; x < 3; ++x) {\
+ ''.replace(/a/, (y = 3))\
+ }\
+ });\
+ "))()
+})()
+
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/t001.js b/js/src/jit-test/tests/closures/t001.js
new file mode 100644
index 0000000000..33530045a4
--- /dev/null
+++ b/js/src/jit-test/tests/closures/t001.js
@@ -0,0 +1,21 @@
+actual = '';
+expected = '4,4,4,';
+
+function k(f_arg) {
+ for (var i = 0; i < 5; ++i) {
+ f_arg(i);
+ }
+}
+
+function t() {
+ var x = 1;
+ k(function (i) { x = i; });
+ appendToActual(x);
+}
+
+t();
+t();
+t();
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/t002.js b/js/src/jit-test/tests/closures/t002.js
new file mode 100644
index 0000000000..77e8178381
--- /dev/null
+++ b/js/src/jit-test/tests/closures/t002.js
@@ -0,0 +1,21 @@
+actual = '';
+expected = '54,54,54,';
+
+function k(a, f_arg, b, c) {
+ for (var i = 0; i < 5; ++i) {
+ f_arg(i + a);
+ }
+}
+
+function t() {
+ var x = 1;
+ k(50, function (i) { x = i; }, 100, 200);
+ appendToActual(x);
+}
+
+t();
+t();
+t();
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/t003.js b/js/src/jit-test/tests/closures/t003.js
new file mode 100644
index 0000000000..4cbf6cf34b
--- /dev/null
+++ b/js/src/jit-test/tests/closures/t003.js
@@ -0,0 +1,21 @@
+actual = '';
+expected = '54,54,54,';
+
+function k(a, b, f_arg, c) {
+ for (var i = 0; i < 5; ++i) {
+ f_arg(i + a);
+ }
+}
+
+function t(a, b) {
+ var x = 1;
+ k(50, 100, function (i) { x = i; }, 200);
+ appendToActual(x);
+}
+
+t(1);
+t(2, 3);
+t(4, 5, 6);
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/t004.js b/js/src/jit-test/tests/closures/t004.js
new file mode 100644
index 0000000000..de430eb6b3
--- /dev/null
+++ b/js/src/jit-test/tests/closures/t004.js
@@ -0,0 +1,21 @@
+actual = '';
+expected = 'NaN,60,74,';
+
+function k(a, b, f_arg, c) {
+ for (var i = 0; i < 5; ++i) {
+ f_arg(i + a);
+ }
+}
+
+function t(a, b) {
+ var x = 1;
+ k(50, 100, function (i) { x = i + a * b; }, 100, 200);
+ appendToActual(x);
+}
+
+t(1);
+t(2, 3);
+t(4, 5, 6);
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/t005.js b/js/src/jit-test/tests/closures/t005.js
new file mode 100644
index 0000000000..a5be41fe82
--- /dev/null
+++ b/js/src/jit-test/tests/closures/t005.js
@@ -0,0 +1,24 @@
+actual = '';
+expected = '4,';
+
+function k(f_arg) {
+ for (var i = 0; i < 5; ++i) {
+ f_arg(i);
+ }
+}
+
+function t() {
+ var x = 1;
+
+ function u() {
+ k(function (i) { x = i; });
+ appendToActual(x);
+ }
+
+ u();
+}
+
+t();
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/t006.js b/js/src/jit-test/tests/closures/t006.js
new file mode 100644
index 0000000000..67052744d4
--- /dev/null
+++ b/js/src/jit-test/tests/closures/t006.js
@@ -0,0 +1,22 @@
+actual = '';
+expected = '2,';
+
+function k(f_arg) {
+ (function() {
+ for (var i = 0; i < 10; ++i) {
+ f_arg();
+ }
+ })();
+}
+
+function t() {
+ var x = 1;
+ k(function () { x = 2; });
+ appendToActual(x);
+}
+
+t();
+
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/t007.js b/js/src/jit-test/tests/closures/t007.js
new file mode 100644
index 0000000000..1d745a3b5a
--- /dev/null
+++ b/js/src/jit-test/tests/closures/t007.js
@@ -0,0 +1,23 @@
+actual = '';
+expected = '0,1,2,3,4,5,6,7,8,9,';
+
+function k(f_arg) {
+ for (var i = 0; i < 10; ++i) {
+ f_arg(i);
+ }
+}
+
+function t() {
+ var x = 1;
+ k(function (i) { x = i; });
+ appendToActual(i);
+}
+
+for (var i = 0; i < 10; ++i) {
+ t();
+}
+
+
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/t008.js b/js/src/jit-test/tests/closures/t008.js
new file mode 100644
index 0000000000..2e5f833d7d
--- /dev/null
+++ b/js/src/jit-test/tests/closures/t008.js
@@ -0,0 +1,26 @@
+actual = '';
+expected = '900,';
+
+function k(f_arg) {
+ for (var i = 0; i < 10; ++i) {
+ f_arg(i);
+ }
+}
+
+function t() {
+ var x = 1;
+ k(function (i) { x = i; });
+ return x;
+}
+
+var ans = 0;
+for (var j = 0; j < 10; ++j) {
+ for (var i = 0; i < 10; ++i) {
+ ans += t();
+ }
+}
+appendToActual(ans);
+
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/t009.js b/js/src/jit-test/tests/closures/t009.js
new file mode 100644
index 0000000000..02acc9a98e
--- /dev/null
+++ b/js/src/jit-test/tests/closures/t009.js
@@ -0,0 +1,18 @@
+actual = '';
+expected = '4,';
+
+function k(f_arg) {
+ for (var i = 0; i < 5; ++i) {
+ f_arg(i);
+ }
+}
+
+function t(x) {
+ k(function (i) { x = i; });
+ appendToActual(x);
+}
+
+t(1);
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/t010.js b/js/src/jit-test/tests/closures/t010.js
new file mode 100644
index 0000000000..be45e78ec4
--- /dev/null
+++ b/js/src/jit-test/tests/closures/t010.js
@@ -0,0 +1,21 @@
+actual = '';
+expected = '101,';
+
+function looper(f) {
+ for (var i = 0; i < 10; ++i) {
+ for (var j = 0; j < 10; ++j) {
+ f();
+ }
+ }
+}
+
+function tester() {
+ var x = 1;
+ looper(function() { ++x; });
+ return x;
+}
+
+appendToActual(tester());
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/t011.js b/js/src/jit-test/tests/closures/t011.js
new file mode 100644
index 0000000000..3ac9b5ad11
--- /dev/null
+++ b/js/src/jit-test/tests/closures/t011.js
@@ -0,0 +1,18 @@
+actual = '';
+expected = '0,1,2,3,4,';
+
+function g(a) {
+}
+
+function f(y) {
+ var q;
+ q = function() { appendToActual(y); };
+ q();
+}
+
+for (var i = 0; i < 5; ++i) {
+ f(i);
+ }
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/t012.js b/js/src/jit-test/tests/closures/t012.js
new file mode 100644
index 0000000000..95936a7683
--- /dev/null
+++ b/js/src/jit-test/tests/closures/t012.js
@@ -0,0 +1,19 @@
+actual = '';
+expected = '0,1,2,3,4,';
+
+function g(a) {
+ a();
+}
+
+function f(y) {
+ var q;
+ q = function() { appendToActual(y); };
+ g(q);
+}
+
+for (var i = 0; i < 5; ++i) {
+ f(i);
+ }
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/t013.js b/js/src/jit-test/tests/closures/t013.js
new file mode 100644
index 0000000000..6a06af8b34
--- /dev/null
+++ b/js/src/jit-test/tests/closures/t013.js
@@ -0,0 +1,21 @@
+actual = '';
+expected = '0,0,0,0,0,0,0,1,1,1,1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,3,3,3,4,4,4,4,4,4,4,';
+
+function g(a) {
+ a();
+}
+
+function f(y) {
+ for (var i = 0; i < 7; ++i) {
+ var q;
+ q = function() { appendToActual(y); };
+ g(q);
+ }
+}
+
+for (var i = 0; i < 5; ++i) {
+ f(i);
+ }
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/t014.js b/js/src/jit-test/tests/closures/t014.js
new file mode 100644
index 0000000000..9e2b96b215
--- /dev/null
+++ b/js/src/jit-test/tests/closures/t014.js
@@ -0,0 +1,21 @@
+actual = '';
+expected = '0,0,0,0,0,0,0,1,1,1,1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,3,3,3,4,4,4,4,4,4,4,';
+
+function g(a) {
+ a();
+}
+
+function f(y) {
+ var q;
+ q = function() { appendToActual(y); };
+ for (var i = 0; i < 7; ++i) {
+ g(q);
+ }
+}
+
+for (var i = 0; i < 5; ++i) {
+ f(i);
+ }
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/t015.js b/js/src/jit-test/tests/closures/t015.js
new file mode 100644
index 0000000000..2d5005c858
--- /dev/null
+++ b/js/src/jit-test/tests/closures/t015.js
@@ -0,0 +1,21 @@
+actual = '';
+expected = '0,1,2,3,4,';
+
+function g(a) {
+ a();
+}
+
+function f(y) {
+ var q;
+ for (var i = 0; i < 7; ++i) {
+ q = function() { appendToActual(y); };
+ }
+ g(q);
+}
+
+for (var i = 0; i < 5; ++i) {
+ f(i);
+ }
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/t016.js b/js/src/jit-test/tests/closures/t016.js
new file mode 100644
index 0000000000..1eac8c17d4
--- /dev/null
+++ b/js/src/jit-test/tests/closures/t016.js
@@ -0,0 +1,23 @@
+actual = '';
+expected = '0,0,0,1,1,1,2,2,2,3,3,3,4,4,4,';
+
+function g(a) {
+ for (var i = 0; i < 3; ++i) {
+ a();
+ }
+}
+
+function f(y) {
+ var q;
+ for (var i = 0; i < 7; ++i) {
+ q = function() { appendToActual(y); };
+ }
+ g(q);
+}
+
+for (var i = 0; i < 5; ++i) {
+ f(i);
+ }
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/t017.js b/js/src/jit-test/tests/closures/t017.js
new file mode 100644
index 0000000000..92acf013de
--- /dev/null
+++ b/js/src/jit-test/tests/closures/t017.js
@@ -0,0 +1,23 @@
+actual = '';
+expected = '0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,';
+
+function g(a) {
+ for (var i = 0; i < 3; ++i) {
+ a();
+ }
+}
+
+function f(y) {
+ var q;
+ for (var i = 0; i < 7; ++i) {
+ q = function() { appendToActual(y); };
+ g(q);
+ }
+}
+
+for (var i = 0; i < 5; ++i) {
+ f(i);
+ }
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/t020.js b/js/src/jit-test/tests/closures/t020.js
new file mode 100644
index 0000000000..30c8b463df
--- /dev/null
+++ b/js/src/jit-test/tests/closures/t020.js
@@ -0,0 +1,17 @@
+actual = '';
+expected = '0,0,1,1,2,2,3,3,';
+
+{ let f = function() {
+ for (let x = 0; x < 4; ++x) {
+ (function() {
+ for (let y = 0; y < 2; ++y) {
+ appendToActual(x);
+ }
+ })()
+ }
+};
+ f(0)
+}
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/t021.js b/js/src/jit-test/tests/closures/t021.js
new file mode 100644
index 0000000000..62052383b1
--- /dev/null
+++ b/js/src/jit-test/tests/closures/t021.js
@@ -0,0 +1,18 @@
+actual = '';
+expected = 'nocrash,';
+
+var v = {};
+
+function a() {
+ var o = 3;
+ v.f = function() { return o; };
+}
+
+for (i = 0; i < 6; i++)
+ new a;
+
+
+appendToActual('nocrash')
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/t022.js b/js/src/jit-test/tests/closures/t022.js
new file mode 100644
index 0000000000..20d73babbe
--- /dev/null
+++ b/js/src/jit-test/tests/closures/t022.js
@@ -0,0 +1,24 @@
+actual = '';
+expected = 'nocrash,';
+
+function jQuery(a, c) {
+}
+jQuery.fn = {};
+(function() {
+ var e =
+["ajaxStart","ajaxStop","ajaxComplete","ajaxError","ajaxSuccess","ajaxSend"];
+ for (var i = 0; i < e.length; i++) {
+ new function() {
+ var o = e[i];
+ jQuery.fn[o] = function(f) {
+ return this.bind(o, f);
+ }
+ };
+ }
+})();
+
+
+appendToActual('nocrash')
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/t023.js b/js/src/jit-test/tests/closures/t023.js
new file mode 100644
index 0000000000..0cddac3752
--- /dev/null
+++ b/js/src/jit-test/tests/closures/t023.js
@@ -0,0 +1,17 @@
+actual = '';
+expected = '0,1,2,0,1,2,';
+
+for (var a = 0; a < 2; ++a) {
+ for (var b = 0; b < 3; ++b) {
+ (function (x) {
+ (function () {
+ for (var c = 0; c < 1; ++c) {
+ appendToActual(x);
+ }
+ })();
+ })(b);
+ }
+}
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/t024.js b/js/src/jit-test/tests/closures/t024.js
new file mode 100644
index 0000000000..fc874c63d8
--- /dev/null
+++ b/js/src/jit-test/tests/closures/t024.js
@@ -0,0 +1,19 @@
+actual = '';
+expected = '787878,';
+
+var q = [];
+for (var a = 0; a < 3; ++a) {
+ (function () {
+ for (var b = 7; b < 9; ++b) {
+ (function () {
+ for (var c = 0; c < 1; ++c) {
+ q.push(b);
+ }
+ })();
+ }
+ })();
+}
+appendToActual(q.join(""));
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/t025.js b/js/src/jit-test/tests/closures/t025.js
new file mode 100644
index 0000000000..5adb253b55
--- /dev/null
+++ b/js/src/jit-test/tests/closures/t025.js
@@ -0,0 +1,26 @@
+actual = '';
+expected = '2,5,';
+
+function loop(f) {
+ var p;
+ for (var i = 0; i < 1000; ++i) {
+ p = f();
+ }
+ return p;
+}
+
+function f(k) {
+ function g() {
+ return k;
+ }
+
+ k = 2;
+ appendToActual(loop(g));
+ k = 5;
+ appendToActual(loop(g));
+}
+
+f();
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/t026.js b/js/src/jit-test/tests/closures/t026.js
new file mode 100644
index 0000000000..12063a7501
--- /dev/null
+++ b/js/src/jit-test/tests/closures/t026.js
@@ -0,0 +1,22 @@
+actual = '';
+expected = '101,nocrash,';
+
+function looper(f) {
+ for (var i = 0; i < 10; ++i) {
+ for (var j = 0; j < 10; ++j) {
+ f();
+ }
+ }
+}
+
+function tester() {
+ var x = 1;
+ looper(function() { ++x; });
+ return x;
+}
+
+appendToActual(tester());
+appendToActual("nocrash");
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/t027.js b/js/src/jit-test/tests/closures/t027.js
new file mode 100644
index 0000000000..423fb52a02
--- /dev/null
+++ b/js/src/jit-test/tests/closures/t027.js
@@ -0,0 +1,21 @@
+actual = '';
+expected = '99,';
+
+function looper(f) {
+ for (var i = 0; i < 10; ++i) {
+ for (var j = 0; j < 10; ++j) {
+ f(10*i + j);
+ }
+ }
+}
+
+function tester() {
+ var x = 1;
+ looper(function(y) { x = y; });
+ return x;
+}
+
+appendToActual(tester());
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/t028.js b/js/src/jit-test/tests/closures/t028.js
new file mode 100644
index 0000000000..b1a6d3a62d
--- /dev/null
+++ b/js/src/jit-test/tests/closures/t028.js
@@ -0,0 +1,23 @@
+actual = '';
+expected = 'undefined,';
+
+function looper(f) {
+ for (var i = 0; i < 10; ++i) {
+ for (var j = 0; j < 10; ++j) {
+ f();
+ }
+ }
+}
+
+function tester() {
+ var x = 1;
+ function f() {
+ return x;
+ }
+ looper(f);
+}
+
+appendToActual(tester());
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/t029.js b/js/src/jit-test/tests/closures/t029.js
new file mode 100644
index 0000000000..be45e78ec4
--- /dev/null
+++ b/js/src/jit-test/tests/closures/t029.js
@@ -0,0 +1,21 @@
+actual = '';
+expected = '101,';
+
+function looper(f) {
+ for (var i = 0; i < 10; ++i) {
+ for (var j = 0; j < 10; ++j) {
+ f();
+ }
+ }
+}
+
+function tester() {
+ var x = 1;
+ looper(function() { ++x; });
+ return x;
+}
+
+appendToActual(tester());
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/t030.js b/js/src/jit-test/tests/closures/t030.js
new file mode 100644
index 0000000000..e0b2b643a1
--- /dev/null
+++ b/js/src/jit-test/tests/closures/t030.js
@@ -0,0 +1,21 @@
+actual = '';
+expected = '2,';
+
+function looper(f) {
+ for (var i = 0; i < 10; ++i) {
+ for (var j = 0; j < 10; ++j) {
+ f();
+ }
+ }
+}
+
+function tester() {
+ var x = 1;
+ looper(function() { x = 2; });
+ return x;
+}
+
+appendToActual(tester());
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/t031.js b/js/src/jit-test/tests/closures/t031.js
new file mode 100644
index 0000000000..33530045a4
--- /dev/null
+++ b/js/src/jit-test/tests/closures/t031.js
@@ -0,0 +1,21 @@
+actual = '';
+expected = '4,4,4,';
+
+function k(f_arg) {
+ for (var i = 0; i < 5; ++i) {
+ f_arg(i);
+ }
+}
+
+function t() {
+ var x = 1;
+ k(function (i) { x = i; });
+ appendToActual(x);
+}
+
+t();
+t();
+t();
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/t032.js b/js/src/jit-test/tests/closures/t032.js
new file mode 100644
index 0000000000..a5be41fe82
--- /dev/null
+++ b/js/src/jit-test/tests/closures/t032.js
@@ -0,0 +1,24 @@
+actual = '';
+expected = '4,';
+
+function k(f_arg) {
+ for (var i = 0; i < 5; ++i) {
+ f_arg(i);
+ }
+}
+
+function t() {
+ var x = 1;
+
+ function u() {
+ k(function (i) { x = i; });
+ appendToActual(x);
+ }
+
+ u();
+}
+
+t();
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/t033.js b/js/src/jit-test/tests/closures/t033.js
new file mode 100644
index 0000000000..e030fbf3c2
--- /dev/null
+++ b/js/src/jit-test/tests/closures/t033.js
@@ -0,0 +1,19 @@
+actual = '';
+expected = '2,';
+
+function k(f_arg) {
+ for (var i = 0; i < 100; ++i) {
+ f_arg();
+ }
+}
+
+function t() {
+ var x = 1;
+ k(function () { x = 2; });
+ appendToActual(x);
+}
+
+t();
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/t034.js b/js/src/jit-test/tests/closures/t034.js
new file mode 100644
index 0000000000..060101ed09
--- /dev/null
+++ b/js/src/jit-test/tests/closures/t034.js
@@ -0,0 +1,20 @@
+actual = '';
+expected = '';
+
+function k(f_arg) {
+ for (var i = 0; i < 10; ++i) {
+ f_arg(i);
+ }
+}
+
+function t() {
+ var x = 1;
+ k(function (i) { x = i; });
+}
+
+for (var i = 0; i < 100; ++i) {
+ t();
+}
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/t035.js b/js/src/jit-test/tests/closures/t035.js
new file mode 100644
index 0000000000..02acc9a98e
--- /dev/null
+++ b/js/src/jit-test/tests/closures/t035.js
@@ -0,0 +1,18 @@
+actual = '';
+expected = '4,';
+
+function k(f_arg) {
+ for (var i = 0; i < 5; ++i) {
+ f_arg(i);
+ }
+}
+
+function t(x) {
+ k(function (i) { x = i; });
+ appendToActual(x);
+}
+
+t(1);
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/t036.js b/js/src/jit-test/tests/closures/t036.js
new file mode 100644
index 0000000000..9e26baff51
--- /dev/null
+++ b/js/src/jit-test/tests/closures/t036.js
@@ -0,0 +1,24 @@
+actual = '';
+expected = '77,77,';
+
+var o = {
+ x: 11,
+ y: 13
+};
+
+function g() {
+ with (o) {
+ var x = 77;
+ for (var i = 0; i < 5; ++i) {
+ var f = function() { appendToActual(x); }
+ }
+ f();
+ }
+
+ f();
+}
+
+g();
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/t037.js b/js/src/jit-test/tests/closures/t037.js
new file mode 100644
index 0000000000..0350c51403
--- /dev/null
+++ b/js/src/jit-test/tests/closures/t037.js
@@ -0,0 +1,14 @@
+actual = '';
+expected = '7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,';
+
+function heavy(s, t, u) {return eval(s)}
+
+for (var i = 0; i < 5; ++i) {
+ var flat = heavy("(function () {var x = t * t; return function(){return x + u}})()", 2, 3);
+ for (var j = 0; j < 5; ++j) {
+ appendToActual(flat());
+ }
+ }
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/test-inner-imports.js b/js/src/jit-test/tests/closures/test-inner-imports.js
new file mode 100644
index 0000000000..8e7e8d05fc
--- /dev/null
+++ b/js/src/jit-test/tests/closures/test-inner-imports.js
@@ -0,0 +1,22 @@
+actual = '';
+expected = '0,0,2,2,4,4,6,6,8,8,';
+
+function g(b) {
+ for (var i = 0; i < 10; ++i) {
+ }
+}
+
+function f(xa_arg) {
+ var xa = xa_arg;
+ for (var i = 0; i < 5; ++i) {
+ var j = i + xa[i];
+ appendToActual(j);
+ g();
+ appendToActual(j);
+ }
+}
+
+f([ 0, 1, 2, 3, 4 ]);
+
+
+assertEq(actual, expected)
diff --git a/js/src/jit-test/tests/closures/upvar-nest.js b/js/src/jit-test/tests/closures/upvar-nest.js
new file mode 100644
index 0000000000..13800111ce
--- /dev/null
+++ b/js/src/jit-test/tests/closures/upvar-nest.js
@@ -0,0 +1,24 @@
+actual = '';
+expected = '0 0 1 1 2 2 3 3,0 0 1 1 2 2 3 3,0 0 1 1 2 2 3 3,0 0 1 1 2 2 3 3,0 0 1 1 2 2 3 3,1 2 2 3 3 4 4 5,1 2 2 3 3 4 4 5,1 2 2 3 3 4 4 5,1 2 2 3 3 4 4 5,1 2 2 3 3 4 4 5,2 4 3 5 4 6 5 7,2 4 3 5 4 6 5 7,2 4 3 5 4 6 5 7,2 4 3 5 4 6 5 7,2 4 3 5 4 6 5 7,3 6 4 7 5 8 6 9,3 6 4 7 5 8 6 9,3 6 4 7 5 8 6 9,3 6 4 7 5 8 6 9,3 6 4 7 5 8 6 9,4 8 5 9 6 10 7 11,4 8 5 9 6 10 7 11,4 8 5 9 6 10 7 11,4 8 5 9 6 10 7 11,4 8 5 9 6 10 7 11,';
+
+function f(a, b) {
+ function g(x, y) {
+ function h(m, n) {
+ function k(u, v) {
+ for (var i = 0; i < 5; ++i) {
+ appendToActual(a + ' ' + b + ' ' + x + ' ' + y + ' ' + m + ' ' + n + ' ' + u + ' ' + v);
+ }
+ }
+ k(m+1, n+1);
+ }
+ h(x+1, y+1);
+ }
+ g(a+1, b+1);
+}
+
+for (var i = 0; i < 5; ++i) {
+ f(i, i+i);
+}
+
+
+assertEq(actual, expected)