From 2c3f170edc8e0da2de19f8a902e59fd04ea6c990 Mon Sep 17 00:00:00 2001 From: brian Date: Wed, 2 Jun 2004 02:18:09 +0000 Subject: [PATCH] give an error when trying to trap private variables darcs-hash:20040602021809-24bed-5a2b5c39ced1846a3557574c9875dc51ee25f9c9.gz --- src/org/ibex/js/Interpreter.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/org/ibex/js/Interpreter.java b/src/org/ibex/js/Interpreter.java index 983b471..e89f752 100644 --- a/src/org/ibex/js/Interpreter.java +++ b/src/org/ibex/js/Interpreter.java @@ -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; -- 1.7.10.4