2003/12/29 22:31:38
[org.ibex.core.git] / src / org / xwt / js / JSFunction.java
index a9164b8..8e5c92a 100644 (file)
@@ -6,7 +6,7 @@ import java.util.*;
 import java.io.*;
 
 /** A JavaScript function, compiled into bytecode */
-public class JSFunction extends JS implements ByteCodes, Tokens {
+public class JSFunction extends JS implements ByteCodes, Tokens, org.xwt.Scheduler.Task {
 
 
     // Fields and Accessors ///////////////////////////////////////////////
@@ -26,6 +26,14 @@ public class JSFunction extends JS implements ByteCodes, Tokens {
 
     // Public //////////////////////////////////////////////////////////////////////////////
 
+    // FEATURE: make sure that this can only be called from the Scheduler...
+    /** if you enqueue a function, it gets invoked in its own pauseable context */
+    public void perform() throws JSExn {
+        Interpreter i = new Interpreter(this, true, new JSArray());
+        int oldpausecount = i.pausecount;
+        i.resume();
+    }
+
     /** parse and compile a function */
     public static JSFunction fromReader(String sourceName, int firstLine, Reader sourceCode) throws IOException {
         JSFunction ret = new JSFunction(sourceName, firstLine, null);
@@ -54,7 +62,7 @@ public class JSFunction extends JS implements ByteCodes, Tokens {
     }
 
     /** Note: code gets run in an <i>unpauseable</i> context. */
-    public Object call(Object a0, Object a1, Object a2, Object[] rest, int nargs) {
+    public Object call(Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn {
         JSArray args = new JSArray();
         if (nargs > 0) args.addElement(a0);
         if (nargs > 1) args.addElement(a1);