From: crawshaw Date: Thu, 6 Jan 2005 21:20:37 +0000 (+0000) Subject: bug fixes X-Git-Url: http://git.megacz.com/?p=org.ibex.js.git;a=commitdiff_plain;h=b7d7d6f7dc1ddac7889d8334c194a96f344524e7;hp=5a5f5ef235158d513c1f2879dc916b115a4fa9d0 bug fixes darcs-hash:20050106212037-2eb37-fc34cd550e32dca15a4e4fd73b53b6f56893b518.gz --- diff --git a/src/org/ibex/js/Interpreter.java b/src/org/ibex/js/Interpreter.java index 80de88d..b0eb602 100644 --- a/src/org/ibex/js/Interpreter.java +++ b/src/org/ibex/js/Interpreter.java @@ -338,7 +338,13 @@ class Interpreter implements ByteCodes, Tokens, Pausable { } 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; @@ -406,7 +412,7 @@ class Interpreter implements ByteCodes, Tokens, Pausable { 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; @@ -515,7 +521,7 @@ class Interpreter implements ByteCodes, Tokens, Pausable { */ 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) { diff --git a/src/org/ibex/js/JSNumber.java b/src/org/ibex/js/JSNumber.java index 836c5e7..a2a6cea 100644 --- a/src/org/ibex/js/JSNumber.java +++ b/src/org/ibex/js/JSNumber.java @@ -5,7 +5,7 @@ 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; diff --git a/src/org/ibex/js/JSString.java b/src/org/ibex/js/JSString.java index 2e40da8..a0ca694 100644 --- a/src/org/ibex/js/JSString.java +++ b/src/org/ibex/js/JSString.java @@ -12,7 +12,7 @@ class JSString extends JSPrimitive { 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); diff --git a/src/org/ibex/js/Test.java b/src/org/ibex/js/Test.java index b5d8b8d..9598db4 100644 --- a/src/org/ibex/js/Test.java +++ b/src/org/ibex/js/Test.java @@ -66,19 +66,20 @@ public class Test extends JS.Obj { 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; }