You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by rw...@apache.org on 2016/02/03 03:35:19 UTC

svn commit: r1728248 - in /pivot/branches/2.0.x: ./ core/src/org/apache/pivot/beans/BXMLSerializer.java tests/src/org/apache/pivot/tests/issues/pivot965/

Author: rwhitcomb
Date: Wed Feb  3 02:35:19 2016
New Revision: 1728248

URL: http://svn.apache.org/viewvc?rev=1728248&view=rev
Log:
PIVOT-965:  Fix an issue with Java 8 (Nashorn script engine) and the way
we deal with included scripts.  The problem is that in creating the new
serializer for the included script, the script engine ends up creating a
new "nashorn.global" context, which does not include any previous defined
variables or functions.  This new context persists as the current "global"
context after the included script has been read.  Then when attempting to
look up any variables/functions defined before the "include" they won't be
found.

The "solution" (or workaround) is to detect when the new global context is
being established and copy the old definitions into it.  Now, that sort of
begs the question as to:
* Is this the right place to do this?
* What about the situation when "inline" is false for the included script?
* What about multiple includes?
* What about nested includes?

These are still unanswered questions needing more research.  So, for now,
just add the workaround (and some of the debug code still there, but
commented out).

This is a merge of revision 1728247 from trunk to branches/2.0.x.

Added:
    pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/issues/pivot965/
      - copied from r1728247, pivot/trunk/tests/src/org/apache/pivot/tests/issues/pivot965/
Modified:
    pivot/branches/2.0.x/   (props changed)
    pivot/branches/2.0.x/core/src/org/apache/pivot/beans/BXMLSerializer.java

Propchange: pivot/branches/2.0.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Feb  3 02:35:19 2016
@@ -1 +1 @@
-/pivot/trunk:1346574,1347051,1394847,1394858,1398511,1399331,1401781,1405882,1407585,1409081,1410536,1410555,1417081,1417258,1428056,1428650,1435351,1436707,1438126,1438659,1444260,1444910,1502657,1510821,1516518,1519859,1522078,1523205,1523736,1523776,1525982,1526005,1536829,1537222,1604238,1610563,1611829,1614462,1624381,1675204,1675517,1678238,1678251,1687873-1687874,1688306,1688484,1688523,1691618,1712175,1717360,1727931
+/pivot/trunk:1346574,1347051,1394847,1394858,1398511,1399331,1401781,1405882,1407585,1409081,1410536,1410555,1417081,1417258,1428056,1428650,1435351,1436707,1438126,1438659,1444260,1444910,1502657,1510821,1516518,1519859,1522078,1523205,1523736,1523776,1525982,1526005,1536829,1537222,1604238,1610563,1611829,1614462,1624381,1675204,1675517,1678238,1678251,1687873-1687874,1688306,1688484,1688523,1691618,1712175,1717360,1727931,1728247

Modified: pivot/branches/2.0.x/core/src/org/apache/pivot/beans/BXMLSerializer.java
URL: http://svn.apache.org/viewvc/pivot/branches/2.0.x/core/src/org/apache/pivot/beans/BXMLSerializer.java?rev=1728248&r1=1728247&r2=1728248&view=diff
==============================================================================
--- pivot/branches/2.0.x/core/src/org/apache/pivot/beans/BXMLSerializer.java (original)
+++ pivot/branches/2.0.x/core/src/org/apache/pivot/beans/BXMLSerializer.java Wed Feb  3 02:35:19 2016
@@ -112,6 +112,22 @@ public class BXMLSerializer implements S
         }
     }
 
+/*    private static void printBindings(java.util.Map<String,Object> bindings) {
+	System.out.format("=== Bindings %1$s ===%n", bindings);
+	for (String key : bindings.keySet()) {
+	    Object value = bindings.get(key);
+	    System.out.format("key: %1$s, value: %2$s [%3$s]%n", key, value, Integer.toHexString(System.identityHashCode(value)));
+	    if (key.equals(NASHORN_GLOBAL)) {
+		Bindings globalBindings = (Bindings)value;
+		for (String globalKey : globalBindings.keySet()) {
+		    Object globalValue = globalBindings.get(globalKey);
+		    System.out.format("    global key: %1$s, value: %2$s [%3$s]%n", globalKey, globalValue, Integer.toHexString(System.identityHashCode(globalValue)));
+		}
+	    }
+	}
+	System.out.println("=====================");
+    }
+*/
     private class AttributeInvocationHandler implements InvocationHandler {
         private ScriptEngine scriptEngine;
         private String event;
@@ -318,6 +334,21 @@ public class BXMLSerializer implements S
 
             @Override
             public Object put(String key, Object value) {
+                // Okay, this is a hack that seems to fix problems with included scripts
+                // under Java 8 (Nashorn) where a new global object gets setup that
+                // doesn't include any of the old values.
+                // TODO: do we need to do this if "inline" is not true on the INCLUDE?
+                if (key.equals(NASHORN_GLOBAL)) {
+                    Object oldGlobal = namespace.put(key, value);
+                    // We have to copy the old global values into the new one
+                    if (oldGlobal != null && oldGlobal instanceof Bindings &&
+                        value != null && value instanceof Bindings) {
+                        Bindings oldGlobalBindings = (Bindings)oldGlobal;
+                        Bindings newBindings = (Bindings)value;
+                        newBindings.putAll(oldGlobalBindings);
+                    }
+                    return oldGlobal;
+                }
                 return namespace.put(key, value);
             }