better JSArray.sort() exception handling
[org.ibex.core.git] / src / org / ibex / js / JSArray.java
index 2171e4d..8aa5325 100644 (file)
@@ -185,33 +185,31 @@ public class JSArray extends JS.BT {
             a.setElementAt(elementAt(start+i),i);
         return a;
     }
-    
+        
     private static final Vec.CompareFunc defaultSort = new Vec.CompareFunc() {
         public int compare(Object a, Object b) {
             try {
                 return JS.toString((JS)a).compareTo(JS.toString((JS)b));
-            } catch(JSExn e) {
-                // FIXME: See emca about this
-                throw new RuntimeException(e.toString());
-            }
+            } catch(JSExn e) { throw new JSExn.Wrapper(e); }
         }
     };
     private JS sort(JS tmp) throws JSExn {
         Vec vec = toVec();
-        if(tmp instanceof JS) {
-            final JS jsFunc = (JS) tmp;
-            vec.sort(new Vec.CompareFunc() {
-                public int compare(Object a, Object b) {
-                    try {
-                        return JS.toInt(jsFunc.call((JS)a, (JS)b, null, null, 2));
-                    } catch (JSExn e) {
-                        // FIXME: Check ecma to see what we should do here
-                        throw new RuntimeException(e.toString());
+        try {
+            if(tmp instanceof JS) {
+                final JS jsFunc = (JS) tmp;
+                vec.sort(new Vec.CompareFunc() {
+                    public int compare(Object a, Object b) {
+                        try {
+                            return JS.toInt(jsFunc.call((JS)a, (JS)b, null, null, 2));
+                        } catch(JSExn e) { throw new JSExn.Wrapper(e); }
                     }
-                }
-            });
-        } else {
-            vec.sort(defaultSort);
+                });
+            } else {
+                vec.sort(defaultSort);
+            }
+        } catch(JSExn.Wrapper e) {
+            throw e.refill();
         }
         setFromVec(vec);
         return this;