}
case CALL: case CALLMETHOD: {
- JS[] jsargs = (JS[])arg;
+ // FIXME: can a lot of simple cases in Parser be
+ // reduced so creating a new JS[] is not necessary?
+ JS[] jsargs;
+ if (arg instanceof JSNumber.I) {
+ jsargs = new JS[((JSNumber.I)arg).toInt()];
+ for (int i=0; i < jsargs.length; i++) jsargs[i] = (JS)stack.pop();
+ } else jsargs = (JS[])arg;
JS method = null;
JS ret = null;
JS key = (JS)stack.pop();
JS js = (JS)stack.peek();
// A trap addition/removal
- if(!(val instanceof JSFunction)) throw new JSExn("tried to add/remove a non-function trap");
+ if(!(val instanceof JSFunction)) throw new JSExn("tried to add/remove a non-function trap"); // FIXME
if(op == ADD_TRAP) js.addTrap(key, val);
else js.delTrap(key, val);
break;
*/
void catchException(JSExn e) throws JSExn {
while(!stack.empty()) {
- JS o = (JS)stack.pop();
+ Object o = stack.pop();
if (o instanceof CatchMarker || o instanceof TryMarker) {
boolean inCatch = o instanceof CatchMarker;
if(inCatch) {
package org.ibex.js;
abstract class JSNumber extends JSPrimitive {
- boolean jsequals(JS o) {
+ public boolean equals(Object o) {
if(o == this) return true;
if(o instanceof JSNumber) {
JSNumber n = (JSNumber) o;
public JSString(String s) { this.s = s; }
public int hashCode() { return s.hashCode(); }
- public boolean jsequals(JS o) {
+ public boolean equals(Object o) {
if(o == this) return true;
if(o instanceof JSString) {
return ((JSString)o).s.equals(s);
super.put(key,val);
}
- public JS callMethod(JS method, JS a0, JS a1, JS a2, JS[] rest, int nargs) throws JSExn {
+ public JS call(JS method, JS[] args) throws JSExn {
if(!Script.isString(method)) return null;
if("print".equals(Script.toString(method))) {
- System.out.println(Script.str(a0));
+ System.out.println(Script.str(args[0]));
return null;
}
- if("clone".equals(Script.toString(method))) return a0 == null ? null : new JS.Clone(a0);
+ if("clone".equals(Script.toString(method)))
+ return args.length < 1 || args[0] == null ? null : new JS.Clone(args[0]);
if("firethis".equals(Script.toString(method))) {
- String action = Script.toString(a0);
- JS target = a1;
- JS key = a2;
- if(action.equals("get")) return a1.getAndTriggerTraps(key);
- else if(action.equals("put")) a1.putAndTriggerTraps(key,Script.S("some value"));
+ String action = Script.toString(args[0]);
+ JS target = args[1];
+ JS key = args[2];
+ if(action.equals("get")) return args[1].getAndTriggerTraps(key);
+ else if(action.equals("put")) args[1].putAndTriggerTraps(key,Script.S("some value"));
else if(action.equals("trigger")) return target.justTriggerTraps(key,Script.S("some trigger value"));
return null;
}