1    package org.xwt.js;
2    
3    /** anything that is callable with the () operator and wasn't compiled from JS code */
4    public abstract class JSCallable extends JS {
5    
6        // return this from get() if the key was actually a method.
7        public static final Object METHOD = new Object();
8    
9        public Object callMethod(Object method, Object a0, Object a1, Object a2, Object[] rest, int nargs) {
10           if (method == null) return call(a0, a1, a2, rest, nargs);
11           Class c = this.getClass();
12           String descrip = c.getName();
13           if (c == Internal.JSCallableStub.class) {
14               descrip = ((Internal.JSCallableStub)this).obj.getClass().getName();
15           }
16           throw new JS.Exn("attempted to call an undefined method ("+method+") on a " + descrip);
17       }
18   
19       public Object call(Object a0, Object a1, Object a2, Object[] rest, int nargs) {
20           Class c = this.getClass();
21           String descrip = c.getName();
22           if (c == Internal.JSCallableStub.class) {
23               descrip = ((Internal.JSCallableStub)this).obj.getClass().getName();
24           }
25           throw new JS.Exn("you cannot call this object (of type " + descrip + ")");
26       }
27   
28   }
29   
30