commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From woon...@apache.org
Subject commons-scxml git commit: SCXML-233 nashorn.global doesn't need to be put in context, which bothers serialization of the context instance. So, saving the nashorn.global only in Bindings.
Date Sun, 12 Jul 2015 17:09:22 GMT
Repository: commons-scxml
Updated Branches:
  refs/heads/master 67bd8cc4e -> 046f547b5


SCXML-233 nashorn.global doesn't need to be put in context, which bothers serialization of
the context instance. So, saving the nashorn.global only in Bindings.


Project: http://git-wip-us.apache.org/repos/asf/commons-scxml/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-scxml/commit/046f547b
Tree: http://git-wip-us.apache.org/repos/asf/commons-scxml/tree/046f547b
Diff: http://git-wip-us.apache.org/repos/asf/commons-scxml/diff/046f547b

Branch: refs/heads/master
Commit: 046f547b562ba2df5bc03f9a5c0125840a39cb2f
Parents: 67bd8cc
Author: Woonsan Ko <woonsan@apache.org>
Authored: Sun Jul 12 13:09:00 2015 -0400
Committer: Woonsan Ko <woonsan@apache.org>
Committed: Sun Jul 12 13:09:00 2015 -0400

----------------------------------------------------------------------
 src/changes/changes.xml                         |  4 +++
 .../scxml2/env/javascript/JSBindings.java       | 26 +++++++++++---------
 .../scxml2/env/javascript/JSEvaluator.java      |  4 +--
 .../scxml2/env/javascript/JSFunctions.java      |  4 ++-
 4 files changed, 24 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-scxml/blob/046f547b/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index fb1dd83..e8d3d98 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -36,6 +36,10 @@
     <release version="2.0" date="In SVN trunk"
       description="Latest unreleased code">
 
+      <action dev="woonsan" type="fix" issue="SCXML-233">
+        [07-12-2015] SCInstance becomes not serialzable after triggering event. 
+      </action>
+
       <action dev="woonsan" type="fix" issue="SCXML-234">
         [07-12-2015] Unit test (ScriptTest) fails on Java 1.8 due to new JS Engine. 
       </action>

http://git-wip-us.apache.org/repos/asf/commons-scxml/blob/046f547b/src/main/java/org/apache/commons/scxml2/env/javascript/JSBindings.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/scxml2/env/javascript/JSBindings.java b/src/main/java/org/apache/commons/scxml2/env/javascript/JSBindings.java
index 85bef0f..6b7142f 100644
--- a/src/main/java/org/apache/commons/scxml2/env/javascript/JSBindings.java
+++ b/src/main/java/org/apache/commons/scxml2/env/javascript/JSBindings.java
@@ -206,6 +206,11 @@ public class JSBindings implements Bindings {
      */
     @Override
     public Object get(Object key) {
+        // nashorn.global should be retrieved from the bindings, not from context.
+        if (NASHORN_GLOBAL.equals(key)) {
+            return bindings.get(key);
+        }
+
         if (hasGlobalBindings() && getGlobalBindings().containsKey(key)) {
             return getGlobalBindings().get(key);
         }
@@ -232,10 +237,13 @@ public class JSBindings implements Bindings {
     public Object put(String name, Object value) {
         Object old = context.get(name);
 
-        if (context.has(name)) {
+        // nashorn.global should be put into the bindings, not into context.
+        if (NASHORN_GLOBAL.equals(name)) {
+            return bindings.put(name, value);
+        } else if (context.has(name)) {
             context.set(name, value);
         } else if (bindings.containsKey(name)) {
-            return bindings.put(name,value);
+            return bindings.put(name, value);
         } else if (hasGlobalBindings() && getGlobalBindings().containsKey(name))
{
             return getGlobalBindings().put(name, value);
         } else {
@@ -253,8 +261,8 @@ public class JSBindings implements Bindings {
      *       context. Not thread-safe.
      */
     @Override
-    public void putAll(Map<? extends String, ? extends Object> list) {
-        bindings.putAll(list);
+    public void putAll(Map<? extends String, ? extends Object> toMerge) {
+        bindings.putAll(toMerge);
     }
 
     /**
@@ -326,27 +334,23 @@ public class JSBindings implements Bindings {
      * </p>
      * @return true if a global bindings (i.e. nashorn Global instance) was ever set by the
script engine
      */
-    boolean hasGlobalBindings() {
+    protected boolean hasGlobalBindings() {
         if (bindings.containsKey(NASHORN_GLOBAL)) {
             return true;
         }
 
-        return context.has(NASHORN_GLOBAL);
+        return false;
     }
 
     /**
      * Return the global bindings (i.e. nashorn Global instance) set by the script engine
if existing.
      * @return the global bindings (i.e. nashorn Global instance) set by the script engine,
or null if not existing.
      */
-    Bindings getGlobalBindings() {
+    protected Bindings getGlobalBindings() {
         if (bindings.containsKey(NASHORN_GLOBAL)) {
             return (Bindings) bindings.get(NASHORN_GLOBAL);
         }
 
-        if (context.has(NASHORN_GLOBAL)) {
-            return (Bindings) context.get(NASHORN_GLOBAL);
-        }
-
         return null;
     }
 }

http://git-wip-us.apache.org/repos/asf/commons-scxml/blob/046f547b/src/main/java/org/apache/commons/scxml2/env/javascript/JSEvaluator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/scxml2/env/javascript/JSEvaluator.java b/src/main/java/org/apache/commons/scxml2/env/javascript/JSEvaluator.java
index 8b47e93..b67ccbc 100644
--- a/src/main/java/org/apache/commons/scxml2/env/javascript/JSEvaluator.java
+++ b/src/main/java/org/apache/commons/scxml2/env/javascript/JSEvaluator.java
@@ -142,8 +142,8 @@ public class JSEvaluator implements Evaluator {
             JSContext effectiveContext = getEffectiveContext((JSContext) context);
 
             // ... initialize
-            ScriptEngine engine   = factory.getEngineByName("JavaScript");
-            Bindings     bindings = engine.getBindings     (ScriptContext.ENGINE_SCOPE);
+            ScriptEngine engine = factory.getEngineByName("JavaScript");
+            Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
 
             // ... replace built-in functions
             String jsExpression = IN_FN.matcher(expression).replaceAll("_builtin.In(");

http://git-wip-us.apache.org/repos/asf/commons-scxml/blob/046f547b/src/main/java/org/apache/commons/scxml2/env/javascript/JSFunctions.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/scxml2/env/javascript/JSFunctions.java b/src/main/java/org/apache/commons/scxml2/env/javascript/JSFunctions.java
index dd26d54..9b2a93e 100644
--- a/src/main/java/org/apache/commons/scxml2/env/javascript/JSFunctions.java
+++ b/src/main/java/org/apache/commons/scxml2/env/javascript/JSFunctions.java
@@ -16,6 +16,8 @@
  */
 package org.apache.commons.scxml2.env.javascript;
 
+import java.io.Serializable;
+
 import org.apache.commons.scxml2.Builtin;
 import org.apache.commons.scxml2.Context;
 import org.apache.commons.scxml2.SCXMLExpressionException;
@@ -25,7 +27,7 @@ import org.apache.commons.scxml2.XPathBuiltin;
  * Custom Javascript engine function providing the SCXML In() predicate and the Commons SCXML
extensions
  * for Data() and Location() to support XPath datamodel access.
  */
-public class JSFunctions {
+public class JSFunctions implements Serializable {
 
     /**
      * The context currently in use for evaluation.


Mime
View raw message