2004/01/03 04:27:27
[org.ibex.core.git] / src / org / xwt / js / JSRegexp.java
index ca22fce..3bb5ab9 100644 (file)
@@ -37,7 +37,7 @@ public class JSRegexp extends JS {
         }
     }
 
-    public Object callMethod(Object method, Object a0, Object a1, Object a2, Object[] rest, int nargs) {
+    public Object callMethod(Object method, Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn {
         switch(nargs) {
             case 1: {
                 //#switch(method)
@@ -74,7 +74,7 @@ public class JSRegexp extends JS {
         return super.callMethod(method, a0, a1, a2, rest, nargs);
     }
     
-    public Object get(Object key) {
+    public Object get(Object key) throws JSExn {
         //#switch(key)
         case "exec": return METHOD;
         case "test": return METHOD;
@@ -84,31 +84,39 @@ public class JSRegexp extends JS {
         return super.get(key);
     }
     
-    public void put(Object key, Object value) {
+    public void put(Object key, Object value) throws JSExn {
         if(key.equals("lastIndex")) lastIndex = JS.toNumber(value).intValue();
         super.put(key,value);
     }
   
     private static Object matchToExecResult(REMatch match, RE re, String s) {
-        JS ret = new JS();
-        ret.put("index", N(match.getStartIndex()));
-        ret.put("input",s);
-        int n = re.getNumSubs();
-        ret.put("length", N(n+1));
-        ret.put("0",match.toString());
-        for(int i=1;i<=n;i++) ret.put(Integer.toString(i),match.toString(i));
-        return ret;
+        try {
+            JS ret = new JS();
+            ret.put("index", N(match.getStartIndex()));
+            ret.put("input",s);
+            int n = re.getNumSubs();
+            ret.put("length", N(n+1));
+            ret.put("0",match.toString());
+            for(int i=1;i<=n;i++) ret.put(Integer.toString(i),match.toString(i));
+            return ret;
+        } catch (JSExn e) {
+            throw new Error("this should never happen");
+        }
     }
     
     public String toString() {
-        StringBuffer sb = new StringBuffer();
-        sb.append('/');
-        sb.append(get("source"));
-        sb.append('/');
-        if(global) sb.append('g');
-        if(Boolean.TRUE.equals(get("ignoreCase"))) sb.append('i');
-        if(Boolean.TRUE.equals(get("multiline"))) sb.append('m');
-        return sb.toString();
+        try {
+            StringBuffer sb = new StringBuffer();
+            sb.append('/');
+            sb.append(get("source"));
+            sb.append('/');
+            if(global) sb.append('g');
+            if(Boolean.TRUE.equals(get("ignoreCase"))) sb.append('i');
+            if(Boolean.TRUE.equals(get("multiline"))) sb.append('m');
+            return sb.toString();
+        } catch (JSExn e) {
+            throw new Error("this should never happen");
+        }
     }
     
     public static Object stringMatch(Object o, Object arg0) throws JSExn {
@@ -263,9 +271,8 @@ public class JSRegexp extends JS {
     }
                     
     
-    public static Object stringSplit(Object o, String s, Object arg0) {
-        // FIXME: reintroduce args.length() < 2 ? Integer.MAX_VALUE : JS.toInt(args.elementAt(1));
-        int limit = JS.toInt(arg0);
+    public static Object stringSplit(String s, Object arg0, Object arg1, int nargs) {
+        int limit = nargs < 2 ? Integer.MAX_VALUE : JS.toInt(arg1);
         if(limit < 0) limit = Integer.MAX_VALUE;
         if(limit == 0) return new JSArray();