X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=sidebyside;f=src%2Forg%2Fibex%2Fjs%2FInterpreter.java;h=6fc2859c30fe596b45c8625f83cb16a288f2ece2;hb=efb8222281235696686fd094844e1d2dcab916ae;hp=983b47173b03694fc55b23a917f1e220176ae1b8;hpb=bf8dd22d35e1f8f5afd6896d65a4f106305665d3;p=org.ibex.core.git diff --git a/src/org/ibex/js/Interpreter.java b/src/org/ibex/js/Interpreter.java index 983b471..6fc2859 100644 --- a/src/org/ibex/js/Interpreter.java +++ b/src/org/ibex/js/Interpreter.java @@ -6,7 +6,7 @@ import java.util.*; /** Encapsulates a single JS interpreter (ie call stack) */ class Interpreter implements ByteCodes, Tokens { - + private static final int MAX_STACK_SIZE = 512; // Thread-Interpreter Mapping ///////////////////////////////////////////////////////////////////////// @@ -236,9 +236,6 @@ class Interpreter implements ByteCodes, Tokens { while (t != null && t.f.numFormalArgs == 0) t = t.next; if (t == null) { target = ts.t.trapee; key = ts.t.name; } - } else if (target instanceof Trap.TrapScope && key.equals(((Trap.TrapScope)target).t.name)) { - throw je("tried to put to " + key + " inside a trap it owns; use cascade instead"); - } else if (target instanceof JS) { if (target instanceof JSScope) { JSScope p = (JSScope)target; // search the scope-path for the trap @@ -251,6 +248,7 @@ class Interpreter implements ByteCodes, Tokens { } if (t != null) { stack.push(new CallMarker(this)); + if(stack.size() > MAX_STACK_SIZE) throw new JSExn("stack overflow"); JSArray args = new JSArray(); args.addElement(val); stack.push(args); @@ -302,6 +300,7 @@ class Interpreter implements ByteCodes, Tokens { } if (t != null) { stack.push(new CallMarker(this)); + if(stack.size() > MAX_STACK_SIZE) throw new JSExn("stack overflow"); JSArray args = new JSArray(); stack.push(args); f = t.f; @@ -352,6 +351,7 @@ class Interpreter implements ByteCodes, Tokens { JSArray arguments = new JSArray(); for(int i=0; i MAX_STACK_SIZE) throw new JSExn("stack overflow"); stack.push(arguments); f = (JSFunction)object; scope = new JSScope(f.parentScope); @@ -402,7 +402,17 @@ class Interpreter implements ByteCodes, Tokens { Object key = stack.pop(); Object obj = stack.peek(); // A trap addition/removal - JS js = obj instanceof JSScope ? ((JSScope)obj).top() : (JS) obj; + JS js = (JS) obj; + if(js instanceof JSScope) { + JSScope s = (JSScope) js; + while(s.getParentScope() != null) { + if(s.has(key)) throw new JSExn("cannot trap a variable that isn't at the top level scope"); + s = s.getParentScope(); + } + js = s; + } + // might want this? + // if(!js.has(key)) throw new JSExn("tried to add/remove a trap from an uninitialized variable"); if(op == ADD_TRAP) js.addTrap(key, (JSFunction)val); else js.delTrap(key, (JSFunction)val); break;