X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2Fjs%2FInterpreter.java;h=14f0f19899581397787f5f3bde5e08c914604208;hb=2532e32f07910e63b366ac8e02e897e5314be72c;hp=1b679cafa95d839d7ca07b48fd60ff99349cbc63;hpb=3591b88b94a6bb378af3d4abe6eb5233ce583104;p=org.ibex.core.git diff --git a/src/org/ibex/js/Interpreter.java b/src/org/ibex/js/Interpreter.java index 1b679ca..14f0f19 100644 --- a/src/org/ibex/js/Interpreter.java +++ b/src/org/ibex/js/Interpreter.java @@ -93,7 +93,9 @@ class Interpreter implements ByteCodes, Tokens { case DUP: stack.push(stack.peek()); break; case NEWSCOPE: scope = new JSScope(scope); break; case OLDSCOPE: scope = scope.getParentScope(); break; - case ASSERT: if (!JS.toBoolean(stack.pop())) throw je("ibex.assertion.failed" /*FEATURE: line number*/); break; + case ASSERT: + if (JS.checkAssertions && !JS.toBoolean(stack.pop())) + throw je("ibex.assertion.failed" /*FEATURE: line number*/); break; case BITNOT: stack.push(JS.N(~JS.toLong(stack.pop()))); break; case BANG: stack.push(JS.B(!JS.toBoolean(stack.pop()))); break; case NEWFUNCTION: stack.push(((JSFunction)arg)._cloneWithNewParentScope(scope)); break; @@ -215,10 +217,22 @@ 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 Trap.TrapScope && key.equals("cascade")) { - Trap.TrapScope ts = (Trap.TrapScope)target; - t = ts.t.next; - ts.cascadeHappened = true; + if (target instanceof JSScope && key.equals("cascade")) { + Trap.TrapScope ts = null; + JSScope p = (JSScope)target; // search the scope-path for the trap + if (target instanceof Trap.TrapScope) { + ts = (Trap.TrapScope)target; + } + else { + while (ts == null && p.getParentScope() != null) { + p = p.getParentScope(); + if (p instanceof Trap.TrapScope) { + ts = (Trap.TrapScope)p; + } + } + } + t = ts.t.next; + ts.cascadeHappened = true; while (t != null && t.f.numFormalArgs == 0) t = t.next; if (t == null) { target = ts.t.trapee; key = ts.t.name; } @@ -233,16 +247,13 @@ class Interpreter implements ByteCodes, Tokens { } else { t = ((JS)target).getTrap(key); } - while (t != null && t.f.numFormalArgs == 0) t = t.next; // find the first write trap - if (t != null) { - stack.push(new CallMarker(this)); - JSArray args = new JSArray(); - args.addElement(val); - stack.push(args); - } } if (t != null) { + stack.push(new CallMarker(this)); + JSArray args = new JSArray(); + args.addElement(val); + stack.push(args); f = t.f; scope = new Trap.TrapScope(f.parentScope, t, val); pc = -1; @@ -287,15 +298,12 @@ class Interpreter implements ByteCodes, Tokens { } else { t = ((JS)o).getTrap(v); } - while (t != null && t.f.numFormalArgs != 0) t = t.next; // get first read trap - if (t != null) { - stack.push(new CallMarker(this)); - JSArray args = new JSArray(); - stack.push(args); - } } if (t != null) { + stack.push(new CallMarker(this)); + JSArray args = new JSArray(); + stack.push(args); f = t.f; scope = new Trap.TrapScope(f.parentScope, t, null); ((Trap.TrapScope)scope).cascadeHappened = true; @@ -364,8 +372,9 @@ class Interpreter implements ByteCodes, Tokens { } case THROW: - throw new JSExn(stack.pop()); + throw new JSExn(stack.pop(), stack, f, pc, scope); + /* FIXME case MAKE_GRAMMAR: { final Grammar r = (Grammar)arg; final JSScope final_scope = scope; @@ -387,7 +396,7 @@ class Interpreter implements ByteCodes, Tokens { stack.push(r2); break; } - + */ case ADD_TRAP: case DEL_TRAP: { Object val = stack.pop(); Object key = stack.pop(); @@ -506,7 +515,6 @@ class Interpreter implements ByteCodes, Tokens { } } catch(JSExn e) { - if(f.op[pc] != FINALLY_DONE) e.addBacktrace(f.sourceName,f.line[pc]); while(stack.size() > 0) { Object o = stack.pop(); if (o instanceof CatchMarker || o instanceof TryMarker) { @@ -531,12 +539,6 @@ class Interpreter implements ByteCodes, Tokens { pc = ((TryMarker)o).finallyLoc - 1; continue OUTER; } - } else if(o instanceof CallMarker) { - CallMarker cm = (CallMarker) o; - if(cm.f == null) - e.addBacktrace("",0); // This might not even be worth mentioning - else - e.addBacktrace(cm.f.sourceName,cm.f.line[cm.pc-1]); } } throw e; @@ -555,7 +557,7 @@ class Interpreter implements ByteCodes, Tokens { public CallMarker(Interpreter cx) { pc = cx.pc + 1; scope = cx.scope; f = cx.f; } } - public static class CatchMarker { public CatchMarker() { } } + public static class CatchMarker { } private static CatchMarker catchMarker = new CatchMarker(); public static class LoopMarker { @@ -687,7 +689,7 @@ class Interpreter implements ByteCodes, Tokens { static Object getFromPrimitive(Object o, Object key) throws JSExn { boolean returnJS = false; if (o instanceof Boolean) { - throw new JSExn("cannot call methods on Booleans"); + throw new JSExn("Booleans do not have properties"); } else if (o instanceof Number) { if (key.equals("toPrecision") || key.equals("toExponential") || key.equals("toFixed")) returnJS = true;