- if (val instanceof JSFunction && obj instanceof JSScope) {
- JSScope parent = (JSScope)obj;
- while(parent.getParentScope() != null) parent = parent.getParentScope();
- if (parent instanceof JS) {
- JS b = (JS)parent;
- if (op == ASSIGN_ADD) b.addTrap(key, (JSFunction)val);
- else b.delTrap(key, (JSFunction)val);
- // skip over the "normal" implementation of +=/-=
- pc += ((Integer)arg).intValue() - 1;
- break;
- }
+ if (val instanceof JSFunction && obj instanceof JS) {
+ // A trap addition/removal
+ JS js = obj instanceof JSScope ? ((JSScope)obj).top() : (JS) obj;
+ if(op == ASSIGN_ADD) js.addTrap(key, (JSFunction)val);
+ else js.delTrap(key, (JSFunction)val);
+ pc += ((Integer)arg).intValue() - 1;
+ } else {
+ // The following setup is VERY important. The generated bytecode depends on the stack
+ // being setup like this (top to bottom) KEY, OBJ, VAL, KEY, OBJ
+ stack.push(key);
+ stack.push(val);
+ stack.push(obj);
+ stack.push(key);