1 // Copyright 2003 Adam Megacz, see the COPYING file for licensing [GPL]
9 * This class encapsulates a single trap placed on a given node. The
10 * traps for a given property name on a given box are maintained as a
11 * linked list stack, with the most recently placed trap at the head
16 JS trapee = null; ///< the box on which this trap was placed
17 Object name = null; ///< the property that the trap was placed on
19 JSFunction f = null; ///< the function for this trap
20 Trap next = null; ///< the next trap down the trap stack
22 Trap(JS b, String n, JSFunction f, Trap nx) {
23 trapee = b; name = n; this.f = f; this.next = nx;
26 private static final JSFunction putInvoker = new JSFunction("putInvoker", 0, null);
27 private static final JSFunction getInvoker = new JSFunction("getInvoker", 0, null);
30 putInvoker.add(-1, ByteCodes.PUT, null);
31 putInvoker.add(-1, Tokens.RETURN, null);
32 getInvoker.add(-1, ByteCodes.GET, null);
33 getInvoker.add(-1, Tokens.RETURN, null);
36 void invoke(Object value) throws JSExn {
37 Interpreter i = new Interpreter(putInvoker, false, null);
44 Object invoke() throws JSExn {
45 Interpreter i = new Interpreter(getInvoker, false, null);
51 // FIXME: review; is necessary?
52 static class TrapScope extends JSScope {
55 boolean cascadeHappened = false;
56 public TrapScope(JSScope parent, Trap t, Object val) { super(parent); this.t = t; this.val = val; }
57 public Object get(Object key) throws JSExn {
58 if (key.equals("trapee")) return t.trapee;
59 if (key.equals("callee")) return t.f;
60 if (key.equals("trapname")) return t.name;
61 return super.get(key);