incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r1557909 - in /sling/trunk/bundles/scripting/javascript: ./ src/main/java/org/apache/sling/scripting/javascript/wrapper/
Date Tue, 14 Jan 2014 02:35:02 GMT
Author: fmeschbe
Date: Tue Jan 14 02:35:01 2014
New Revision: 1557909

URL: http://svn.apache.org/r1557909
Log:
SLING-3308 Upgrade to Rhino 1.7R4

Apply extended patch by Rohit Kumar (Thanks alot !). Extensions to
the original patch are checking all wrapper objects whether the
wrapped field needs a null check.

Modified:
    sling/trunk/bundles/scripting/javascript/pom.xml
    sling/trunk/bundles/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableCalendar.java
    sling/trunk/bundles/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableItemMap.java
    sling/trunk/bundles/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableNode.java
    sling/trunk/bundles/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableProperty.java
    sling/trunk/bundles/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableResource.java

Modified: sling/trunk/bundles/scripting/javascript/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/javascript/pom.xml?rev=1557909&r1=1557908&r2=1557909&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/javascript/pom.xml (original)
+++ sling/trunk/bundles/scripting/javascript/pom.xml Tue Jan 14 02:35:01 2014
@@ -137,9 +137,9 @@
             <artifactId>jcr</artifactId>
         </dependency>
         <dependency>
-            <groupId>rhino</groupId>
-            <artifactId>js</artifactId>
-            <version>1.6R6</version>
+            <groupId>org.mozilla</groupId>
+            <artifactId>rhino</artifactId>
+            <version>1.7R4</version>
         </dependency>
         <dependency>
             <groupId>org.slf4j</groupId>

Modified: sling/trunk/bundles/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableCalendar.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableCalendar.java?rev=1557909&r1=1557908&r2=1557909&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableCalendar.java
(original)
+++ sling/trunk/bundles/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableCalendar.java
Tue Jan 14 02:35:01 2014
@@ -19,7 +19,6 @@ package org.apache.sling.scripting.javas
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
 import java.util.GregorianCalendar;
-
 import org.apache.sling.scripting.javascript.SlingWrapper;
 import org.mozilla.javascript.ScriptRuntime;
 import org.mozilla.javascript.Scriptable;
@@ -31,12 +30,17 @@ public class ScriptableCalendar extends 
 
 	public static final String CLASSNAME = "Calendar";
 	private SimpleDateFormat calendarFormat;
-	
+
 	/** Calendar is a class, not an interface - so we need to enumerate possible implementations
here */
     public static final Class<?> [] WRAPPED_CLASSES = { Calendar.class, GregorianCalendar.class
};
 
+    /**
+     * The wrapped Calendar. Will be {@code null} if the
+     * {@link #jsConstructor(Object)} method is not called, which particularly
+     * is the case for the Calendar host object prototype.
+     */
 	private Calendar calendar;
-	
+
     public Class<?>[] getWrappedClasses() {
 		return WRAPPED_CLASSES;
 	}
@@ -44,7 +48,7 @@ public class ScriptableCalendar extends 
     public void jsConstructor(Object o) {
         this.calendar = (Calendar) o;
     }
-	
+
     @Override
     public Object get(String name, Scriptable start) {
 
@@ -57,14 +61,14 @@ public class ScriptableCalendar extends 
         if(calendar == null) {
             return Undefined.instance;
         }
-        
+
         if("date".equals(name)) {
         	return ScriptRuntime.toObject(this, calendar.getTime());
         }
-        
+
         return getNative(name, start);
     }
-    
+
 	@Override
 	protected Class<?> getStaticType() {
 		return Calendar.class;
@@ -92,7 +96,7 @@ public class ScriptableCalendar extends 
         }
         return calendarFormat.format(calendar.getTime());
 	}
-	
+
     public Object unwrap() {
         return calendar;
     }

Modified: sling/trunk/bundles/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableItemMap.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableItemMap.java?rev=1557909&r1=1557908&r2=1557909&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableItemMap.java
(original)
+++ sling/trunk/bundles/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableItemMap.java
Tue Jan 14 02:35:01 2014
@@ -39,10 +39,7 @@ public class ScriptableItemMap extends S
     /** default log */
     private final Logger log = LoggerFactory.getLogger(getClass());
 
