I've written a very simple JUnit test to illustrate my problem.

import java.util.HashMap;
import java.util.Map;
import javax.script.ScriptEngine;
import javax.script.ScriptException;
import junit.framework.TestCase;


public class ScriptEngineTest extends TestCase {

    public void testNull() throws ScriptException {
        Map globals = new HashMap();
        javax.script.ScriptEngineManager manager = new
javax.script.ScriptEngineManager();
        ScriptEngine engine = manager.getEngineByExtension("js");

        Object o = engine.eval("var city = null; city;");

        assertNull(o);
    }


}



I would expect the returned object 'o' to be null.  Unfortunately,
engine.eval always throws the following error:

org.mozilla.javascript.EcmaError: ReferenceError: "city" is not
defined. (<Unknown source>#1)
        at
org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:
3350)
        at
org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:
3340)
        at
org.mozilla.javascript.ScriptRuntime.notFoundError(ScriptRuntime.java:
3413)


What am I doing wrong?  When I run this same statement through
Firefox's Error Console, it returns null as I would expect.

I'm using the Scripting JSR libraries because I'm running under Java
5, not Java 6.   Other statements evaluate as I would expect, the only
problems seem to occur with null values.  I've tried the code with
js-1.6R5 that comes with the JSR libraries and I've also tried
upgrading to js-1.6R7.  The result is the same.

Help!  Its driving me nuts.  I need to have nullable values.


-Tom
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to