commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Woonsan Ko (JIRA)" <>
Subject [jira] [Commented] (SCXML-234) Unit test (ScriptTest) fails on Java 1.8 due to new JS Engine
Date Sun, 12 Jul 2015 15:14:04 GMT


Woonsan Ko commented on SCXML-234:

Fixed by merging this PR:

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]:

// nashorn engine associates a fresh nashorn Global with the ENGINE_SCOPE
   Object obj = myNewContext.getBindings(ScriptContext.ENGINE_SCOPE);
   Object nashornGlobal = ((Bindings)obj).get(""); 
   // "" is the key used to associate
   ScriptObjectMirror globalMirror = (ScriptObjectMirror) nashornGlobal;

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.


> Unit test (ScriptTest) fails on Java 1.8 due to new JS Engine
> -------------------------------------------------------------
>                 Key: SCXML-234
>                 URL:
>             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(
> 	at org.junit.Assert.assertEquals(
> 	at org.apache.commons.scxml2.model.ScriptTest.testJavaScriptExecution(
> {code}
> Tested on JDK 1.8.

This message was sent by Atlassian JIRA

View raw message