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;