- /** the result of a graft */
- public static class Graft extends JSCallable {
- private JS graftee;
- private Object replaced_key;
- private Object replaced_val;
- public Graft(Object graftee, Object key, Object val) {
- if (graftee instanceof JSArray) throw new JS.Exn("can't graft onto JSArrays (yet)");
- if (graftee instanceof JSCallable) throw new JS.Exn("can't graft onto JSCallables (yet)");
- if (graftee instanceof JSScope) throw new JS.Exn("can't graft onto JSScopes (yet)");
- this.graftee = (JS)graftee;
- replaced_key = key;
- replaced_val = val;
- }
- public boolean equals(Object o) { return (this == o || graftee.equals(o)); }
- public int hashCode() { return graftee.hashCode(); }
- public Object get(Object key) { return replaced_key.equals(key) ? replaced_val : graftee.get(key); }
- public void put(Object key, Object val) { graftee.put(key, val); }
- public void call(Object method, JSArray args) {
- if (replaced_key.equals(method)) return ((JSCallable)replaced_val).call(null, args);
- else if (graftee instanceof JSCallable) return graftee.call(method, args);
- else throw new JS.Exn("cannot call this value");
- }
- public Number coerceToNumber() { return graftee.coerceToNumber(); }
- public String coerceToString() { return graftee.coerceToString(); }
- public boolean coerceToBoolean() { return graftee.coerceToBoolean(); }
- public String typeName() { return graftee.typeName(); }
- public Enumeration keys() {
- return new Enumeration() {
- Enumeration graftee_enumeration = graftee.keys();
- boolean returned_replaced = false;
- public boolean hasMoreElements() {
- if (graftee_enumeration.hasMoreElements()) return true;
- return !returned_replaced;
- }
- public Object nextElement() {
- if (!graftee_enumeration.hasMoreElements()) {
- if (returned_replaced) throw new NoSuchElementException();
- returned_replaced = true;
- return replaced_key;
- } else {
- Object ret = graftee_enumeration.nextElement();
- if (!returned_replaced && ret.equals(replaced_key)) returned_replaced = true;
- return ret;
- }
- }
- };
- }
+ /** retrieve a trap from the entries hash */
+ protected final void putTrap(Object key, Trap value) {
+ if (!isTrappable()) return;
+ if (entries == null) entries = new Hash();
+ entries.put(key, Trap.class, value);