2003/11/13 05:04:22
[org.ibex.core.git] / src / org / xwt / js / Regexp.java
index fd85881..834a425 100644 (file)
@@ -7,9 +7,7 @@ public class Regexp extends JS.Obj {
     private RE re;
     private int lastIndex;
     
-    public Regexp(JS.Array args) throws JS.Exn {
-        if(args.length() < 1) throw new JS.Exn("Not enough args to regexp");
-        Object arg0 = args.elementAt(0);
+    public Regexp(Object arg0, Object arg1) throws JS.Exn {
         if(arg0 instanceof Regexp) {
             Regexp r = (Regexp) arg0;
             this.global = r.global;
@@ -19,7 +17,7 @@ public class Regexp extends JS.Obj {
             String pattern = arg0.toString();
             String sFlags = null;
             int flags = 0;
-            if(args.length() == 2) sFlags = args.elementAt(1).toString();
+            if(arg1 != null) sFlags = (String)arg1;
             if(sFlags == null) sFlags = "";
             for(int i=0;i<sFlags.length();i++) {
                 switch(sFlags.charAt(i)) {
@@ -30,26 +28,38 @@ public class Regexp extends JS.Obj {
                 }
             }
             re = newRE(pattern,flags);
-            put("source",pattern);
-            put("global",wrapBool(global));
-            put("ignoreCase",wrapBool(flags & RE.REG_ICASE));
-            put("multiline",wrapBool(flags & RE.REG_MULTILINE));
+            _put("source",pattern);
+            _put("global",wrapBool(global));
+            _put("ignoreCase",wrapBool(flags & RE.REG_ICASE));
+            _put("multiline",wrapBool(flags & RE.REG_MULTILINE));
+        }
+    }
+
+    public Object callMethod(Object method, Array args, boolean checkOnly) throws JS.Exn {
+        if (method.equals("exec")) {
+            if (checkOnly) return Boolean.TRUE;
+            return exec(args);
+        } else if (method.equals("test")) {
+            if (checkOnly) return Boolean.TRUE;
+            return test(args);
+        } else if (method.equals("toString")) {
+            if (checkOnly) return Boolean.TRUE;
+            return toString();
         }
-        // FIXME: Do whatever we need to do to take advantage of the GETCALL bytecode when its available
-        final JS.Callable execFN = new JS.Callable() { public Object call(JS.Array args) { return exec(args); } };
-        final JS.Callable testFN = new JS.Callable() { public Object call(JS.Array args) { return test(args); } };
-        final JS.Callable toStringFN = new JS.Callable() { public Object call(JS.Array args) { return Regexp.this.toString(); } };
-        put("exec",execFN);
-        put("test",testFN);
-        put("toString",toStringFN);
+        if (checkOnly) return Boolean.FALSE;
+        return null;
     }
     
-    public Object get(Object key) {
+    // gcj bug...
+    public Object get(Object key) { return _get(key); }
+    public Object put(Object key,Object value) { _put(key,value); return null; }
+
+    public Object _get(Object key) {
         if(key.equals("lastIndex")) return new Integer(lastIndex);
         return super.get(key);
     }
     
-    public void put(Object key, Object value) {
+    public void _put(Object key, Object value) {
         if(key.equals("lastIndex")) lastIndex = JS.toNumber(value).intValue();
         super.put(key,value);
     }
@@ -111,11 +121,11 @@ public class Regexp extends JS.Obj {
     public String toString() {
         StringBuffer sb = new StringBuffer();
         sb.append('/');
-        sb.append(get("source"));
+        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');
+        if(Boolean.TRUE.equals(_get("ignoreCase"))) sb.append('i');
+        if(Boolean.TRUE.equals(_get("multiline"))) sb.append('m');
         return sb.toString();
     }
     
@@ -346,4 +356,6 @@ public class Regexp extends JS.Obj {
     private static Boolean wrapBool(int n) {
         return wrapBool(n != 0);
     }
+    
+    public String typeName() { return "regexp"; }
 }