-
Bug
-
Resolution: Not an Issue
-
P3
-
None
-
None
-
JDK8b132
-
generic
-
generic
-
Verified
While investigating my #2 issue from
https://bugs.openjdk.java.net/browse/JDK-8006183?focusedCommentId=13504584&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-13504584
I've noticed a problem with identity. I know the identity of Java objects passed to Nashorn and returned back is weaker than it used to be in Rhino - e.g. sometimes objects are not == only equal. But I found a case where the object is not even equal and I consider it a bug. Would you agree that following testIdentity function should never throw the IllegalStateException?
public static void main(String[] args) throws Exception {
ScriptEngineManager sem = new ScriptEngineManager();
ScriptEngine eng = sem.getEngineByMimeType("text/javascript");
Invocable inv = (Invocable) eng;
testIdentity(eng, new Object());
}
private static void testIdentity(ScriptEngine eng, Object obj) throws Exception {
Invocable inv = (Invocable) eng;
eng.eval("function id(x) { return x; }");
Object returned = inv.invokeFunction("id", obj);
if (returned == obj || obj.equals(returned)) {
return;
}
throw new IllegalStateException(
"Not equals! obj: " + obj + " returned: " + returned +
"\ntypes: " + obj.getClass() + " real: " + returned.getClass()
);
}
I would agree with such statement. Having a function that returns is parameter, should return the parameter. At least I hope.
https://bugs.openjdk.java.net/browse/JDK-8006183?focusedCommentId=13504584&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-13504584
I've noticed a problem with identity. I know the identity of Java objects passed to Nashorn and returned back is weaker than it used to be in Rhino - e.g. sometimes objects are not == only equal. But I found a case where the object is not even equal and I consider it a bug. Would you agree that following testIdentity function should never throw the IllegalStateException?
public static void main(String[] args) throws Exception {
ScriptEngineManager sem = new ScriptEngineManager();
ScriptEngine eng = sem.getEngineByMimeType("text/javascript");
Invocable inv = (Invocable) eng;
testIdentity(eng, new Object());
}
private static void testIdentity(ScriptEngine eng, Object obj) throws Exception {
Invocable inv = (Invocable) eng;
eng.eval("function id(x) { return x; }");
Object returned = inv.invokeFunction("id", obj);
if (returned == obj || obj.equals(returned)) {
return;
}
throw new IllegalStateException(
"Not equals! obj: " + obj + " returned: " + returned +
"\ntypes: " + obj.getClass() + " real: " + returned.getClass()
);
}
I would agree with such statement. Having a function that returns is parameter, should return the parameter. At least I hope.
- relates to
-
JDK-8046013 TypeError: Cannot apply "with" to non script object
- Resolved