X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2Fjs%2FInterpreter.java;h=df802e274fb8f50678e4d50ce9ac4fdcd997469f;hb=6547223b65f2b7837605a83115411b59b48c56df;hp=c049088e591bcc59bd236c170717c39de3fd21e9;hpb=e8762b25b82d2113ce27869e7f2f096eca10239e;p=org.ibex.core.git diff --git a/src/org/xwt/js/Interpreter.java b/src/org/xwt/js/Interpreter.java index c049088..df802e2 100644 --- a/src/org/xwt/js/Interpreter.java +++ b/src/org/xwt/js/Interpreter.java @@ -32,7 +32,7 @@ class Interpreter implements ByteCodes, Tokens { } /** this is the only synchronization point we need in order to be threadsafe */ - synchronized Object resume() { + synchronized Object resume() throws JSExn { Thread t = Thread.currentThread(); Interpreter old = (Interpreter)threadToInterpreter.get(t); threadToInterpreter.put(t, this); @@ -167,7 +167,7 @@ class Interpreter implements ByteCodes, Tokens { Trap t = ts.t.next; while (t != null && t.f.numFormalArgs == 0) t = t.next; if (t == null) { - ((JS)ts.t.trapee).put(t.name, ts.val); + ((JS)ts.t.trapee).put(ts.t.name, ts.val); if (pausecount > initialPauseCount) { pc++; return null; } // we were paused } else { stack.push(o); @@ -182,7 +182,7 @@ class Interpreter implements ByteCodes, Tokens { } } scope = ((CallMarker)o).scope; - pc = ((CallMarker)o).pc; + pc = ((CallMarker)o).pc - 1; f = (JSFunction)((CallMarker)o).f; stack.push(retval); continue OUTER; @@ -203,7 +203,7 @@ class Interpreter implements ByteCodes, Tokens { throw je("tried to assign \"" + (val==null?"(null)":val.toString()) + "\" to the null key"); Trap t = null; if (target instanceof JS) { - t = ((JS)target).getTrap(val); + t = ((JS)target).getTrap(key); while (t != null && t.f.numFormalArgs == 0) t = t.next; } else if (target instanceof Trap.TrapScope && key.equals("cascade")) { Trap.TrapScope ts = (Trap.TrapScope)target; @@ -241,7 +241,7 @@ class Interpreter implements ByteCodes, Tokens { } Object ret = null; if (v == null) throw je("tried to get the null key from " + o); - if (o == null) throw je("tried to get property \"" + v + "\" from the null value @" + pc + "\n" + f.dump()); + if (o == null) throw je("tried to get property \"" + v + "\" from the null object"); if (o instanceof String || o instanceof Number || o instanceof Boolean) { ret = getFromPrimitive(o,v); stack.push(ret); @@ -285,12 +285,15 @@ class Interpreter implements ByteCodes, Tokens { if (object == JS.METHOD) { method = stack.pop(); object = stack.pop(); + } else if (object == null) { + Object name = stack.pop(); + stack.pop(); + throw new JSExn("function '"+name+"' not found"); } else { stack.pop(); stack.pop(); } } - Object[] rest = numArgs > 3 ? new Object[numArgs - 3] : null; for(int i=numArgs - 1; i>2; i--) rest[i-3] = stack.pop(); Object a2 = numArgs <= 2 ? null : stack.pop(); @@ -524,7 +527,7 @@ class Interpreter implements ByteCodes, Tokens { // Operations on Primitives ////////////////////////////////////////////////////////////////////// - static Object callMethodOnPrimitive(Object o, Object method, Object arg0, Object arg1, Object arg2, Object[] rest, int alength) { + static Object callMethodOnPrimitive(Object o, Object method, Object arg0, Object arg1, Object arg2, Object[] rest, int alength) throws JSExn { if (o instanceof Number) { //#switch(method) case "toFixed": throw new JSExn("toFixed() not implemented"); @@ -613,7 +616,7 @@ class Interpreter implements ByteCodes, Tokens { throw new JSExn("Attempted to call non-existent method: " + method); } - static Object getFromPrimitive(Object o, Object key) { + static Object getFromPrimitive(Object o, Object key) throws JSExn { boolean returnJS = false; if (o instanceof Boolean) { throw new JSExn("cannot call methods on Booleans"); @@ -644,14 +647,14 @@ class Interpreter implements ByteCodes, Tokens { case "toLowerCase": returnJS = true; break; case "toUpperCase": returnJS = true; break; case "toString": returnJS = true; break; - case "substr": returnJS = true; break; - //#end + case "substr": returnJS = true; break; + //#end } if (returnJS) { final Object target = o; final String method = key.toString(); return new JS() { - public Object call(Object a0, Object a1, Object a2, Object[] rest, int nargs) { + public Object call(Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn { if (nargs > 2) throw new JSExn("cannot call that method with that many arguments"); return callMethodOnPrimitive(target, method, a0, a1, a2, rest, nargs); } @@ -664,7 +667,7 @@ class Interpreter implements ByteCodes, Tokens { private Object method; JS obj; public Stub(JS obj, Object method) { this.obj = obj; this.method = method; } - public Object call(Object a0, Object a1, Object a2, Object[] rest, int nargs) { + public Object call(Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn { return ((JS)obj).callMethod(method, a0, a1, a2, rest, nargs); } }