diff options
Diffstat (limited to 'js/src/tests/js1_7/geniter')
49 files changed, 2413 insertions, 0 deletions
diff --git a/js/src/tests/js1_7/geniter/326466-01.js b/js/src/tests/js1_7/geniter/326466-01.js new file mode 100644 index 000000000..4c9bf1ad3 --- /dev/null +++ b/js/src/tests/js1_7/geniter/326466-01.js @@ -0,0 +1,45 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 326466; +var summary = 'Implement Pythonic generators and iteration protocol support'; +var actual; +var expect; + +printBugNumber(BUGNUMBER); +printStatus (summary); + +function fib() +{ + var a = 0, b = 1; + + while (true) + { + yield a; + var t = a; + a = b; + b += t; + } +} + +var g = fib(); + +expect = '[object Generator]'; +actual = g.toString(); +reportCompare(expect, actual, summary); + +var actual = []; +var expect = [0, 1, 1, 2, 3, 5, 8, 13]; +actual.push(g.next()); +actual.push(g.next()); +actual.push(g.next()); +actual.push(g.next()); +actual.push(g.next()); +actual.push(g.next()); +actual.push(g.next()); +actual.push(g.next()); +reportCompare(expect.join(), actual.join(), summary); + diff --git a/js/src/tests/js1_7/geniter/browser.js b/js/src/tests/js1_7/geniter/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/js1_7/geniter/browser.js diff --git a/js/src/tests/js1_7/geniter/builtin-Iterator-function.js b/js/src/tests/js1_7/geniter/builtin-Iterator-function.js new file mode 100644 index 000000000..01b659e7d --- /dev/null +++ b/js/src/tests/js1_7/geniter/builtin-Iterator-function.js @@ -0,0 +1,89 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = "(none)"; +var summary = "Iterator() test"; +var actual, expect; + +printBugNumber(BUGNUMBER); +printStatus(summary); + +/************** + * BEGIN TEST * + **************/ + +var failed = false; + +function Array_equals(a, b) +{ + if (!(a instanceof Array) || !(b instanceof Array)) + throw new Error("Arguments not both of type Array"); + if (a.length != b.length) + return false; + for (var i = 0, sz = a.length; i < sz; i++) + if (a[i] !== b[i]) + return false; + return true; +} + +var meow = "meow", oink = "oink", baa = "baa"; + +var it = Iterator([meow, oink, baa]); +var it2 = Iterator([meow, oink, baa], true); + +try +{ + if (!Array_equals(it.next(), [0, meow])) + throw [0, meow]; + if (!Array_equals(it.next(), [1, oink])) + throw [1, oink]; + if (!Array_equals(it.next(), [2, baa])) + throw [2, baa]; + + var stopPassed = false; + try + { + it.next(); + } + catch (e) + { + if (e === StopIteration) + stopPassed = true; + } + + if (!stopPassed) + throw "it: missing or incorrect StopIteration"; + + if (it2.next() != 0) + throw "wanted key=0"; + if (it2.next() != 1) + throw "wanted key=1"; + if (it2.next() != 2) + throw "wanted key=2"; + + var stopPassed = false; + try + { + it2.next(); + } + catch (e) + { + if (e === StopIteration) + stopPassed = true; + } + + if (!stopPassed) + throw "it2: missing or incorrect StopIteration"; +} +catch (e) +{ + failed = e; +} + +expect = false; +actual = failed; + +reportCompare(expect, actual, summary); diff --git a/js/src/tests/js1_7/geniter/close-returns-undefined.js b/js/src/tests/js1_7/geniter/close-returns-undefined.js new file mode 100644 index 000000000..a1f81ec5b --- /dev/null +++ b/js/src/tests/js1_7/geniter/close-returns-undefined.js @@ -0,0 +1,20 @@ +function gen() { + yield 3; +} + +var g = gen(); +assertEq(g.close(), undefined); + +var h = gen(); +assertEq(h.next(), 3); +var caught = false; +try { + h.next(); +} catch (e) { + caught = true; + assertEq(e instanceof StopIteration, true); +} +assertEq(caught, true); +assertEq(h.close(), undefined); + +reportCompare(); diff --git a/js/src/tests/js1_7/geniter/fibonacci-matrix-generator.js b/js/src/tests/js1_7/geniter/fibonacci-matrix-generator.js new file mode 100644 index 000000000..e1c9efb13 --- /dev/null +++ b/js/src/tests/js1_7/geniter/fibonacci-matrix-generator.js @@ -0,0 +1,64 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = "(none)"; +var summary = "Fibonacci generator by matrix multiplication"; +var actual, expect; + +printBugNumber(BUGNUMBER); +printStatus(summary); + +/************** + * BEGIN TEST * + **************/ + +function fib() +{ + var init = [1, 0]; + var mx = [[1, 1], [1, 0]]; + while (true) + { + yield init[1]; + var tmp = [,]; + tmp[0] = + mx[0][0]*init[0] + mx[0][1]*init[1]; + tmp[1] = + mx[1][0]*init[0] + mx[1][1]*init[1]; + init = tmp; + } +} + +var failed = false; +var it = fib(); + +try +{ + if (it.next() != 0) + throw "F_0 failed"; + if (it.next() != 1) + throw "F_1 failed"; + if (it.next() != 1) + throw "F_2 failed"; + if (it.next() != 2) + throw "F_3 failed"; + if (it.next() != 3) + throw "F_4 failed"; + if (it.next() != 5) + throw "F_5 failed"; + if (it.next() != 8) + throw "F_6 failed"; +} +catch (e) +{ + failed = e; +} + + + +expect = false; +actual = failed; + +reportCompare(expect, actual, summary); diff --git a/js/src/tests/js1_7/geniter/gen-with-call-obj.js b/js/src/tests/js1_7/geniter/gen-with-call-obj.js new file mode 100644 index 000000000..90c6f09c5 --- /dev/null +++ b/js/src/tests/js1_7/geniter/gen-with-call-obj.js @@ -0,0 +1,36 @@ +var foo; + +function gen() { + var x = 0; + foo = function() { return x++; } + for (var i = 0; i < 10; ++i) + yield x++; +} + +var j = 0; +for (i in gen()) + assertEq(i, j++); + +// now mess up the stack + +function f1(x) { + var a, b, c, d, e, f, g; + return x <= 0 ? 0 : f1(x-1); +} +f1(10); +function f2(x) { + var a = x, b = x; + return x <= 0 ? 0 : f2(x-1); +} +f2(10); + +// now observe gen's call object (which should have been put) + +gc(); +assertEq(foo(), 10); +gc(); +assertEq(foo(), 11); +gc(); +assertEq(foo(), 12); + +reportCompare(true,true); diff --git a/js/src/tests/js1_7/geniter/iterator-toString.js b/js/src/tests/js1_7/geniter/iterator-toString.js new file mode 100644 index 000000000..686ec0c8b --- /dev/null +++ b/js/src/tests/js1_7/geniter/iterator-toString.js @@ -0,0 +1,43 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = "(none)"; +var summary = "gen.toString() omitting 'yield' from value"; +var actual, expect; + +printBugNumber(BUGNUMBER); +printStatus(summary); + +/************** + * BEGIN TEST * + **************/ + +var failed = false; + +function gen() +{ + yield 17; +} + +try +{ + var str = gen.toString(); + var index = str.search(/yield/); + + if (index < 0) + throw "yield not found in str: " + str; +} +catch (e) +{ + failed = e; +} + + + +expect = false; +actual = failed; + +reportCompare(expect, actual, summary); diff --git a/js/src/tests/js1_7/geniter/message-value-passing.js b/js/src/tests/js1_7/geniter/message-value-passing.js new file mode 100644 index 000000000..626c788be --- /dev/null +++ b/js/src/tests/js1_7/geniter/message-value-passing.js @@ -0,0 +1,88 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 326466; +var summary = "Generator value/exception passing"; +var actual, expect; + +printBugNumber(BUGNUMBER); +printStatus(summary); + +/************** + * BEGIN TEST * + **************/ + +function gen() +{ + var rv, rv2, rv3, rv4; + rv = yield 1; + + if (rv) + rv2 = yield rv; + else + rv3 = yield 2; + + try + { + if (rv2) + yield rv2; + else + rv3 = yield 3; + } + catch (e) + { + if (e == 289) + yield "exception caught"; + } + + yield 5; +} + +var failed = false; +var it = gen(); + +try +{ + if (it.next() != 1) + throw "failed on 1"; + + if (it.send(17) != 17) + throw "failed on 17"; + + if (it.next() != 3) + throw "failed on 3"; + + if (it.throw(289) != "exception caught") + throw "it.throw(289) failed"; + + if (it.next() != 5) + throw "failed on 5"; + + var stopPassed = false; + try + { + it.next(); + } + catch (e) + { + if (e === StopIteration) + stopPassed = true; + } + + if (!stopPassed) + throw "missing or incorrect StopIteration"; +} +catch (e) +{ + failed = e; +} + + + +expect = false; +actual = failed; + +reportCompare(expect, actual, summary); diff --git a/js/src/tests/js1_7/geniter/multiple-close.js b/js/src/tests/js1_7/geniter/multiple-close.js new file mode 100644 index 000000000..7864459ef --- /dev/null +++ b/js/src/tests/js1_7/geniter/multiple-close.js @@ -0,0 +1,65 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = "(none)"; +var summary = "calling it.close multiple times is harmless"; +var actual, expect; + +printBugNumber(BUGNUMBER); +printStatus(summary); + +/************** + * BEGIN TEST * + **************/ + +function fib() +{ + yield 0; // 0 + yield 1; // 1 + yield 1; // 2 + yield 2; // 3 + yield 3; // 4 + yield 5; // 5 + yield 8; // 6 +} + +var failed = false; +var it = fib(); + +try +{ + if (it.next() != 0) + throw "0 failed"; + + // closing an already-closed generator is a no-op + it.close(); + it.close(); + it.close(); + + var stopPassed = false; + try + { + it.next(); + } + catch (e) + { + if (e === StopIteration) + stopPassed = true; + } + if (!stopPassed) + throw "a closed iterator throws StopIteration on next"; +} +catch (e) +{ + failed = e; +} + + + +expect = false; +actual = failed; + +reportCompare(expect, actual, summary); diff --git a/js/src/tests/js1_7/geniter/nested-yield.js b/js/src/tests/js1_7/geniter/nested-yield.js new file mode 100644 index 000000000..a5a1bf59e --- /dev/null +++ b/js/src/tests/js1_7/geniter/nested-yield.js @@ -0,0 +1,58 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = "(none)"; +var summary = "YieldExpression is and contains an AssignmentExpression"; +var actual, expect; + +printBugNumber(BUGNUMBER); +printStatus(summary); + +/************** + * BEGIN TEST * + **************/ + +var failed = false; + +function gen() +{ + yield (yield (yield 7)); +} + +var it = gen(); + +try +{ + if (it.next() != 7) + throw "7 not yielded"; + if (it.send(17) != 17) + throw "passed-in 17 not yielded"; + if (it.send(undefined) !== undefined) + throw "should be able to yield undefined"; + + var stopPassed = false; + try + { + it.next(); + } + catch (e) + { + if (e === StopIteration) + stopPassed = true; + } + + if (!stopPassed) + throw "it: missing or incorrect StopIteration"; +} +catch (e) +{ + failed = e; +} + +expect = false; +actual = failed; + +reportCompare(expect, actual, summary); diff --git a/js/src/tests/js1_7/geniter/pi-generator.js b/js/src/tests/js1_7/geniter/pi-generator.js new file mode 100644 index 000000000..5be593ab4 --- /dev/null +++ b/js/src/tests/js1_7/geniter/pi-generator.js @@ -0,0 +1,59 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = "(none)"; +var summary = "A (slow) generator of pi"; +var actual, expect; + +printBugNumber(BUGNUMBER); +printStatus(summary); + +/************** + * BEGIN TEST * + **************/ + +function pi() +{ + var val = 0; + var curr = 1; + var isNeg = false; + while (true) + { + if (isNeg) + yield val -= 4/curr; + else + yield val += 4/curr; + curr += 2; + isNeg = !isNeg; + } +} + +var failed = false; +var it = pi(); + +var vals = + [4, + 4 - 4/3, + 4 - 4/3 + 4/5, + 4 - 4/3 + 4/5 - 4/7]; + +try +{ + for (var i = 0, sz = vals.length; i < sz; i++) + if (it.next() != vals[i]) + throw vals[i]; +} +catch (e) +{ + failed = e; +} + + + +expect = false; +actual = failed; + +reportCompare(expect, actual, summary); diff --git a/js/src/tests/js1_7/geniter/regress-345855.js b/js/src/tests/js1_7/geniter/regress-345855.js new file mode 100644 index 000000000..a88ccd440 --- /dev/null +++ b/js/src/tests/js1_7/geniter/regress-345855.js @@ -0,0 +1,93 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 345855; +var summary = 'Blank yield expressions are not syntax errors'; +var actual = ''; +var expect = 'No Error'; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + expect = "SyntaxError"; + try + { + eval('(function() {x = 12 + yield;})'); + actual = 'No Error'; + } + catch(ex) + { + actual = ex.name; + } + reportCompare(expect, actual, summary + ': function() {x = 12 + yield;}'); + + expect = "SyntaxError"; + try + { + eval('(function() {x = 12 + yield 42})'); + actual = 'No Error'; + } + catch(ex) + { + actual = ex.name; + } + reportCompare(expect, actual, summary + ': function() {x = 12 + yield 42}'); + + expect = 'No Error'; + try + { + eval('(function() {x = 12 + (yield);})'); + actual = 'No Error'; + } + catch(ex) + { + actual = ex + ''; + } + reportCompare(expect, actual, summary + ': function() {x = 12 + (yield);}'); + + try + { + eval('(function () {foo((yield))})'); + actual = 'No Error'; + } + catch(ex) + { + actual = ex + ''; + } + reportCompare(expect, actual, summary + ': function () {foo((yield))}'); + + try + { + eval('(function() {x = 12 + (yield 42)})'); + actual = 'No Error'; + } + catch(ex) + { + actual = ex + ''; + } + reportCompare(expect, actual, summary + ': function() {x = 12 + (yield 42)}'); + + try + { + eval('(function (){foo((yield 42))})'); + actual = 'No Error'; + } + catch(ex) + { + actual = ex + ''; + } + reportCompare(expect, actual, summary + ': function (){foo((yield 42))}'); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_7/geniter/regress-345879-01.js b/js/src/tests/js1_7/geniter/regress-345879-01.js new file mode 100644 index 000000000..540852a23 --- /dev/null +++ b/js/src/tests/js1_7/geniter/regress-345879-01.js @@ -0,0 +1,33 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 345879; +var summary = 'Crash when calling a function from a generator with less arguments than its arity '; +var actual = 'No Crash'; +var expect = 'No Crash'; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + function gen() { + yield isNaN(); + } + + f = gen(); + f.next(); + + reportCompare(expect, actual, summary); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_7/geniter/regress-345879-02.js b/js/src/tests/js1_7/geniter/regress-345879-02.js new file mode 100644 index 000000000..aec3d81a1 --- /dev/null +++ b/js/src/tests/js1_7/geniter/regress-345879-02.js @@ -0,0 +1,34 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 345879; +var summary = 'Crash when calling a function from a generator with less arguments than its arity '; +var actual = 'No Crash'; +var expect = 'No Crash'; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + function gen() { + (yield 5)(); + yield; + } + f = gen(); + f.next(); + f.send(Function()); + + reportCompare(expect, actual, summary); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_7/geniter/regress-347593.js b/js/src/tests/js1_7/geniter/regress-347593.js new file mode 100644 index 000000000..353d9412c --- /dev/null +++ b/js/src/tests/js1_7/geniter/regress-347593.js @@ -0,0 +1,60 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 347593; +var summary = 'For-each loop with destructuring assignment'; +var actual = ''; +var expect = ''; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + // Before JS1.7's destructuring for…in was fixed to match JS1.8's, + // the expected result was '23'. + expect = 'TypeError'; + actual = ''; + try { + for (let [, { a: b }] in [{ a: 2 }, { a: 3 }]) { + actual += b; + } + reportCompare(expect, actual, summary); + } catch (ex) { + actual = ex.name; + } + + expect = '23'; + actual = ''; + for each (let { a: b } in [{ a: 2 }, { a: 3 }]) + { + actual += b; + } + reportCompare(expect, actual, summary); + + expect = 'TypeError'; + actual = ''; + try + { + for each (let [, { a: b }] in [{ a: 2 }, { a: 3 }]) + { + actual += b; + } + } + catch(ex) + { + actual = ex.name; + } + reportCompare(expect, actual, summary); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_7/geniter/regress-347739.js b/js/src/tests/js1_7/geniter/regress-347739.js new file mode 100644 index 000000000..46c749ec7 --- /dev/null +++ b/js/src/tests/js1_7/geniter/regress-347739.js @@ -0,0 +1,49 @@ +// |reftest| skip -- obsolete test +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 347739; +var summary = 'generator_instance.close readonly and immune'; +var actual = ''; +var expect = ''; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + function gen_test(test_index) + { + try { + yield 1; + } finally { + actual += "Inside finally: "+test_index + ' '; + } + } + + actual = ''; + expect = 'Inside finally: 1 Inside finally: 2 '; + + var iter1 = gen_test(1); + iter1.next(); + iter1.close = null; + iter1 = null; + gc(); + + var iter2 = gen_test(2); + for (i in iter2) + iter2.close = null; + + reportCompare(expect, actual, summary + ': 2'); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_7/geniter/regress-349012-01.js b/js/src/tests/js1_7/geniter/regress-349012-01.js new file mode 100644 index 000000000..297b03732 --- /dev/null +++ b/js/src/tests/js1_7/geniter/regress-349012-01.js @@ -0,0 +1,52 @@ +// |reftest| skip -- obsolete test +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 349012; +var summary = 'closing a generator fails to report error if yield during close is ignored'; +var actual = ''; +var expect = ''; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +if (typeof quit != 'undefined') +{ + quit(0); +} + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + expect = "Inner finally,Outer finally"; + + function gen() + { + try { + try { + yield 1; + } finally { + actual += "Inner finally"; + yield 2; + } + } finally { + actual += ",Outer finally"; + } + } + + var iter = gen(); + iter.next(); + iter = null; + gc(); + + reportCompare(expect, actual, summary); + exitFunc ('test'); +} diff --git a/js/src/tests/js1_7/geniter/regress-349012-02.js b/js/src/tests/js1_7/geniter/regress-349012-02.js new file mode 100644 index 000000000..5c78423cd --- /dev/null +++ b/js/src/tests/js1_7/geniter/regress-349012-02.js @@ -0,0 +1,61 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 349012; +var summary = 'generators with nested try finally blocks'; +var actual = ''; +var expect = ''; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + expect = "[object StopIteration]"; + var expectyield = "12"; + var expectfinally = "Inner finally,Outer finally"; + var actualyield = ""; + var actualfinally = ""; + + function gen() + { + try { + try { + yield 1; + } finally { + actualfinally += "Inner finally"; + yield 2; + } + } finally { + actualfinally += ",Outer finally"; + } + } + + var iter = gen(); + actualyield += iter.next(); + actualyield += iter.next(); + try + { + actualyield += iter.next(); + actual = "No exception"; + } + catch(ex) + { + actual = ex + ''; + } + + reportCompare(expect, actual, summary); + reportCompare(expectyield, actualyield, summary); + reportCompare(expectfinally, actualfinally, summary); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_7/geniter/regress-349012-03.js b/js/src/tests/js1_7/geniter/regress-349012-03.js new file mode 100644 index 000000000..4d1747597 --- /dev/null +++ b/js/src/tests/js1_7/geniter/regress-349012-03.js @@ -0,0 +1,42 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 349012; +var summary = 'generator recursively calling itself via send is a TypeError'; +var actual = ''; +var expect = ''; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + function gen() { + var iter = yield; + try { + iter.send(1); + } catch (e) { + yield e; + } + } + + expect = true; + var iter = gen(); + iter.next(); + var ex = iter.send(iter); + print(ex + ''); + actual = (ex instanceof TypeError); + + reportCompare(expect, actual, summary); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_7/geniter/regress-349012-04.js b/js/src/tests/js1_7/geniter/regress-349012-04.js new file mode 100644 index 000000000..705bbd909 --- /dev/null +++ b/js/src/tests/js1_7/geniter/regress-349012-04.js @@ -0,0 +1,42 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 349012; +var summary = 'generator recursively calling itself via next is an Error'; +var actual = ''; +var expect = ''; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + function gen() { + var iter = yield; + try { + iter.next(1); + } catch (e) { + yield e; + } + } + + expect = true; + var iter = gen(); + iter.next(); + var ex = iter.send(iter); + print(ex + ''); + actual = (ex instanceof TypeError); + + reportCompare(expect, actual, summary); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_7/geniter/regress-349012-05.js b/js/src/tests/js1_7/geniter/regress-349012-05.js new file mode 100644 index 000000000..5eb442b9a --- /dev/null +++ b/js/src/tests/js1_7/geniter/regress-349012-05.js @@ -0,0 +1,43 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 349012; +var summary = 'generator recursively calling itself via close is an Error'; +var actual = ''; +var expect = ''; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + var iter; + function gen() { + iter.close(); + yield 1; + } + + expect = /TypeError.*[aA]lready executing generator/; + try + { + iter = gen(); + var i = iter.next(); + print("i="+i); + } + catch(ex) + { + actual = ex + ''; + } + reportMatch(expect, actual, summary); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_7/geniter/regress-349023-01.js b/js/src/tests/js1_7/geniter/regress-349023-01.js new file mode 100644 index 000000000..3eab5eb94 --- /dev/null +++ b/js/src/tests/js1_7/geniter/regress-349023-01.js @@ -0,0 +1,42 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 349023; +var summary = 'Bogus JSCLASS_IS_EXTENDED in the generator class'; +var actual = 'No Crash'; +var expect = 'No Crash'; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + function gen() { + var i = 0; + yield i; + } + + try + { + var g = gen(); + for (var i = 0; i < 10; i++) { + print(g.next()); + } + } + catch(ex) + { + } + + reportCompare(expect, actual, summary); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_7/geniter/regress-349023-02.js b/js/src/tests/js1_7/geniter/regress-349023-02.js new file mode 100644 index 000000000..25bde697c --- /dev/null +++ b/js/src/tests/js1_7/geniter/regress-349023-02.js @@ -0,0 +1,29 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 349023; +var summary = 'Bogus JSCLASS_IS_EXTENDED in the generator class'; +var actual = 'No Crash'; +var expect = 'No Crash'; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + var gen = (function() { yield 3; })(); + gen.foopy; + + reportCompare(expect, actual, summary); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_7/geniter/regress-349023-03.js b/js/src/tests/js1_7/geniter/regress-349023-03.js new file mode 100644 index 000000000..26201061d --- /dev/null +++ b/js/src/tests/js1_7/geniter/regress-349023-03.js @@ -0,0 +1,29 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 349023; +var summary = 'Bogus JSCLASS_IS_EXTENDED in the generator class'; +var actual = 'No Crash'; +var expect = 'No Crash'; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + var gen = (function() { yield 3; })(); + var x = (gen ==gen); + + reportCompare(expect, actual, summary); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_7/geniter/regress-349331.js b/js/src/tests/js1_7/geniter/regress-349331.js new file mode 100644 index 000000000..091fbb1f0 --- /dev/null +++ b/js/src/tests/js1_7/geniter/regress-349331.js @@ -0,0 +1,95 @@ +// |reftest| skip -- obsolete test +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 349331; +var summary = 'generator.close without GeneratorExit'; +var actual = ''; +var expect = ''; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + var catch1, catch2, catch3, finally1, finally2, finally3; + var iter; + + function gen() + { + yield 1; + try { + try { + try { + yield 1; + } catch (e) { + catch1 = true; + } finally { + finally1 = true; + } + } catch (e) { + catch2 = true; + } finally { + finally2 = true; + } + } catch (e) { + catch3 = true; + } finally { + finally3 = true; + } + } + +// test explicit close call + catch1 = catch2 = catch3 = finally1 = finally2 = finally3 = false; + iter = gen(); + iter.next(); + iter.next(); + iter.close(); + + var passed = !catch1 && !catch2 && !catch3 && finally1 && finally2 && + finally3; + + if (!passed) { + print("Failed!"); + print("catch1=" + catch1 + " catch2=" + catch2 + " catch3=" + + catch3); + print("finally1=" + finally1 + " finally2=" + finally2 + + " finally3=" + finally3); + } + + reportCompare(true, passed, 'test explicit close call'); + +// test GC-invoked close + catch1 = catch2 = catch3 = finally1 = finally2 = finally3 = false; + iter = gen(); + iter.next(); + iter.next(); + iter = null; + gc(); + gc(); + + var passed = !catch1 && !catch2 && !catch3 && finally1 && finally2 && + finally3; + + if (!passed) { + print("Failed!"); + print("catch1=" + catch1 + " catch2=" + catch2 + " catch3=" + + catch3); + print("finally1=" + finally1 + " finally2=" + finally2 + + " finally3="+finally3); + } + reportCompare(true, passed, 'test GC-invoke close'); + + reportCompare(expect, actual, summary); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_7/geniter/regress-349362.js b/js/src/tests/js1_7/geniter/regress-349362.js new file mode 100644 index 000000000..e87c25d16 --- /dev/null +++ b/js/src/tests/js1_7/geniter/regress-349362.js @@ -0,0 +1,29 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 349362; +var summary = 'generator toString should be [object Generator]'; +var actual = ''; +var expect = '[object Generator]'; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + var y = function(){ yield 3}; + actual = y().toString(); + + reportCompare(expect, actual, summary); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_7/geniter/regress-349851.js b/js/src/tests/js1_7/geniter/regress-349851.js new file mode 100644 index 000000000..efd4ee626 --- /dev/null +++ b/js/src/tests/js1_7/geniter/regress-349851.js @@ -0,0 +1,36 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 349851; +var summary = 'decompilation of yield \\n, 3'; +var actual = ''; +var expect = 'SyntaxError'; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + // note the newline after yield is required for this test + try + { + var f = eval('function(){ yield \n,3 }'); + } + catch(ex) + { + actual = ex.name; + } + + reportCompare(expect, actual, summary); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_7/geniter/regress-350621.js b/js/src/tests/js1_7/geniter/regress-350621.js new file mode 100644 index 000000000..60d7d5491 --- /dev/null +++ b/js/src/tests/js1_7/geniter/regress-350621.js @@ -0,0 +1,63 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 350621; +var summary = 'for-in loops over generator objects'; +var actual = ''; +var expect = ''; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + var LOOPS = 500; + + function gen1() { + for (var a = 1; a <= LOOPS; ++a) + yield; + } + + function gen2() { + for (var b in gen1()) + yield; + } + + function test_it(RUNS) { + for (var c = 1; c <= RUNS; ++c) { + var count = 0; + for (var d in gen2()) { + // The next line is needed to demonstrate the bug. + // Note that simply omitting the "x" triggers the bug far less often. + Object("x"); + ++count; + } + if (count != LOOPS) { + print("Test run " + c + ": test failed, count = " + count + + ", should be " + LOOPS); + var failed = true; + } + } + actual = !failed; + if (!failed) + { + print("Test passed."); + } + } + + expect = true; + test_it(20); + + reportCompare(expect, actual, summary); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_7/geniter/regress-350809.js b/js/src/tests/js1_7/geniter/regress-350809.js new file mode 100644 index 000000000..fd1f600c8 --- /dev/null +++ b/js/src/tests/js1_7/geniter/regress-350809.js @@ -0,0 +1,36 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 350809; +var summary = 'Do not assertion: if yield in xml filtering predicate'; +var actual = 'No Crash'; +var expect = 'No Crash'; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + try + { + eval('(function(){ <x/>.(yield 4) })().next();'); + } + catch(ex) + { + actual = expect = + 'InternalError: yield not yet supported from filtering predicate'; + } + + reportCompare(expect, actual, summary); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_7/geniter/regress-351120.js b/js/src/tests/js1_7/geniter/regress-351120.js new file mode 100644 index 000000000..e01c2595a --- /dev/null +++ b/js/src/tests/js1_7/geniter/regress-351120.js @@ -0,0 +1,36 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 351120; +var summary = 'Incorrect error messages with yield expressions'; +var actual = ''; +var expect = ''; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + expect = /TypeError:.*(is not a function|Cannot find function).*/; + actual = ''; + try + { + (function() { yield [].z({}); })().next(); + } + catch(ex) + { + actual = ex + ''; + } + reportMatch(expect, actual, summary); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_7/geniter/regress-352197.js b/js/src/tests/js1_7/geniter/regress-352197.js new file mode 100644 index 000000000..7982e12ee --- /dev/null +++ b/js/src/tests/js1_7/geniter/regress-352197.js @@ -0,0 +1,36 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 352197; +var summary = 'TypeError if yield after return value in a block'; +var actual = ''; +var expect = ''; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + expect = /TypeError: anonymous generator function returns a value/; + try + { + var gen = eval('(function() { { return 5; } yield 3; })'); + actual = 'No Error'; + } + catch(ex) + { + actual = ex + ''; + } + reportMatch(expect, actual, summary); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_7/geniter/regress-352876.js b/js/src/tests/js1_7/geniter/regress-352876.js new file mode 100644 index 000000000..600c82899 --- /dev/null +++ b/js/src/tests/js1_7/geniter/regress-352876.js @@ -0,0 +1,42 @@ +/* -*- tab-width: 2; indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 352876; +var summary = 'Do not assert with nested finally return|yield'; +var actual = ''; +var expect = ''; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + expect = '[object StopIteration]'; + actual = ''; + try + { + var g = (function() { + try { try { } finally { return; } } finally { yield 3; } + })(); + + g.next(); + g.next(); + } + catch(ex) + { + actual = ex + ''; + } + + reportCompare(expect, actual, summary); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_7/geniter/regress-355834.js b/js/src/tests/js1_7/geniter/regress-355834.js new file mode 100644 index 000000000..37624fa53 --- /dev/null +++ b/js/src/tests/js1_7/geniter/regress-355834.js @@ -0,0 +1,30 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 355834; +var summary = 'new Function("yield")'; +var actual = ''; +var expect = ''; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + expect = '[object Generator]'; + var g = (new Function('yield'))(1); + actual = g + ''; + + reportCompare(expect, actual, summary); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_7/geniter/regress-359062.js b/js/src/tests/js1_7/geniter/regress-359062.js new file mode 100644 index 000000000..9a806d7cf --- /dev/null +++ b/js/src/tests/js1_7/geniter/regress-359062.js @@ -0,0 +1,41 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 359062; +var summary = 'Access generator local variables from nested functions'; +var actual = ''; +var expect = ''; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + expect = "Generator string"; + + var scope = "Global"; + + function gen() { + var scope = "Generator"; + function inner() { + actual = scope + " " + typeof scope; + } + inner(); + yield; + } + + gen().next(); + + reportCompare(expect, actual, summary); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_7/geniter/regress-366941.js b/js/src/tests/js1_7/geniter/regress-366941.js new file mode 100644 index 000000000..74ee3a937 --- /dev/null +++ b/js/src/tests/js1_7/geniter/regress-366941.js @@ -0,0 +1,83 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* + * Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/licenses/publicdomain/ + * Contributor: Robert Sayre + */ + + +//----------------------------------------------------------------------------- +var BUGNUMBER = 366941; +var summary = 'Destructuring enumerations, iterations'; +var actual = ''; +var expect = ''; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + var list1 = [[1,2],[3,4],[5,6]]; + var list2 = [[1,2,3],[4,5,6],[7,8,9]]; + + expect = '1,2;3,4;5,6;'; + actual = ''; + + for each (var [foo, bar] in list1) { + actual += foo + "," + bar + ";"; + } + + reportCompare(expect, actual, summary + ': 1'); + + expect = '1,2,3;4,5,6;7,8,9;'; + actual = ''; + for each (var [foo, bar, baz] in list2) { + actual += foo + "," + bar + "," + baz + ";"; + } + + reportCompare(expect, actual, summary + ': 2'); + + function gen(list) { + for each (var test in list) { + yield test; + } + } + + var iter1 = gen(list1); + + expect = '1,2;3,4;5,6;'; + actual = ''; + + for (var [foo, bar] in iter1) { + actual += foo + "," + bar + ";"; + } + + reportCompare(expect, actual, summary + ': 3'); + + // Before JS1.7's destructuring for…in was fixed to match JS1.8's, + // the expected result was a SyntaxError about the for…in loop's lhs. + var iter2 = gen(list2); + expect = '1,2,3;4,5,6;7,8,9;'; + actual = ''; + + try + { + eval('for (var [foo, bar, baz] in iter2) {' + + 'actual += foo + "," + bar + "," + baz + ";";' + + '}'); + } + catch(ex) + { + actual = ex + ''; + } + + reportCompare(expect, actual, summary + ': 4'); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_7/geniter/regress-382335.js b/js/src/tests/js1_7/geniter/regress-382335.js new file mode 100644 index 000000000..357156ce1 --- /dev/null +++ b/js/src/tests/js1_7/geniter/regress-382335.js @@ -0,0 +1,36 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +//----------------------------------------------------------------------------- +var BUGNUMBER = 382335; +var summary = 'Trampolining threads using generators and iterators'; +var actual = ''; +var expect = ''; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + function make_gen() { yield 1; } + + var gen2 = make_gen(); + + gen2.next(); + gen2.close(); + + print(10); + + reportCompare(expect, actual, summary); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_7/geniter/regress-387871.js b/js/src/tests/js1_7/geniter/regress-387871.js new file mode 100644 index 000000000..bb5202dae --- /dev/null +++ b/js/src/tests/js1_7/geniter/regress-387871.js @@ -0,0 +1,41 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +//----------------------------------------------------------------------------- +var BUGNUMBER = 387871; +var summary = 'Do not assert: gen->state != JSGEN_RUNNING && gen->state != JSGEN_CLOSING'; +var actual = 'No Crash'; +var expect = 'No Crash'; + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + var a = gen(); + + try { + a.next(); + throw "a.next() should throw about already invoked generator"; + } catch (e) { + if (!(e instanceof TypeError)) + throw e; + } + + function gen() + { + for (x in a) + yield 1; + } + reportCompare(expect, actual, summary); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_7/geniter/regress-390918.js b/js/src/tests/js1_7/geniter/regress-390918.js new file mode 100644 index 000000000..fdd19e2ad --- /dev/null +++ b/js/src/tests/js1_7/geniter/regress-390918.js @@ -0,0 +1,46 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 390918; +var summary = 'Do not assert: !gen->frame.down" with gc in generator'; +var actual = 'No Crash'; +var expect = 'No Crash'; + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + function gen() + { + var c = [1, "x"]; + gc(); + try { + yield c; + } finally { + gc(); + } + } + + var iter = gen(); + var i; + for (i in iter) { + gc(); + iter.close(); + } + + if (!(i.length === 2 && i[0] === 1 && i[1] === "x")) + throw "Unexpected yield result: "+i; + + reportCompare(expect, actual, summary); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_7/geniter/regress-392310.js b/js/src/tests/js1_7/geniter/regress-392310.js new file mode 100644 index 000000000..a6edd25f7 --- /dev/null +++ b/js/src/tests/js1_7/geniter/regress-392310.js @@ -0,0 +1,42 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 392310; +var summary = 'send on newborn generator'; +var actual = ''; +var expect = ''; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + print("See http://developer.mozilla.org/en/docs/New_in_JavaScript_1.7"); + + function yielder() { + actual = 'before yield'; + yield; + actual = 'after yield'; + } + + var gen = yielder(); + expect = 'before yield'; + gen.send('foo'); + reportCompare(expect, actual, 'send(value) to newborn generator'); + + var gen = yielder(); + expect = 'before yield'; + gen.send(undefined); + reportCompare(expect, actual, 'send(undefined) to newborn generator'); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_7/geniter/regress-466206.js b/js/src/tests/js1_7/geniter/regress-466206.js new file mode 100644 index 000000000..fc6b2fe9e --- /dev/null +++ b/js/src/tests/js1_7/geniter/regress-466206.js @@ -0,0 +1,38 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 466206; +var summary = 'Do not crash due to unrooted function variables'; +var actual = ''; +var expect = ''; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + var f; + + function g() { + var x = {}; + f = function () { x.y; }; + if (0) yield; + } + + try { g().next(); } catch (e) {} + gc(); + f(); + + reportCompare(expect, actual, summary); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_7/geniter/send-no-rhs.js b/js/src/tests/js1_7/geniter/send-no-rhs.js new file mode 100644 index 000000000..e37681ba9 --- /dev/null +++ b/js/src/tests/js1_7/geniter/send-no-rhs.js @@ -0,0 +1,57 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = "(none)"; +var summary = "|it.send(o)| without an RHS"; +var actual, expect; + +printBugNumber(BUGNUMBER); +printStatus(summary); + +/************** + * BEGIN TEST * + **************/ + +var failed = false; + +function gen() +{ + yield 7; + yield 3; +} + +var it = gen(); + +try +{ + if (it.next() != 7) + throw "7 not yielded"; + if (it.send(12) != 3) + throw "3 not yielded"; + + var stopPassed = false; + try + { + it.send(35); // resultant value of |yield 3;| + } + catch (e) + { + if (e === StopIteration) + stopPassed = true; + } + + if (!stopPassed) + throw "it: missing or incorrect StopIteration"; +} +catch (e) +{ + failed = e; +} + +expect = false; +actual = failed; + +reportCompare(expect, actual, summary); diff --git a/js/src/tests/js1_7/geniter/sequential-yields.js b/js/src/tests/js1_7/geniter/sequential-yields.js new file mode 100644 index 000000000..b829907b6 --- /dev/null +++ b/js/src/tests/js1_7/geniter/sequential-yields.js @@ -0,0 +1,72 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = "(none)"; +var summary = "Sequential yields"; +var actual, expect; + +printBugNumber(BUGNUMBER); +printStatus(summary); + +/************** + * BEGIN TEST * + **************/ + +function fib() +{ + yield 0; // 0 + yield 1; // 1 + yield 1; // 2 + yield 2; // 3 + yield 3; // 4 + yield 5; // 5 + yield 8; // 6 +} + +var failed = false; +var it = fib(); + +try +{ + if (it.next() != 0) + throw "0 failed"; + if (it.next() != 1) + throw "1 failed"; + if (it.next() != 1) + throw "2 failed"; + if (it.next() != 2) + throw "3 failed"; + if (it.next() != 3) + throw "4 failed"; + if (it.next() != 5) + throw "5 failed"; + if (it.next() != 8) + throw "6 failed"; + + var stopPassed = false; + try + { + it.next(); + } + catch (e) + { + if (e === StopIteration) + stopPassed = true; + } + if (!stopPassed) + throw "missing or incorrect StopIteration"; +} +catch (e) +{ + failed = e; +} + + + +expect = false; +actual = failed; + +reportCompare(expect, actual, summary); diff --git a/js/src/tests/js1_7/geniter/shell.js b/js/src/tests/js1_7/geniter/shell.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/js1_7/geniter/shell.js diff --git a/js/src/tests/js1_7/geniter/simple-fib.js b/js/src/tests/js1_7/geniter/simple-fib.js new file mode 100644 index 000000000..51c144ab9 --- /dev/null +++ b/js/src/tests/js1_7/geniter/simple-fib.js @@ -0,0 +1,55 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 326466; // bug 326466, comment 1 +var summary = "Simple Fibonacci iterator"; +var actual, expect; + +printBugNumber(BUGNUMBER); +printStatus(summary); + +/************** + * BEGIN TEST * + **************/ + +function fib() +{ + var a = 0, b = 1; + while (true) + { + yield a; + var t = a; + a = b; + b += t; + } +} + +var failed = false; + +try +{ + var g = fib(); + + if (g.next() != 0) + throw "F_0 = 0"; + if (g.next() != 1) + throw "F_1 = 1"; + if (g.next() != 1) + throw "F_2 = 1"; + if (g.next() != 2) + throw "F_3 = 2"; +} +catch (e) +{ + failed = e; +} + + + +expect = false; +actual = failed; + +reportCompare(expect, actual, summary); diff --git a/js/src/tests/js1_7/geniter/throw-after-close.js b/js/src/tests/js1_7/geniter/throw-after-close.js new file mode 100644 index 000000000..3aef5e306 --- /dev/null +++ b/js/src/tests/js1_7/geniter/throw-after-close.js @@ -0,0 +1,90 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = "(none)"; +var summary = "gen.close(); gen.throw(ex) throws ex forever"; +var actual, expect; + +printBugNumber(BUGNUMBER); +printStatus(summary); + +/************** + * BEGIN TEST * + **************/ + +function gen() +{ + var x = 5, y = 7; + var z = x + y; + yield z; +} + +var failed = false; +var it = gen(); + +try +{ + it.close(); + + // throw on closed generators just rethrows + var doThrow = true; + var thrown = "foobar"; + try + { + it.throw(thrown); + } + catch (e) + { + if (e === thrown) + doThrow = false; + } + + if (doThrow) + throw "it.throw(\"" + thrown + "\") failed"; + + // you can throw stuff at a closed generator forever + doThrow = true; + thrown = "sparky"; + try + { + it.throw(thrown); + } + catch (e) + { + if (e === thrown) + doThrow = false; + } + + if (doThrow) + throw "it.throw(\"" + thrown + "\") failed"; + + // don't execute a yield -- the uncaught exception + // exhausted the generator + var stopPassed = false; + try + { + it.next(); + } + catch (e) + { + if (e === StopIteration) + stopPassed = true; + } + + if (!stopPassed) + throw "invalid or incorrect StopIteration"; +} +catch (e) +{ + failed = e; +} + + + +expect = false; +actual = failed; + +reportCompare(expect, actual, summary); diff --git a/js/src/tests/js1_7/geniter/throw-forever.js b/js/src/tests/js1_7/geniter/throw-forever.js new file mode 100644 index 000000000..2e28b39f9 --- /dev/null +++ b/js/src/tests/js1_7/geniter/throw-forever.js @@ -0,0 +1,85 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = "(none)"; +var summary = "gen.throw(ex) returns ex for an exhausted gen"; +var actual, expect; + +printBugNumber(BUGNUMBER); +printStatus(summary); + +/************** + * BEGIN TEST * + **************/ + +function gen() +{ + var x = 5, y = 7; + var z = x + y; + yield z; +} + +var failed = false; +var it = gen(); + +try +{ + // throw works even on newly-initialized generators + var thrown = "foobar"; + var doThrow = true; + try + { + it.throw(thrown); + } + catch (e) + { + if (e === thrown) + doThrow = false; + } + if (doThrow) + throw "it.throw(\"" + thrown + "\") failed"; + + // you can throw stuff at a generator which hasn't + // been used yet forever + thrown = "baz"; + doThrow = true; + try + { + it.throw(thrown); + } + catch (e) + { + if (e === thrown) + doThrow = false; + } + if (doThrow) + throw "it.throw(\"" + thrown + "\") failed"; + + // don't execute a yield -- the uncaught exception + // exhausted the generator + var stopPassed = false; + try + { + it.next(); + } + catch (e) + { + if (e === StopIteration) + stopPassed = true; + } + + if (!stopPassed) + throw "missing or incorrect StopIteration"; +} +catch (e) +{ + failed = e; +} + +expect = false; +actual = failed; + +reportCompare(expect, actual, summary); diff --git a/js/src/tests/js1_7/geniter/unreachable-yield.js b/js/src/tests/js1_7/geniter/unreachable-yield.js new file mode 100644 index 000000000..b1338ff64 --- /dev/null +++ b/js/src/tests/js1_7/geniter/unreachable-yield.js @@ -0,0 +1,57 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = "(none)"; +var summary = "Iterator with unreachable yield statement"; +var actual, expect; + +printBugNumber(BUGNUMBER); +printStatus(summary); + +/************** + * BEGIN TEST * + **************/ + +function gen() +{ + // this is still a generator even if yield can't + // be invoked, because yield is a syntactical + // part of the language + if (false) + yield "failed"; +} + +var failed = false; +try +{ + var it = gen(); + if (it == undefined) + throw "gen() not recognized as generator"; + + // no yields to execute + var stopPassed = false; + try + { + it.next(); + } + catch (e) + { + if (e === StopIteration) + stopPassed = true; + } + + if (!stopPassed) + throw "incorrect or invalid StopIteration"; +} +catch (e) +{ + failed = e; +} + +expect = false; +actual = failed; + +reportCompare(expect, actual, summary); diff --git a/js/src/tests/js1_7/geniter/yield-new.js b/js/src/tests/js1_7/geniter/yield-new.js new file mode 100644 index 000000000..726da3944 --- /dev/null +++ b/js/src/tests/js1_7/geniter/yield-new.js @@ -0,0 +1,28 @@ +const K = 20; + +var obj; + +var g = new function() { + this.x = "puppies"; + obj = this; + for (var i = 0; i < K; ++i) + yield i; + yield this; +} + +var ct = 0; +for (var i in g) + assertEq((ct < K && ct++ == i) || i == obj, true); +assertEq(i.x, "puppies"); + +function g2() { + for (var i=0; i<20; i++) + yield i; +} +var i = 0; +for (var x of new g2()) { + assertEq(i, x); + i++; +} + +reportCompare(true,true); diff --git a/js/src/tests/js1_7/geniter/yield-undefined.js b/js/src/tests/js1_7/geniter/yield-undefined.js new file mode 100644 index 000000000..5e75fb601 --- /dev/null +++ b/js/src/tests/js1_7/geniter/yield-undefined.js @@ -0,0 +1,63 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +// Note that this syntax isn't in the most recently posted ES4 TG1 wiki export, +// either in the specification parts or in the grammar, so this test might be +// Spidermonkey-specific. +var BUGNUMBER = "(none)"; +var summary = "|yield;| is equivalent to |yield undefined;| "; +var actual, expect; + +printBugNumber(BUGNUMBER); +printStatus(summary); + +/************** + * BEGIN TEST * + **************/ + +var failed = false; + +function gen() +{ + yield 7; + yield; + yield 3; +} + +var it = gen(); + +try +{ + if (it.next() != 7) + throw "7 not yielded"; + if (it.next() !== undefined) + throw "|yield;| should be equivalent to |yield undefined;|"; + if (it.next() != 3) + throw "3 not yielded"; + + var stopPassed = false; + try + { + it.next(); + } + catch (e) + { + if (e === StopIteration) + stopPassed = true; + } + + if (!stopPassed) + throw "it: missing or incorrect StopIteration"; +} +catch (e) +{ + failed = e; +} + +expect = false; +actual = failed; + +reportCompare(expect, actual, summary); |