Subj : Bug in 1.6R2 with recursive functions ? - Bug.java (1/1) To : netscape.public.mozilla.jseng From : Ulf Dittmer Date : Sat Sep 17 2005 02:10 pm Hello- The attached program defines a recursive JS function and tries to invoke it from within a Scope. It runs fine with Rhino 1.5R5, but fails with 1.6R2 with: Exception in thread "main" org.mozilla.javascript.EcmaError: ReferenceError: "addOne" is not defined. (addOne#1) The non-recursive case works, it's only when recursion is attempted that the error manifests itself. I wonder if it's related to the elimination of tail recursion under this bug for 1.6R1: https://bugzilla.mozilla.org/show_bug.cgi?id=257128 Please take a look at this, and let me know if I should write up a bug. Cheers, Ulf /* Hello- The following program defines a recursive JS function and tries to invoke it from within a Scope. It runs fine with Rhino 1.5R5, but fails with 1.6R2 with: Exception in thread "main" org.mozilla.javascript.EcmaError: ReferenceError: "addOne" is not defined. (addOne#1) The non-recursive case works, it's only when recursion is attempted that the error manifests itself. I wonder if it's related to the elimination of tail recursion under this bug for 1.6R1: https://bugzilla.mozilla.org/show_bug.cgi?id=257128 Please have a look at this, and let me know if I should write up a bug. Cheers, Ulf */ import org.mozilla.javascript.*; public class Bug { public static void main (String args[]) throws JavaScriptException { Context cx = Context.enter(); cx.setOptimizationLevel(-1); try { Scriptable scope = cx.initStandardObjects(null); String addOne = "function addOne (n) { if (n == 0) return 1; else return addOne(n-1) + 1; }"; Function addOneFunc = cx.compileFunction(scope, addOne, "addOne", 1, null); // works fine for 0, but there is no recursion System.out.println(addOneFunc.call(cx, scope, null, new Integer[]{ new Integer(0) })); // fails for anything that recurses System.out.println(addOneFunc.call(cx, scope, null, new Integer[]{ new Integer(10) })); } finally { Context.exit(); } } } .