More fun with scopes and ScriptObjectMirror
Tim Fox
timvolpe at gmail.com
Tue Dec 10 11:49:54 PST 2013
Sorry for the deluge of posts, but I think I've found another issue with
scopes/ScriptObjectMirror.
Consider this case: https://gist.github.com/purplefox/7896892
I have a simple JS object which contains a function 'setCallback' which
simply delegates to a Java object which also has a setCallback method.
Calling this method works fine from within the same scope that it was
created in.
However, if I export the object to another scope - wrapping in
ScriptObjectMirror as advised (and this is exactly the kind of thing I
would need to do to implement CommonJS require in Nashorn), and then try
to call the setCallback method from there, it yields the following
exception:
java.lang.ClassCastException: Cannot cast
jdk.nashorn.api.scripting.ScriptObjectMirror to java.lang.Runnable
at
sun.invoke.util.ValueConversions.newClassCastException(ValueConversions.java:461)
at
sun.invoke.util.ValueConversions.castReference(ValueConversions.java:456)
at jdk.nashorn.internal.scripts.Script$\^eval\_._L2(<eval>:3)
at
jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:500)
at
jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:207)
at
jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:378)
at
jdk.nashorn.api.scripting.ScriptObjectMirror.call(ScriptObjectMirror.java:107)
at jdk.nashorn.internal.scripts.Script$\^eval\_.runScript(<eval>:1)
at
jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:498)
at
jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:207)
at
jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:378)
at
jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:544)
at
jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:526)
at
jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:522)
at
jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:193)
at
org.vertx.java.platform.impl.HandlerScopeTest.run(HandlerScopeTest.java:48)
at
org.vertx.java.platform.impl.HandlerScopeTest.main(HandlerScopeTest.java:9)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
More information about the nashorn-dev
mailing list