michael@0: function factorial(n) { michael@0: if (n <= 1) { michael@0: return 1; michael@0: } else { michael@0: return n * factorial(n - 1); michael@0: } michael@0: } michael@0: michael@0: function* yielder(n) { michael@0: while (n-- >= 0) { michael@0: yield { value: n, squared: n * n }; michael@0: } michael@0: } michael@0: michael@0: function thrower() { michael@0: throw new Error("Curse your sudden but inevitable betrayal!"); michael@0: } michael@0: michael@0: function main() { michael@0: factorial(5); michael@0: michael@0: // XXX bug 923729: Can't test yielding yet. michael@0: // for (let x of yielder(5)) {} michael@0: michael@0: try { michael@0: thrower(); michael@0: } catch (e) { michael@0: } michael@0: }