incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r1541393 - in /sling/trunk/bundles/scripting/javascript/src: main/java/org/apache/sling/scripting/javascript/internal/RhinoJavaScriptEngine.java test/java/org/apache/sling/scripting/wrapper/ScriptableResourceTest.java
Date Wed, 13 Nov 2013 05:28:06 GMT
Author: fmeschbe
Date: Wed Nov 13 05:28:05 2013
New Revision: 1541393

URL: http://svn.apache.org/r1541393
Log:
SLING-3241 Unwrapped any wrapped objects before returning
the result from script evaluation.

Also adapted the ScriptableResourceTest becaused "undefined" is returned
as null now. The test evaluates a comparison to the undefined value and
verifies the result is true.

Modified:
    sling/trunk/bundles/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/internal/RhinoJavaScriptEngine.java
    sling/trunk/bundles/scripting/javascript/src/test/java/org/apache/sling/scripting/wrapper/ScriptableResourceTest.java

Modified: sling/trunk/bundles/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/internal/RhinoJavaScriptEngine.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/internal/RhinoJavaScriptEngine.java?rev=1541393&r1=1541392&r2=1541393&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/internal/RhinoJavaScriptEngine.java
(original)
+++ sling/trunk/bundles/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/internal/RhinoJavaScriptEngine.java
Wed Nov 13 05:28:05 2013
@@ -36,6 +36,7 @@ import org.mozilla.javascript.JavaScript
 import org.mozilla.javascript.ScriptRuntime;
 import org.mozilla.javascript.Scriptable;
 import org.mozilla.javascript.ScriptableObject;
+import org.mozilla.javascript.Undefined;
 import org.mozilla.javascript.WrapFactory;
 import org.mozilla.javascript.Wrapper;
 import org.slf4j.Logger;
@@ -111,9 +112,15 @@ public class RhinoJavaScriptEngine exten
             final int lineNumber = 1;
             final Object securityDomain = null;
 
-            return rhinoContext.evaluateReader(scope, scriptReader, scriptName,
+            Object result = rhinoContext.evaluateReader(scope, scriptReader, scriptName,
                     lineNumber, securityDomain);
 
+            if (result instanceof Wrapper) {
+                result = ((Wrapper) result).unwrap();
+            }
+
+            return (result instanceof Undefined) ? null : result;
+
         } catch (JavaScriptException t) {
 
             // prevent variables to be pushed back in case of errors

Modified: sling/trunk/bundles/scripting/javascript/src/test/java/org/apache/sling/scripting/wrapper/ScriptableResourceTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/javascript/src/test/java/org/apache/sling/scripting/wrapper/ScriptableResourceTest.java?rev=1541393&r1=1541392&r2=1541393&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/javascript/src/test/java/org/apache/sling/scripting/wrapper/ScriptableResourceTest.java
(original)
+++ sling/trunk/bundles/scripting/javascript/src/test/java/org/apache/sling/scripting/wrapper/ScriptableResourceTest.java
Wed Nov 13 05:28:05 2013
@@ -37,7 +37,6 @@ import org.apache.sling.commons.testing.
 import org.apache.sling.jcr.resource.JcrResourceConstants;
 import org.apache.sling.scripting.RepositoryScriptingTestBase;
 import org.apache.sling.scripting.javascript.internal.ScriptEngineHelper;
-import org.mozilla.javascript.Undefined;
 import org.mozilla.javascript.Wrapper;
 
 public class ScriptableResourceTest extends RepositoryScriptingTestBase {
@@ -153,14 +152,10 @@ public class ScriptableResourceTest exte
         data.put("resource", new TestResource(node));
 
         // the node to which the resource adapts
-        assertEquals(Undefined.instance,
-            script.eval("resource.adaptTo()", data));
-        assertEquals(Undefined.instance, script.eval("resource.adaptTo(null)",
-            data));
-        assertEquals(Undefined.instance, script.eval(
-            "resource.adaptTo(undefined)", data));
-        assertEquals(Undefined.instance, script.eval(
-            "resource.adaptTo(Packages.java.util.Date)", data));
+        assertEquals(true, script.eval("resource.adaptTo() == undefined", data));
+        assertEquals(true, script.eval("resource.adaptTo(null) == undefined", data));
+        assertEquals(true, script.eval("resource.adaptTo(undefined) == undefined", data));
+        assertEquals(true, script.eval("resource.adaptTo(Packages.java.util.Date) == undefined",
data));
     }
 
     private void assertEquals(Node expected, Object actual) {
@@ -279,7 +274,7 @@ public class ScriptableResourceTest exte
 			}
 		}
 
-        
+
     }
 
 }



Mime
View raw message