diff options
Diffstat (limited to 'js/src/tests/js1_8/genexps')
-rw-r--r-- | js/src/tests/js1_8/genexps/regress-347739.js | 51 | ||||
-rw-r--r-- | js/src/tests/js1_8/genexps/regress-349012-01.js | 54 | ||||
-rw-r--r-- | js/src/tests/js1_8/genexps/regress-349326.js | 148 | ||||
-rw-r--r-- | js/src/tests/js1_8/genexps/regress-384991.js | 59 | ||||
-rw-r--r-- | js/src/tests/js1_8/genexps/regress-665286.js | 33 | ||||
-rw-r--r-- | js/src/tests/js1_8/genexps/regress-683738.js | 71 | ||||
-rw-r--r-- | js/src/tests/js1_8/genexps/shell.js | 0 |
7 files changed, 416 insertions, 0 deletions
diff --git a/js/src/tests/js1_8/genexps/regress-347739.js b/js/src/tests/js1_8/genexps/regress-347739.js new file mode 100644 index 000000000..cdc4c9c6a --- /dev/null +++ b/js/src/tests/js1_8/genexps/regress-347739.js @@ -0,0 +1,51 @@ +/* -*- 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 = 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); + var close = iter1.close; + iter1.close = null; + delete iter1.close; + iter1.next(); + iter1.close(); + + var iter2 = gen_test(2); + for (i in iter2) { + iter2.close = null; + delete iter2.close; + } + + reportCompare(expect, actual, summary + ': 2'); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_8/genexps/regress-349012-01.js b/js/src/tests/js1_8/genexps/regress-349012-01.js new file mode 100644 index 000000000..1e3e03f28 --- /dev/null +++ b/js/src/tests/js1_8/genexps/regress-349012-01.js @@ -0,0 +1,54 @@ +/* -*- 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 = '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"; + } + } + + try { + for (var i in gen()) + break; + } catch (e) { + if (!(e instanceof TypeError)) + throw e; + } + + reportCompare(expect, actual, summary); + exitFunc ('test'); +} diff --git a/js/src/tests/js1_8/genexps/regress-349326.js b/js/src/tests/js1_8/genexps/regress-349326.js new file mode 100644 index 000000000..eea4e98a7 --- /dev/null +++ b/js/src/tests/js1_8/genexps/regress-349326.js @@ -0,0 +1,148 @@ +/* -*- 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 = 349326; +var summary = 'closing generators'; +var actual = 'PASS'; +var expect = 'PASS'; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + let closed; + + function gen() + { + try { + yield 1; + yield 2; + } finally { + closed = true; + } + } + +// Test that return closes the generator + function test_return() + { + for (let i in gen()) { + if (i != 1) + throw "unexpected generator value"; + return 10; + } + } + + closed = false; + test_return(); + if (closed !== true) + throw "return does not close generator"; + +// test that break closes generator + + closed = false; + for (let i in gen()) { + if (i != 1) + throw "unexpected generator value"; + break; + } + if (closed !== true) + throw "break does not close generator"; + +label: { + for (;;) { + closed = false; + for (let i in gen()) { + if (i != 1) + throw "unexpected generator value"; + break label; + } + } + } + + if (closed !== true) + throw "break does not close generator"; + +// test that an exception closes generator + + function function_that_throws() + { + throw function_that_throws; + } + + try { + closed = false; + for (let i in gen()) { + if (i != 1) + throw "unexpected generator value"; + function_that_throws(); + } + } catch (e) { + if (e !== function_that_throws) + throw e; + } + + if (closed !== true) + throw "exception does not close generator"; + +// Check consistency of finally execution in presence of generators + + let gen2_was_closed = false; + let gen3_was_closed = false; + let finally_was_executed = false; + + function gen2() { + try { + yield 2; + } finally { + if (gen2_was_closed || !finally_was_executed || !gen3_was_closed) + throw "bad oder of gen2 finally execution" + gen2_was_closed = true; + throw gen2; + } + } + + function gen3() { + try { + yield 3; + } finally { + if (gen2_was_closed || finally_was_executed || gen3_was_closed) + throw "bad oder of gen3 finally execution" + gen3_was_closed = true; + } + } + +label2: { + try { + for (let i in gen2()) { + try { + for (let j in gen3()) { + break label2; + } + } finally { + if (gen2_was_closed || finally_was_executed || !gen3_was_closed) + throw "bad oder of try-finally execution"; + finally_was_executed = true; + } + } + throw "gen2 finally should throw"; + } catch (e) { + if (e != gen2) throw e; + } + } + + print("OK"); + + reportCompare(expect, actual, summary); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_8/genexps/regress-384991.js b/js/src/tests/js1_8/genexps/regress-384991.js new file mode 100644 index 000000000..a34adfb3f --- /dev/null +++ b/js/src/tests/js1_8/genexps/regress-384991.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 = 384991; +var summary = ' w(yield) should not cause "yield expression must be parenthesized" syntax error'; +var actual = ''; +var expect = ''; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + expect = 'No Error'; + + try + { + actual = 'No Error'; + (function() { w((yield)); }); + } + catch(ex) + { + actual = ex + ''; + } + reportCompare(expect, actual, summary + ': 1'); + + try + { + actual = 'No Error'; + (function() { w(1 ? yield : 0); }); + } + catch(ex) + { + actual = ex + ''; + } + reportCompare(expect, actual, summary + ': 2'); + + try + { + actual = 'No Error'; + (function () { f(x = yield); const x = undefined; }); + } + catch(ex) + { + actual = ex + ''; + } + reportCompare(expect, actual, summary + ': 3'); + + exitFunc ('test'); +} diff --git a/js/src/tests/js1_8/genexps/regress-665286.js b/js/src/tests/js1_8/genexps/regress-665286.js new file mode 100644 index 000000000..fc8f92266 --- /dev/null +++ b/js/src/tests/js1_8/genexps/regress-665286.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 = 665286; +var summary = 'yield in arguments list'; +var actual = ''; +var expect = ''; + +function reported() { + function f() { + x + } + f(yield []) +} + +function simplified1() { + print(yield) +} + +function simplified2() { + print(1, yield) +} + +reportCompare(reported.isGenerator(), true, "reported case: is generator"); +reportCompare(typeof reported(), "object", "reported case: calling doesn't crash"); +reportCompare(simplified1.isGenerator(), true, "simplified case 1: is generator"); +reportCompare(typeof simplified1(), "object", "simplified case 1: calling doesn't crash"); +reportCompare(simplified2.isGenerator(), true, "simplified case 2: is generator"); +reportCompare(typeof simplified2(), "object", "simplified case 2: calling doesn't crash"); diff --git a/js/src/tests/js1_8/genexps/regress-683738.js b/js/src/tests/js1_8/genexps/regress-683738.js new file mode 100644 index 000000000..de563645d --- /dev/null +++ b/js/src/tests/js1_8/genexps/regress-683738.js @@ -0,0 +1,71 @@ +/* -*- 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 = 683738; +var summary = 'return with argument and lazy generator detection'; +var actual = ''; +var expect = ''; + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + expect = "generator function foo returns a value"; + try + { + actual = 'No Error'; + eval("function foo(x) { if (x) { return this; } else { yield 3; } }"); + } + catch(ex) + { + actual = ex.message; + } + reportCompare(expect, actual, summary + ": 1"); + + expect = "generator function foo returns a value"; + try + { + actual = 'No Error'; + eval("function foo(x) { if (x) { yield 3; } else { return this; } }"); + } + catch(ex) + { + actual = ex.message; + } + reportCompare(expect, actual, summary + ": 2"); + + expect = "generator function foo returns a value"; + try + { + actual = 'No Error'; + eval("function foo(x) { if (x) { return this; } else { (yield 3); } }"); + } + catch(ex) + { + actual = ex.message; + } + reportCompare(expect, actual, summary + ": 3"); + + expect = "generator function foo returns a value"; + try + { + actual = 'No Error'; + eval("function foo(x) { if (x) { (yield 3); } else { return this; } }"); + } + catch(ex) + { + actual = ex.message; + } + reportCompare(expect, actual, summary + ": 4"); + +} diff --git a/js/src/tests/js1_8/genexps/shell.js b/js/src/tests/js1_8/genexps/shell.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/js1_8/genexps/shell.js |