X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2Fjs%2FJSCallable.java;h=c9c09d01e9b91853aaf1cf485fd027a3cf44d50b;hb=8c1756ef3fd42cc2f324baf47e13a83f51045efe;hp=8865f3ba2b7e45eb5bf84b3c741a6d24a38cf976;hpb=2b1b2ef9bb8b8a34efb6329c552eea4f773d9466;p=org.ibex.core.git diff --git a/src/org/xwt/js/JSCallable.java b/src/org/xwt/js/JSCallable.java index 8865f3b..c9c09d0 100644 --- a/src/org/xwt/js/JSCallable.java +++ b/src/org/xwt/js/JSCallable.java @@ -1,35 +1,18 @@ package org.xwt.js; /** anything that is callable with the () operator and wasn't compiled from JS code */ -public abstract class JSCallable extends JSObj { - public Object call0(Object method) throws JS.Exn { - JSArray args = new JSArray(); - return call(method, args); - } - public Object call1(Object method, Object arg1) throws JS.Exn { - JSArray args = new JSArray(); - args.addElement(arg1); - return call(method, args); - } - public Object call2(Object method, Object arg1, Object arg2) throws JS.Exn { - JSArray args = new JSArray(); - args.addElement(arg1); - args.addElement(arg2); - return call(method, args); +public abstract class JSCallable extends JS { + + // return this from get() if the key was actually a method. + public static final Object METHOD = new Object(); + + public Object callMethod(Object method, Object a0, Object a1, Object a2, Object[] rest, int nargs) { + throw new JS.Exn("attempted to call an undefined method"); } - public Object call(Object method, JSArray args) throws JS.Exn { - 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"); + + public Object call(Object a0, Object a1, Object a2, Object[] rest, int nargs) { + throw new JS.Exn("you cannot call this object"); } + }