jswitch
[org.ibex.core.git] / src / org / ibex / js / JSArray.java
index 8aa5325..d0cd550 100644 (file)
@@ -24,40 +24,38 @@ public class JSArray extends JS.BT {
     }*/
     
     public JS callMethod(JS method, JS a0, JS a1, JS a2, JS[] rest, int nargs) throws JSExn {
-        if(isString(method)) {
-            //#switch(JS.toString(method))
-            case "pop": {
-                int oldSize = size();
-                if(oldSize == 0) return null;
-                return removeElementAt(oldSize-1);
-            }
-            case "reverse": return reverse();
-            case "toString": return join(",");
-            case "shift":
-                if(length() == 0) return null;
-                return removeElementAt(0);
-            case "join":
-                return join(nargs == 0 ? "," : JS.toString(a0));
-            case "sort":
-                return sort(nargs < 1 ? null : a0);
-            case "slice":
-                int start = toInt(nargs < 1 ? null : a0);
-                int end = nargs < 2 ? length() : toInt(a1);
-                return slice(start, end);
-            case "push": {
-                int oldSize = size();
-                for(int i=0; i<nargs; i++) insertElementAt(i==0?a0:i==1?a1:i==2?a2:rest[i-3],oldSize+i);
-                return N(oldSize + nargs);
-            }
-            case "unshift":
-                for(int i=0; i<nargs; i++) insertElementAt(i==0?a0:i==1?a1:i==2?a2:rest[i-3],i);
-                return N(size());
-            case "splice":
-                JSArray array = new JSArray();
-                for(int i=0; i<nargs; i++) array.addElement(i==0?a0:i==1?a1:i==2?a2:rest[i-3]);
-                return splice(array);
-            //#end
+        //#jswitch(method)
+        case "pop": {
+            int oldSize = size();
+            if(oldSize == 0) return null;
+            return removeElementAt(oldSize-1);
         }
+        case "reverse": return reverse();
+        case "toString": return join(",");
+        case "shift":
+            if(length() == 0) return null;
+            return removeElementAt(0);
+        case "join":
+            return join(nargs == 0 ? "," : JS.toString(a0));
+        case "sort":
+            return sort(nargs < 1 ? null : a0);
+        case "slice":
+            int start = toInt(nargs < 1 ? null : a0);
+            int end = nargs < 2 ? length() : toInt(a1);
+            return slice(start, end);
+        case "push": {
+            int oldSize = size();
+            for(int i=0; i<nargs; i++) insertElementAt(i==0?a0:i==1?a1:i==2?a2:rest[i-3],oldSize+i);
+            return N(oldSize + nargs);
+        }
+        case "unshift":
+            for(int i=0; i<nargs; i++) insertElementAt(i==0?a0:i==1?a1:i==2?a2:rest[i-3],i);
+            return N(size());
+        case "splice":
+            JSArray array = new JSArray();
+            for(int i=0; i<nargs; i++) array.addElement(i==0?a0:i==1?a1:i==2?a2:rest[i-3]);
+            return splice(array);
+        //#end
         return super.callMethod(method, a0, a1, a2, rest, nargs);
     }
         
@@ -67,21 +65,19 @@ public class JSArray extends JS.BT {
             if (i < 0 || i >= size()) return null;
             return elementAt(i);
         }
-        if(isString(key)) {
-            //#switch(JS.toString(key))
-            case "pop": return METHOD;
-            case "reverse": return METHOD;
-            case "toString": return METHOD;
-            case "shift": return METHOD;
-            case "join": return METHOD;
-            case "sort": return METHOD;
-            case "slice": return METHOD;
-            case "push": return METHOD;
-            case "unshift": return METHOD;
-            case "splice": return METHOD;
-            case "length": return N(size());
-            //#end
-        }
+        //#jswitch(key)
+        case "pop": return METHOD;
+        case "reverse": return METHOD;
+        case "toString": return METHOD;
+        case "shift": return METHOD;
+        case "join": return METHOD;
+        case "sort": return METHOD;
+        case "slice": return METHOD;
+        case "push": return METHOD;
+        case "unshift": return METHOD;
+        case "splice": return METHOD;
+        case "length": return N(size());
+        //#end
         return super.get(key);
     }