// Static Data //////////////////////////////////////////////////////////////
/** a vector of weak references to all instances of Trap; used for retheming */
- private static Vec allTraps = new Vec(1000);
+ private static Hashtable allTraps = new Hashtable(1000);
/** List of properties that cannot be trapped */
private static final Hash PROHIBITED = new Hash(120, 3);
for(int i=0; i<p.length; i++) PROHIBITED.put(p[i], Boolean.TRUE);
};
+ private static Object dummy = new Object();
+
+
// Instance Members ////////////////////////////////////////////////////////
/** the box on which this trap was placed */
/** The nodeName of the Template whose script placed the trap. See Template.nodeName for more detail. */
private String placerNodeName = null;
- /** the index of this Trap in the allTraps vector */
- private int indexInAllTraps = 0;
+ /** our weak reference in the allTraps Hash */
+ private Weak myWeak = Platform.getWeak(this);
+
// Static Methods //////////////////////////////////////////////////////////////////////////
static void addTrap(Box trapee, String name, Function f, boolean isreadtrap, Scriptable rp) {
if (PROHIBITED.get(name) != null || name.startsWith("xwt_")) {
- System.out.println("Error: you cannot place traps on special property \"" + name + "\"");
+ Log.log(Trap.class, "Error: you cannot place traps on special property \"" + name + "\"");
return;
}
else return current.trapee;
}
+ /** called by Rhino's arguments.trapname hack */
+ public static String currentTrapname() {
+ Trap current = TrapContext.get().currentTrap;
+ if (current == null) return null;
+ else return current.name;
+ }
+
/** removes all traps whose function's ultimate parent scope is <tt>b</tt>. Used for retheming */
public static void removeAllTrapsByBox(Box b) {
- for(int i=0; i<allTraps.size(); i++) {
- Trap t = (Trap)((Weak)allTraps.elementAt(i)).get();
- if (t == null) continue;
+ Enumeration e = allTraps.keys();
+ while(e.hasMoreElements()) {
+ Weak w = (Weak)e.nextElement();
+ Trap t = (Trap)w.get();
+ if (t == null) {
+ allTraps.remove(w);
+ continue;
+ }
for(Scriptable cur = t.f; cur != null; cur = cur.getParentScope()) {
if (cur == b) {
t.delete();
- i--;
break;
}
}
}
}
+
// Instance Methods //////////////////////////////////////////////////////////////////////////
- private Trap() {
- indexInAllTraps = allTraps.size();
- allTraps.addElement(Platform.getWeak(this));
- }
+ private Trap() { allTraps.put(myWeak, dummy); }
/** perform this trap -- arg.length == 0 if this is a get; otherwise it contains a single element to be put */
public Object perform(Object[] arg) {
}
if (trapee.surface != null && !trapee.is_trapped("KeyPressed") && !trapee.is_trapped("KeyReleased"))
trapee.surface.keywatchers.removeElement(trapee);
- if (allTraps.size() == 1) allTraps.setSize(0);
- else {
- allTraps.setElementAt(allTraps.elementAt(allTraps.size() - 1), indexInAllTraps);
- allTraps.setSize(allTraps.size() - 1);
- }
+ allTraps.remove(myWeak);
}
/** per-thread storage for Traps */
}
}
+