2003/09/23 21:16:10
[org.ibex.core.git] / src / org / xwt / js / CompiledFunctionImpl.java
index 9fe5435..87c527c 100644 (file)
@@ -77,7 +77,8 @@ class CompiledFunctionImpl extends JS.Callable implements ByteCodes, Tokens {
             Object ret = cx.stack.pop();
             if (cx.stack.size() > size)
                 // this should never happen
-                throw new Error("ERROR: stack grew by " + (cx.stack.size() - size) + " elements during call at " + sourceName + ":" + firstLine);
+                throw new Error("ERROR: stack grew by " + (cx.stack.size() - size) +
+                                " elements during call at " + sourceName + ":" + firstLine);
             return ret;
         } catch(Error e) {
             // Unwind the stack
@@ -331,20 +332,26 @@ class CompiledFunctionImpl extends JS.Callable implements ByteCodes, Tokens {
                 Object old = t.pop();
                 Object key = t.pop();
                 Object obj = t.peek();
-                if (obj instanceof org.xwt.Box && val instanceof CompiledFunction) {
-                    if (curOP == ASSIGN_ADD) {
-                        ((org.xwt.Box)obj).addTrap(key, val);
-                    } else {
-                        ((org.xwt.Box)obj).delTrap(key, val);
+                if (val instanceof CompiledFunction) {
+                    if (obj instanceof JS.Scope) {
+                        JS.Scope parent = (JS.Scope)obj;
+                        while(parent.getParentScope() != null) parent = parent.getParentScope();
+                        if (parent instanceof org.xwt.Box) {
+                            if (curOP == ASSIGN_ADD) {
+                                ((org.xwt.Box)parent).addTrap(key, val);
+                            } else {
+                                ((org.xwt.Box)parent).delTrap(key, val);
+                            }
+                            // skip over the "normal" implementation of +=/-=
+                            pc += ((Integer)arg[pc]).intValue() - 1;
+                            break;
+                        }
                     }
-                    // skip over the "normal" implementation of +=/-=
-                    pc += ((Integer)arg[pc]).intValue() - 1;
-                } else {
-                    // use the "normal" implementation
-                    t.push(key);
-                    t.push(old);
-                    t.push(arg);
                 }
+                // use the "normal" implementation
+                t.push(key);
+                t.push(old);
+                t.push(arg);
                 break;
             }