JSObject call() is passed undefined/null for the argument 'thiz'?

Art Fiedler artfiedler at gmail.com
Wed Nov 30 19:06:21 UTC 2016


When calling the following code, I expected the call to myJSObject inside
testJSOCall to pass the current
scope as a ScriptObjectMirror to JSObjectImpl's call method as the thiz
argument. In this case without
modifying the call to myJSObject() should 'this' automatically be passed to
the call() method?

Arthur Fiedler

public class NashornBugTest
    public static void main(String[] args) throws Exception {
        NashornScriptEngineFactory factory = new
        ScriptEngine scriptEngine = factory.getScriptEngine();
        scriptEngine.put("myJSObject", new JSObjectImpl());
            "var a = 42;\n" +
            "function testJSOCall(b) {\n" +
            "    myJSObject('text purposely did not pass b');\n" +
            "}\n" +
    public static class JSObjectImpl extends AbstractJSObject
        public Object call(Object thiz, Object... args)
            if (ScriptObjectMirror.isUndefined(thiz) || thiz == null)
                throw new IllegalArgumentException("'thiz' is
            // TODO: need the value of 'b' in the calling function
            return super.call(thiz, args);
        public boolean isFunction()
            return true;

More information about the nashorn-dev mailing list