jswitch
[org.ibex.core.git] / src / org / ibex / js / JS.java
index c13d2a0..65ba3f6 100644 (file)
@@ -74,13 +74,7 @@ public abstract class JS {
         public final void replaceNode(int index, Object o) { bt().replaceNode(index,o); }
         public final int indexNode(Object o) { return bt().indexNode(o); }
     }
-    
-    // FEATURE: JS.StringKeys
-    /* public static StringKeys extends JS {
-        public JS get(JS key) { return JS.isString(key) ? get(JS.toString(key) : null; }
-        ...
-    */
-    
+        
     JS _unclone() { return this; }
     
     public interface Cloneable { }
@@ -120,7 +114,7 @@ public abstract class JS {
         public final JS nextElement() throws JSExn { return !done ? _nextElement() : parent != null ? parent.nextElement() : null; }
         
         public JS get(JS key) throws JSExn {
-            //#switch(JS.toString(key))
+            //#jswitch(key)
             case "hasMoreElements": return B(hasMoreElements());
             case "nextElement": return nextElement();
             //#end
@@ -300,17 +294,21 @@ 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);
-        throw new Error("FIXME");
-        /*if (t != null) t.invoke(value);
-        elese put(key, value);*/
+        if(t == null || (t = t.writeTrap()) == null) put(key,value);
+        else new Interpreter(t,value,false).resume();
     }
 
     /** 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);
-        throw new Error("FIXME");
-        /*if (t != null) return t.invoke();
-        else return get(key);*/
+        if (t == null || (t = t.readTrap()) == null) return get(key);
+        else return new Interpreter(t,null,false).resume();
+    }
+    
+    public JS justTriggerTraps(JS key, JS value) throws JSExn {
+        Trap t = getTrap(key);
+        if(t == null || (t = t.writeTrap()) == null) return value;
+        else return new Interpreter(t,value,true).resume();
     }
 
     /** adds a trap, avoiding duplicates */