2003/11/16 02:40:44
[org.ibex.core.git] / src / org / xwt / js / JSCallable.java
index 42def05..8865f3b 100644 (file)
@@ -18,7 +18,18 @@ public abstract class JSCallable extends JSObj {
         return call(method, args);
     }
     public Object call(Object method, JSArray args) throws JS.Exn {
-        throw new JS.Exn("cannot invoke this method with " + args.size() + " arguments");
+        if (method != null) {
+            Object meth = get(method);
+            if (meth == null) throw new JS.Exn("attempt to invoke the null method");
+            if (!(meth instanceof JSCallable)) throw new JS.Exn("cannot call a " + meth.getClass().getName());
+            switch (args.size()) {
+                case 0: return ((JSCallable)meth).call0(null);
+                case 1: return ((JSCallable)meth).call1(null, args.elementAt(0));
+                case 2: return ((JSCallable)meth).call2(null, args.elementAt(0), args.elementAt(1));
+                default: return ((JSCallable)meth).call(null, args);
+            }
+        }
+        throw new JS.Exn("cannot invoke method " + method + " on object " + this.getClass().getName() + " with " + args.size() + " arguments");
     }
 }