2003/11/16 08:28:10
[org.ibex.core.git] / src / org / xwt / js / JSContext.java
index 4eaf9b2..ec73e94 100644 (file)
@@ -23,23 +23,40 @@ public class JSContext {
      *  eval()
      */
     int pausecount = 0;
+    boolean pauseable;
 
-    JSFunction f = null;          ///< the currently-executing JSFunction
-    JSScope scope = null;
+    JSFunction f;                 ///< the currently-executing JSFunction
+    JSScope scope;
     Vec stack = new Vec();        ///< the object stack
     int pc = 0;                   ///< the program counter
-    boolean pauseable;
 
-    public static void invokePauseable(JSFunction function) { new JSContext(f, true).invoke(new JSArray()); }
+    /** can be paused */
+    public static void invokePauseable(JSFunction function) {
+        new JSContext(function, true).invoke(new JSArray());
+    }
+
+    /** cannot be paused */
+    public static void invokeTrap(JSTrap.JSTrappable t, Object key, Object value) {
+        JSFunction invoker = new JSFunction("trap invoker", 0, null);
+        invoker.add(-1, ByteCodes.PUT, null);
+        JSContext cx = new JSContext(invoker, false);
+        cx.stack.push(t);
+        cx.stack.push(key);
+        cx.stack.push(value);
+        cx.resume();
+    }
 
     JSContext(JSFunction f, boolean pauseable) {
         this.pauseable = pauseable;
         this.f = f;
-        scope = new JSScope(function.parentJSScope);
+        scope = new JSScope(f.parentJSScope);
     }
 
     void invoke(JSArray args) {
-        stack.push(new JSFunction.CallMarker(cx));
+        JSFunction tf = f;
+        f = null;
+        stack.push(new Interpreter.CallMarker(this));
+        f = tf;
         stack.push(args);
         resume();
     }
@@ -50,8 +67,8 @@ public class JSContext {
         if (!pauseable) return null;
         pausecount++;
         return new Callback() { public Object call(Object o) {
-            paused = false;
             stack.push(o);
+            pc++;
             resume();
             return null;
         } };
@@ -62,7 +79,7 @@ public class JSContext {
         JSContext old = (JSContext)threadToJSContext.get(t);
         threadToJSContext.put(t, this);
         try {
-            JSFunction.eval(this);
+            Interpreter.eval(this);
         } finally {
             if (old == null) threadToJSContext.remove(t);
             else threadToJSContext.put(t, old);