give an error when trying to trap private variables
authorbrian <brian@brianweb.net>
Wed, 2 Jun 2004 02:18:09 +0000 (02:18 +0000)
committerbrian <brian@brianweb.net>
Wed, 2 Jun 2004 02:18:09 +0000 (02:18 +0000)
darcs-hash:20040602021809-24bed-5a2b5c39ced1846a3557574c9875dc51ee25f9c9.gz

src/org/ibex/js/Interpreter.java

index 983b471..e89f752 100644 (file)
@@ -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;