2003/11/17 05:23:32
authormegacz <megacz@xwt.org>
Fri, 30 Jan 2004 07:41:41 +0000 (07:41 +0000)
committermegacz <megacz@xwt.org>
Fri, 30 Jan 2004 07:41:41 +0000 (07:41 +0000)
darcs-hash:20040130074141-2ba56-427a8bdf3d84425eab08f7f08725f2a4cedd48f1.gz

src/org/xwt/js/Internal.java
src/org/xwt/js/Interpreter.java
src/org/xwt/js/JSCallable.java

index 4cddef1..d1ac346 100644 (file)
@@ -130,8 +130,11 @@ class Internal {
             final Object target = o;
             final String method = key.toString();
             return new JSCallable() {
-                    // FIXME
-                public Object call(Object notUsed, JSArray args) { return callMethodOnPrimitive(target,method,args); }
+                    public Object call(Object a0, Object a1, Object a2, Object[] rest, int nargs) {
+                        JSArray args = new JSArray();
+                        for(int i=0; i<nargs; i++) args.addElement(i==0?a0:i==1?a1:i==2?a2:rest[i-3]);
+                        return callMethodOnPrimitive(target,method,args);
+                    }
             };
         }
         return null;
@@ -139,7 +142,7 @@ class Internal {
     
     static class JSCallableStub extends JSCallable {
         private Object method;
-        private JS obj;
+        JS obj;
         public JSCallableStub(JS obj, Object method) { this.obj = obj; this.method = method; }
         public Object call(Object a0, Object a1, Object a2, Object[] rest, int nargs) {
             return ((JSCallable)obj).callMethod(method, a0, a1, a2, rest, nargs);
index a9ea8a3..c9bcd73 100644 (file)
@@ -241,9 +241,14 @@ class Interpreter implements ByteCodes, Tokens {
 
                 if (op == CALL) {
                     object = cx.stack.pop();
-                } else if (object == JSCallable.METHOD) {
-                    method = cx.stack.pop();
-                    object = cx.stack.pop();
+                } else {
+                    if (object == JSCallable.METHOD) {
+                        method = cx.stack.pop();
+                        object = cx.stack.pop();
+                    } else {
+                        cx.stack.pop();
+                        cx.stack.pop();
+                    }
                 }
 
                 if (object instanceof String || object instanceof Number || object instanceof Boolean) {
@@ -269,7 +274,7 @@ class Interpreter implements ByteCodes, Tokens {
                     Object a2 = numArgs <= 2 ? null : cx.stack.pop();
                     Object a1 = numArgs <= 1 ? null : cx.stack.pop();
                     Object a0 = numArgs <= 0 ? null : cx.stack.pop();
-                    ret = c.callMethod(method, a0, a1, a2, rest, numArgs);
+                    ret = method == null ? c.call(a0, a1, a2, rest, numArgs) : c.callMethod(method, a0, a1, a2, rest, numArgs);
 
                 } else {
                     throw new JS.Exn("can't call a " + object.getClass().getName() + " @" + cx.pc + "\n" + cx.f.dump());
index c9c09d0..ac44c5c 100644 (file)
@@ -7,11 +7,22 @@ public abstract class JSCallable extends JS {
     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");
+        if (method == null) return call(a0, a1, a2, rest, nargs);
+        Class c = this.getClass();
+        String descrip = c.getName();
+        if (c == Internal.JSCallableStub.class) {
+            descrip = ((Internal.JSCallableStub)this).obj.getClass().getName();
+        }
+        throw new JS.Exn("attempted to call an undefined method ("+method+") on a " + descrip);
     }
 
     public Object call(Object a0, Object a1, Object a2, Object[] rest, int nargs) {
-        throw new JS.Exn("you cannot call this object");
+        Class c = this.getClass();
+        String descrip = c.getName();
+        if (c == Internal.JSCallableStub.class) {
+            descrip = ((Internal.JSCallableStub)this).obj.getClass().getName();
+        }
+        throw new JS.Exn("you cannot call this object (of type " + descrip + ")");
     }
 
 }