You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Woonsan Ko (JIRA)" <ji...@apache.org> on 2015/07/12 17:14:04 UTC
[jira] [Commented] (SCXML-234) Unit test (ScriptTest) fails on Java
1.8 due to new JS Engine
[ https://issues.apache.org/jira/browse/SCXML-234?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14623846#comment-14623846 ]
Woonsan Ko commented on SCXML-234:
----------------------------------
Fixed by merging this PR: https://github.com/apache/commons-scxml/pull/1
The main difference made in nashorn JavaScriptEngine (Java 1.8), from user's perspective, is "user can supply any ScriptContext implementation containing any Bindings object as ENGINE_SCOPE, nashorn engine cannot always assume ENGINE_SCOPE Bindings to be backed by a nashorn Global instance." [1]
So, the user should retrieve the nashorn global object (the only location where the evaluated variables are stored) like the example [1]:
{code}
// nashorn engine associates a fresh nashorn Global with the ENGINE_SCOPE
Object obj = myNewContext.getBindings(ScriptContext.ENGINE_SCOPE);
Object nashornGlobal = ((Bindings)obj).get("nashorn.global");
// "nashorn.global" is the key used to associate
ScriptObjectMirror globalMirror = (ScriptObjectMirror) nashornGlobal;
{code}
Luckily ScriptObjectMirror is javax.script.Bindings type, so I used Bindings to cast the nashorn.globals when available. This makes it compatible with standard API usages, without having to depend on nashorn specific APIs.
Also, I was able to check if nashorn.globals is available or not, so this fix would make the test work on both Java 1.8 and earlier versions.
[1] https://wiki.openjdk.java.net/display/Nashorn/Nashorn+jsr223+engine+notes
> Unit test (ScriptTest) fails on Java 1.8 due to new JS Engine
> -------------------------------------------------------------
>
> Key: SCXML-234
> URL: https://issues.apache.org/jira/browse/SCXML-234
> Project: Commons SCXML
> Issue Type: Bug
> Reporter: Woonsan Ko
> Assignee: Woonsan Ko
> Fix For: 2.0
>
>
> One unit test fails:
> {code}
> Running org.apache.commons.scxml2.model.ScriptTest
> Tests run: 2, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.226 sec <<< FAILURE! - in org.apache.commons.scxml2.model.ScriptTest
> testJavaScriptExecution(org.apache.commons.scxml2.model.ScriptTest) Time elapsed: 0.218 sec <<< FAILURE!
> org.junit.ComparisonFailure: expected:<[end]> but was:<[script]>
> at org.junit.Assert.assertEquals(Assert.java:115)
> at org.junit.Assert.assertEquals(Assert.java:144)
> at org.apache.commons.scxml2.model.ScriptTest.testJavaScriptExecution(ScriptTest.java:49)
> {code}
> Tested on JDK 1.8.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)