From: megacz Date: Fri, 30 Jan 2004 07:42:50 +0000 (+0000) Subject: 2003/12/13 08:13:33 X-Git-Tag: RC3~270 X-Git-Url: http://git.megacz.com/?p=org.ibex.core.git;a=commitdiff_plain;h=de0141dae807567fa444fe99bbe4821543f4f507 2003/12/13 08:13:33 darcs-hash:20040130074250-2ba56-0fc9b6616e996bee1fbe7a914e18ba1a6260c6bb.gz --- diff --git a/src/org/xwt/js/JS.java b/src/org/xwt/js/JS.java index de0c5fc..60c974a 100644 --- a/src/org/xwt/js/JS.java +++ b/src/org/xwt/js/JS.java @@ -21,15 +21,6 @@ public class JS extends org.xwt.util.BalancedTree { return c == null || c.f == null ? null : c.f.sourceName; } - public static class PausedException extends Exception { PausedException() { } } - - public static void invokePauseable(JSFunction function) throws JS.PausedException, JSExn { - Interpreter i = new Interpreter(function, true, new JSArray()); - int oldpausecount = i.pausecount; - i.resume(); - if (i.pausecount > oldpausecount) throw new PausedException(); - } - public static class NotPauseableException extends Exception { NotPauseableException() { } } /** returns a callback which will restart the context; expects a value to be pushed onto the stack when unpaused */ @@ -40,9 +31,10 @@ public class JS extends org.xwt.util.BalancedTree { return new JS.UnpauseCallback(i); } - public static class UnpauseCallback { + public static class UnpauseCallback implements Scheduler.Task { Interpreter i; UnpauseCallback(Interpreter i) { this.i = i; } + public void perform() throws JSExn { unpause(null); } public void unpause(Object o) throws JSExn { // FIXME: if o instanceof JSExn, throw it into the JSworld i.stack.push(o); diff --git a/src/org/xwt/js/JSFunction.java b/src/org/xwt/js/JSFunction.java index c15ef55..8e5c92a 100644 --- a/src/org/xwt/js/JSFunction.java +++ b/src/org/xwt/js/JSFunction.java @@ -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);