r9582 - in helma/helma/branches/lazy_collections/src/helma: objectmodel/db scripting/rhino

[email protected]
Newsgroups gmane.comp.java.helma.cvs
Message-ID <20090407140129.0C7853D0D6@mia>
Author: hannes
Date: 2009-04-07 16:01:29 +0200 (Tue, 07 Apr 2009)
New Revision: 9582

Modified:
   helma/helma/branches/lazy_collections/src/helma/objectmodel/db/SubnodeList.java
   helma/helma/branches/lazy_collections/src/helma/scripting/rhino/HopObject.java
Log:
Add some index sanity checks so we fare better in the real world.

Details at http://dev.helma.org/trac/helma/changeset/9582

Modified: helma/helma/branches/lazy_collections/src/helma/objectmodel/db/SubnodeList.java
===================================================================
--- helma/helma/branches/lazy_collections/src/helma/objectmodel/db/SubnodeList.java	2009-04-07 13:03:55 UTC (rev 9581)
+++ helma/helma/branches/lazy_collections/src/helma/objectmodel/db/SubnodeList.java	2009-04-07 14:01:29 UTC (rev 9582)
@@ -64,6 +64,9 @@
     }
 
     public Object get(int index) {
+        if (index < 0 || index >= list.size()) {
+            return null;
+        }
         return list.get(index);
     }
 

Modified: helma/helma/branches/lazy_collections/src/helma/scripting/rhino/HopObject.java
===================================================================
--- helma/helma/branches/lazy_collections/src/helma/scripting/rhino/HopObject.java	2009-04-07 13:03:55 UTC (rev 9581)
+++ helma/helma/branches/lazy_collections/src/helma/scripting/rhino/HopObject.java	2009-04-07 14:01:29 UTC (rev 9582)
@@ -501,6 +501,10 @@
         Node node = (Node) getNode();
         prefetchChildren(start, length);
         SubnodeList list = node.getSubnodeList();
+        length = Math.min(list.size() - start, length);
+        if (length <= 0) {
+            return Context.getCurrentContext().newArray(core.global, 0);
+        }
         Object[] array = new Object[length];
 
         for (int i = 0; i < length; i++) {
@@ -691,6 +695,15 @@
     }
 
     /**
+     * Check if node is contained in the subnode collection.
+     * Return its index position if it is, and -1 otherwise.
+     * @deprecated use indexOf(Object) instead.
+     */
+    public int jsFunction_contains(Object obj) {
+        return jsFunction_indexOf(obj);
+    }
+    
+    /**
      * Set a property in this HopObject
      *
      * @param name property name
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.