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;
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);
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) {
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());
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 + ")");
}
}