-    private Map<String, Item> items = new LinkedHashMap<String, Item>();
-
-    public ScriptableItemMap() {
-    }
+    private final Map<String, Item> items = new LinkedHashMap<String, Item>();
 
     public void jsConstructor(Object res) {
         if (res instanceof Iterator<?>) {

Modified: sling/trunk/bundles/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableNode.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableNode.java?rev=1557909&r1=1557908&r2=1557909&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableNode.java
(original)
+++ sling/trunk/bundles/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableNode.java
Tue Jan 14 02:35:01 2014
@@ -55,6 +55,11 @@ public class ScriptableNode extends Scri
     /** default log */
     private final Logger log = LoggerFactory.getLogger(getClass());
 
+    /**
+     * The wrapped JCR Node instance. Will be {@code null} if the
+     * {@link #jsConstructor(Object)} method is not called, which particularly
+     * is the case for the Node host object prototype.
+     */
     private Node node;
 
     public void jsConstructor(Object res) {
@@ -68,7 +73,7 @@ public class ScriptableNode extends Scri
     public Class<?> [] getWrappedClasses() {
         return WRAPPED_CLASSES;
     }
-    
+
     @Override
     protected Class<?> getStaticType() {
         return Node.class;
@@ -78,7 +83,7 @@ public class ScriptableNode extends Scri
     protected Object getWrappedObject() {
         return node;
     }
-    
+
     public Object jsFunction_addNode(String path, String primaryType) throws RepositoryException
{
         Node n = null;
         if(primaryType == null || "undefined".equals(primaryType)) {
@@ -118,7 +123,7 @@ public class ScriptableNode extends Scri
             return toScriptableItemMap(null);
         }
     }
-    
+
     public Object jsFunction_getProperties() {
         try {
             return toScriptableItemMap(node.getProperties());
@@ -135,7 +140,7 @@ public class ScriptableNode extends Scri
             return Undefined.instance;
         }
     }
-    
+
     public Object jsFunction_getProperty(String name) throws RepositoryException {
         Object[] args = { node.getProperty(name) };
         return ScriptRuntime.newObject(Context.getCurrentContext(), this,
@@ -253,7 +258,7 @@ public class ScriptableNode extends Scri
             return node.toString();
         }
     }
-    
+
     public Object jsFunction_getParent() {
         try {
             return ScriptRuntime.toObject(this, node.getParent());
@@ -277,7 +282,7 @@ public class ScriptableNode extends Scri
     public boolean jsFunction_getModified() {
         return node.isModified();
     }
-    
+
     public void jsFunction_remove() throws RepositoryException {
         node.remove();
     }
@@ -338,10 +343,10 @@ public class ScriptableNode extends Scri
 
         if (items.size()==0) {
             return getNative(name, start);
-            
+
         } else if (items.size()==1 && !isMulti) {
             return items.iterator().next();
-            
+
         } else {
             NativeArray result = new NativeArray(items.toArray());
             ScriptRuntime.setObjectProtoAndParent(result, this);
@@ -392,34 +397,38 @@ public class ScriptableNode extends Scri
     @SuppressWarnings("unchecked")
     @Override
     public Object getDefaultValue(Class typeHint) {
-        try {
-            return node.getPath();
-        } catch(Exception e) {
-            return null;
-        }
+        return toString();
     }
 
     @Override
     public boolean has(String name, Scriptable start) {
-        try {
-            // TODO should this take into account our jsFunction_ members?
-            return node.hasProperty(name) || node.hasNode(name);
-        } catch (RepositoryException e) {
-            return false;
+        if (node != null) {
+            try {
+                // TODO should this take into account our jsFunction_ members?
+                return node.hasProperty(name) || node.hasNode(name);
+            } catch (RepositoryException e) {
+                // does not matter
+            }
         }
+
+        return false;
     }
 
     public Class<?> jsGet_javascriptWrapperClass() {
         return getClass();
     }
-    
+
     @Override
     public String toString() {
-        try {
-            return node.getPath();
-        } catch (RepositoryException e) {
-            return node.toString();
+        if (node != null) {
+            try {
+                return node.getPath();
+            } catch (RepositoryException e) {
+                return node.toString();
+            }
         }
+
+        return String.valueOf((Object) null);
     }
 
     // ---------- Wrapper interface --------------------------------------------
@@ -428,9 +437,9 @@ public class ScriptableNode extends Scri
     public Object unwrap() {
         return node;
     }
-    
+
     //---------- Helper -------------------------------------------------------
-    
+
     private Object toScriptableItemMap(Iterator<?> iter) {
         Object[] args = (iter != null) ? new Object[] { iter } : null;
         return ScriptRuntime.newObject(Context.getCurrentContext(), this,

Modified: sling/trunk/bundles/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableProperty.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableProperty.java?rev=1557909&r1=1557908&r2=1557909&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableProperty.java
(original)
+++ sling/trunk/bundles/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableProperty.java
Tue Jan 14 02:35:01 2014
@@ -35,6 +35,11 @@ public class ScriptableProperty extends 
 
     public static final Class<?>[] WRAPPED_CLASSES = { Property.class };
 
+    /**
+     * The wrapped JCR Property instance. Will be {@code null} if the
+     * {@link #jsConstructor(Object)} method is not called, which particularly
+     * is the case for the Property host object prototype.
+     */
     private Property property;
 
     public ScriptableProperty() {
@@ -208,10 +213,10 @@ public class ScriptableProperty extends 
     public Class<?> jsGet_javascriptWrapperClass() {
         return getClass();
     }
-    
+
     public Object jsFunction_valueOf(String hint) {
         if ("undefined".equals(hint)) {
-            
+
             try {
                 switch (property.getType()) {
                     case PropertyType.BOOLEAN:
@@ -229,15 +234,15 @@ public class ScriptableProperty extends 
                 // don't care, just return the string value
                 return toString();
             }
-            
+
         } else if ("object".equals(hint)) {
             // return this as a Scriptable :-)
             return this;
-            
+
         } else if ("function".equals(hint)) {
             // cannot return this as a Function
             return Undefined.instance;
-            
+
         } else if ("boolean".equals(hint)) {
             // boolean value
             try {
@@ -245,7 +250,7 @@ public class ScriptableProperty extends 
             } catch (RepositoryException re) {
                 return false;
             }
-            
+
         } else if ("number".equals(hint)) {
             // numeric value
             try {
@@ -258,7 +263,7 @@ public class ScriptableProperty extends 
         // unknown hint or "string"
         return toString();
     }
-    
+
     @Override
     public Object get(String name, Scriptable start) {
         final Object fromSuperclass = super.get(name, start);
@@ -269,7 +274,7 @@ public class ScriptableProperty extends 
         if(property == null) {
             return Undefined.instance;
         }
-        
+
         return getNative(name, start);
     }
 
@@ -279,11 +284,15 @@ public class ScriptableProperty extends 
 
     @Override
     public String toString() {
-        try {
-            return property.getValue().getString();
-        } catch (RepositoryException e) {
-            return property.toString();
+        if (property != null) {
+            try {
+                return property.getValue().getString();
+            } catch (RepositoryException e) {
+                return property.toString();
+            }
         }
+
+        return String.valueOf((Object) null);
     }
 
     // ---------- Wrapper interface --------------------------------------------

Modified: sling/trunk/bundles/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableResource.java?rev=1557909&r1=1557908&r2=1557909&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableResource.java
(original)
+++ sling/trunk/bundles/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableResource.java
Tue Jan 14 02:35:01 2014
@@ -240,7 +240,11 @@ public class ScriptableResource extends 
     @SuppressWarnings("unchecked")
     @Override
     public Object getDefaultValue(Class typeHint) {
-        return resource.getPath();
+        if (resource != null) {
+            return resource.getPath();
+        }
+
+        return String.valueOf((Object) null);
     }
 
     public void setResource(Resource entry) {



Mime
View raw message