more trap cleanup, properly handle JS.Clones
[org.ibex.core.git] / src / org / ibex / js / JS.java
index a81c419..c13d2a0 100644 (file)
@@ -44,7 +44,7 @@ public abstract class JS {
     String debugToString() { return "[class=" + getClass().getName() + "]"; }
     boolean jsequals(JS o) { return this == o; }
     
-    public static class O extends JS {
+    public static class O extends JS implements Cloneable {
         private Hash entries;
         
         public Enumeration keys() throws JSExn { return entries == null ? (Enumeration)EMPTY_ENUMERATION : (Enumeration)new JavaEnumeration(null,entries.keys()); }
@@ -85,7 +85,7 @@ public abstract class JS {
     
     public interface Cloneable { }
     
-    public static class Clone extends JS.O implements Cloneable {
+    public static class Clone extends JS.O {
         protected final JS clonee;
         JS _unclone() { return clonee.unclone(); }
         public JS getClonee() { return clonee; }
@@ -95,8 +95,8 @@ public abstract class JS {
         }
         public boolean jsequals(JS o) { return unclone().jsequals(o.unclone()); }
         public Enumeration keys() throws JSExn { return clonee.keys(); }
-        public JS get(JS key) throws JSExn { return clonee.get(key); }
-        public void put(JS key, JS val) throws JSExn { clonee.put(key, val); }
+        public JS get(JS key) throws JSExn { return clonee.getAndTriggerTraps(key); }
+        public void put(JS key, JS val) throws JSExn { clonee.putAndTriggerTraps(key, val); }
         public JS callMethod(JS method, JS a0, JS a1, JS a2, JS[] rest, int nargs) throws JSExn {
             return clonee.callMethod(method, a0, a1, a2, rest, nargs);
         }
@@ -300,15 +300,17 @@ public abstract class JS {
     /** performs a put, triggering traps if present; traps are run in an unpauseable interpreter */
     public void putAndTriggerTraps(JS key, JS value) throws JSExn {
         Trap t = getTrap(key);
-        if (t != null) t.invoke(value);
-        else put(key, value);
+        throw new Error("FIXME");
+        /*if (t != null) t.invoke(value);
+        elese put(key, value);*/
     }
 
     /** performs a get, triggering traps if present; traps are run in an unpauseable interpreter */
     public JS getAndTriggerTraps(JS key) throws JSExn {
         Trap t = getTrap(key);
-        if (t != null) return t.invoke();
-        else return get(key);
+        throw new Error("FIXME");
+        /*if (t != null) return t.invoke();
+        else return get(key);*/
     }
 
     /** adds a trap, avoiding duplicates */
@@ -323,7 +325,7 @@ public abstract class JS {
     final void delTrap(JS key, JSFunction f) throws JSExn {
         Trap t = (Trap)getTrap(key);
         if (t == null) return;
-        if (t.f == f) { putTrap(t.name, t.next); return; }
+        if (t.f == f) { putTrap(t.target, t.next); return; }
         for(; t.next != null; t = t.next) if (t.next.f == f) { t.next = t.next.next; return; }
     }