1
2 package org.xwt.js;
3
4 import java.util.*;
5 import org.xwt.util.*;
6 import java.io.*;
7
8
14 class Trap {
15
16 JS trapee = null;
17 Object name = null;
18
19 JSFunction f = null;
20 Trap next = null;
21
22 Trap(JS b, String n, JSFunction f, Trap nx) {
23 trapee = b; name = n; this.f = f; this.next = nx;
24 }
25
26 private static final JSFunction putInvoker = new JSFunction("putInvoker", 0, null);
27 private static final JSFunction getInvoker = new JSFunction("getInvoker", 0, null);
28
29 static {
30 putInvoker.add(1, ByteCodes.PUT, null);
31 putInvoker.add(2, Tokens.RETURN, null);
32 getInvoker.add(1, ByteCodes.GET, null);
33 getInvoker.add(2, Tokens.RETURN, null);
34 }
35
36 void invoke(Object value) throws JSExn {
37 Interpreter i = new Interpreter(putInvoker, false, null);
38 i.stack.push(trapee);
39 i.stack.push(name);
40 i.stack.push(value);
41 i.resume();
42 }
43
44 Object invoke() throws JSExn {
45 Interpreter i = new Interpreter(getInvoker, false, null);
46 i.stack.push(trapee);
47 i.stack.push(name);
48 return i.resume();
49 }
50
51
52 static class TrapScope extends JSScope {
53 Trap t;
54 Object val = null;
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);
62 }
63 }
64 }
65
66