diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /js/src/jit-test/tests/closures | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/jit-test/tests/closures')
98 files changed, 1981 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 000000000..a0aeca1d2 --- /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/bug496987.js b/js/src/jit-test/tests/closures/bug496987.js new file mode 100644 index 000000000..2c4c10efa --- /dev/null +++ b/js/src/jit-test/tests/closures/bug496987.js @@ -0,0 +1,17 @@ +actual = ''; +expected = '0,undefined,0,undefined,1,undefined,0,undefined,1,undefined,0,undefined,1,undefined,nocrash,'; + +// bug 496987 + +for each(let a in ["", "", true, "", true, "", true]) { + appendToActual((function() { + for (var e in [0]) { + appendToActual( + a) + } + })()) +} + +appendToActual('nocrash') + + +assertEq(actual, expected) diff --git a/js/src/jit-test/tests/closures/bug497015-1.js b/js/src/jit-test/tests/closures/bug497015-1.js new file mode 100644 index 000000000..ac0511a31 --- /dev/null +++ b/js/src/jit-test/tests/closures/bug497015-1.js @@ -0,0 +1,19 @@ +actual = ''; +expected = ',0,0,8888,0,0,8888,0,0,/x/,0,0,'; + +for each(let a in ['', 8888, 8888, /x/]) { + ''; + for each(e in ['', false, '']) { + (function(e) { + for each(let c in ['']) { + appendToActual(a); + } + })(); + for (let aa = 0; aa < 1; ++aa) { + a = aa; + } + } +} + + +assertEq(actual, expected) diff --git a/js/src/jit-test/tests/closures/bug497015-2.js b/js/src/jit-test/tests/closures/bug497015-2.js new file mode 100644 index 000000000..0395a18f3 --- /dev/null +++ b/js/src/jit-test/tests/closures/bug497015-2.js @@ -0,0 +1,22 @@ +actual = ''; +expected = 'zzz ,zzz 100,zzz 100,zzz 7777,zzz 100,zzz 100,zzz 8888,zzz 100,zzz 100,zzz /x/,zzz 100,zzz 100,'; + +//function f() { +for each(let a in ['', 7777, 8888, /x/]) { + for each(e in ['', false, '']) { + (function(e) { + for each(let c in ['']) { + appendToActual('zzz ' + a); + } + })(); + for (let aa = 100; aa < 101; ++aa) { + a = aa; + } + } +} +//} + +//f(); + + +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 000000000..ebd3e0203 --- /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 000000000..4584ac350 --- /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/bug540133.js b/js/src/jit-test/tests/closures/bug540133.js new file mode 100644 index 000000000..495f7b0c9 --- /dev/null +++ b/js/src/jit-test/tests/closures/bug540133.js @@ -0,0 +1,4 @@ +(function() { + var x; + eval("for (x in (gc)()) for each(e in [0]) { print }") +})() 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 000000000..56c1a5a31 --- /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 000000000..07faa26b6 --- /dev/null +++ b/js/src/jit-test/tests/closures/bug540243.js @@ -0,0 +1,10 @@ +for (a in (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 000000000..419d33eb5 --- /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 000000000..32e3af156 --- /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 000000000..828688b3a --- /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 000000000..34a59c5fb --- /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 000000000..ab44d5850 --- /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 000000000..ccf5c8270 --- /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 000000000..bab2df6d8 --- /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 000000000..c6f35352d --- /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 000000000..4ec09e9f7 --- /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 000000000..3ac9b5ad1 --- /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-2.js b/js/src/jit-test/tests/closures/flat-closure-2.js new file mode 100644 index 000000000..ae1043097 --- /dev/null +++ b/js/src/jit-test/tests/closures/flat-closure-2.js @@ -0,0 +1,14 @@ +actual = ''; +expected = 'nocrash,'; + +let z = {}; +for (var i = 0; i < 4; ++i) { + for each (var e in [{}, 1, {}]) { + +(function () z)(); + } +} + +appendToActual('nocrash') + + +assertEq(actual, expected) diff --git a/js/src/jit-test/tests/closures/flat-closure-4.js b/js/src/jit-test/tests/closures/flat-closure-4.js new file mode 100644 index 000000000..4d4613e15 --- /dev/null +++ b/js/src/jit-test/tests/closures/flat-closure-4.js @@ -0,0 +1,15 @@ +actual = ''; +expected = ',,,,,[object Object],[object Object],[object Object],[object Object],[object Object],,,,,,[object Object],[object Object],[object Object],[object Object],[object Object],,,,,,[object Object],[object Object],[object Object],[object Object],[object Object],,,,,,[object Object],[object Object],[object Object],[object Object],[object Object],,,,,,'; + +function f() { + var e; + for each (e in ["", {}, "", {}, "", {}, "", {}, ""]) { + var g = function() { for (var i = 0; i < 5; ++i) appendToActual(e); } + g(); + } +} + +f(); + + +assertEq(actual, expected) diff --git a/js/src/jit-test/tests/closures/flat-closure-5.js b/js/src/jit-test/tests/closures/flat-closure-5.js new file mode 100644 index 000000000..f9bd10ae0 --- /dev/null +++ b/js/src/jit-test/tests/closures/flat-closure-5.js @@ -0,0 +1,19 @@ +actual = ''; +expected = 'undefined,[object Object],undefined,[object Object],undefined,[object Object],undefined,[object Object],undefined,[object Object],undefined,[object Object],undefined,[object Object],undefined,[object Object],undefined,[object Object],undefined,[object Object],'; + +function f() { +for (var q = 0; q < 10; ++q) { + for each(let b in [(void 0), {}]) { + (function() { + for (var i = 0; i < 1; ++i) { + appendToActual('' + b) + } + }()) + } +} +} + +f() + + +assertEq(actual, expected) diff --git a/js/src/jit-test/tests/closures/flat-closure-6.js b/js/src/jit-test/tests/closures/flat-closure-6.js new file mode 100644 index 000000000..18a0bcb43 --- /dev/null +++ b/js/src/jit-test/tests/closures/flat-closure-6.js @@ -0,0 +1,17 @@ +actual = ''; +expected = 'bundefined,aundefined,b[object Object],aundefined,bundefined,aundefined,b[object Object],aundefined,bundefined,aundefined,b[object Object],aundefined,bundefined,aundefined,b[object Object],aundefined,bundefined,aundefined,b[object Object],aundefined,bundefined,aundefined,b[object Object],aundefined,bundefined,aundefined,b[object Object],aundefined,bundefined,aundefined,b[object Object],aundefined,bundefined,aundefined,b[object Object],aundefined,bundefined,aundefined,b[object Object],aundefined,'; + +// tests nfixed case of getting slot with let. + +for (var q = 0; q < 10; ++q) { + for each(let b in [(void 0), {}]) { + appendToActual('a' + ((function() { + for (var e in ['']) { + appendToActual('b' + b) + } + })())) + } +} + + +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 000000000..8f653a52f --- /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 () 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 000000000..fb719b0f2 --- /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/incr-exit-2.js b/js/src/jit-test/tests/closures/incr-exit-2.js new file mode 100644 index 000000000..643f0ec6f --- /dev/null +++ b/js/src/jit-test/tests/closures/incr-exit-2.js @@ -0,0 +1,20 @@ +actual = ''; +expected = '-3,'; + +v = 0 +{ let f = function (y) { + { let f = function (g) { + for each(let h in g) { + if (++y > 2) { + appendToActual(h) + } + } + }; + f([(--y), false, true, (--y), false, (--y)]) + } +}; + f(v) +} + + +assertEq(actual, expected) diff --git a/js/src/jit-test/tests/closures/incr-exit.js b/js/src/jit-test/tests/closures/incr-exit.js new file mode 100644 index 000000000..34888b525 --- /dev/null +++ b/js/src/jit-test/tests/closures/incr-exit.js @@ -0,0 +1,20 @@ +actual = ''; +expected = 'ddd,'; + +// Bug 508187 +{ let f = function (y) { + { let ff = function (g) { + for each(let h in g) { + if (++y > 5) { + appendToActual('ddd') + } + } + }; + ff(['', null, '', false, '', '', null]) + } +}; + f(-1) +} + + +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 000000000..eba73cb64 --- /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 000000000..75541baab --- /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 000000000..933da605e --- /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 000000000..7a90fdf77 --- /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 000000000..03fc5ed2c --- /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 000000000..6943e64d6 --- /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 000000000..a0f68486a --- /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 000000000..498083f94 --- /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 000000000..127b097dc --- /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 000000000..34f1d0ea4 --- /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 000000000..b07b02b05 --- /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 000000000..228dfaac4 --- /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 000000000..596028e59 --- /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 000000000..4be0c44c4 --- /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 000000000..1753f2689 --- /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 000000000..08a7d56ff --- /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 000000000..c37b3cc65 --- /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 000000000..72eae0e40 --- /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 000000000..33c89d12e --- /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 000000000..690990891 --- /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 000000000..034a0e197 --- /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 000000000..49b98aa9e --- /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 000000000..458968fb3 --- /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 000000000..c15f3c2e1 --- /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 000000000..f3eb8b8f5 --- /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 000000000..63e3be3f4 --- /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 000000000..b5e30ab2c --- /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 000000000..fd450dd84 --- /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 000000000..cf66c61d3 --- /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 000000000..82adb07fd --- /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 000000000..5aa3b17d0 --- /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 000000000..c07d81b8a --- /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 000000000..33530045a --- /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 000000000..77e817838 --- /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 000000000..4cbf6cf34 --- /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 000000000..de430eb6b --- /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 000000000..a5be41fe8 --- /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 000000000..67052744d --- /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 000000000..1d745a3b5 --- /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 000000000..2e5f833d7 --- /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 000000000..02acc9a98 --- /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 000000000..be45e78ec --- /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 000000000..3ac9b5ad1 --- /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 000000000..95936a768 --- /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 000000000..6a06af8b3 --- /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 000000000..9e2b96b21 --- /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 000000000..2d5005c85 --- /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 000000000..1eac8c17d --- /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 000000000..92acf013d --- /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/t018.js b/js/src/jit-test/tests/closures/t018.js new file mode 100644 index 000000000..846394efe --- /dev/null +++ b/js/src/jit-test/tests/closures/t018.js @@ -0,0 +1,16 @@ +actual = ''; +expected = 'undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,'; + +for (x = 0; x < 10; ++x) { + for each(let a in ['', NaN]) { + appendToActual((function() { + for (let y = 0; y < 1; ++y) { + '' + a + } + })()) + } +} + + + +assertEq(actual, expected) diff --git a/js/src/jit-test/tests/closures/t019.js b/js/src/jit-test/tests/closures/t019.js new file mode 100644 index 000000000..bbd0ade7c --- /dev/null +++ b/js/src/jit-test/tests/closures/t019.js @@ -0,0 +1,16 @@ +actual = ''; +expected = 'undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,'; + +for (x = 0; x < 10; ++x) { + for each(let a in ['', NaN, 3, 5.5, {}]) { + appendToActual((function() { + for (let y = 0; y < 1; ++y) { + '' + a + } + })()) + } +} + + + +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 000000000..30c8b463d --- /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 000000000..62052383b --- /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 000000000..20d73babb --- /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 000000000..0cddac375 --- /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 000000000..fc874c63d --- /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 000000000..5adb253b5 --- /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 000000000..12063a750 --- /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 000000000..423fb52a0 --- /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 000000000..b1a6d3a62 --- /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 000000000..be45e78ec --- /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 000000000..e0b2b643a --- /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 000000000..33530045a --- /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 000000000..a5be41fe8 --- /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 000000000..e030fbf3c --- /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 000000000..060101ed0 --- /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 000000000..02acc9a98 --- /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 000000000..9e26baff5 --- /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 000000000..0350c5140 --- /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 000000000..8e7e8d05f --- /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 000000000..13800111c --- /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) |