public static UnpauseCallback pause() throws NotPauseableException {
Interpreter i = Interpreter.current();
if (i.pausecount == -1) throw new NotPauseableException();
+ boolean get;
+ switch(i.f.op[i.pc]) {
+ case Tokens.RETURN: case ByteCodes.PUT: get = false; break;
+ case ByteCodes.GET: get = true; break;
+ default: throw new Error("should never happen");
+ }
i.pausecount++;
- return new JS.UnpauseCallback(i);
+ return new JS.UnpauseCallback(i,get);
}
public static class UnpauseCallback implements Task {
- Interpreter i;
- UnpauseCallback(Interpreter i) { this.i = i; }
- public void perform() throws JSExn { unpause((JS)null); }
- public void unpause(JS o) throws JSExn {
- i.stack.push(o);
- i.resume();
+ private Interpreter i;
+ private boolean get;
+ UnpauseCallback(Interpreter i, boolean get) { this.i = i; this.get = get; }
+ public void perform() throws JSExn { unpause(); }
+ public JS unpause() throws JSExn { return unpause((JS)null); }
+ public JS unpause(JS o) throws JSExn {
+ if (o == JS.METHOD) throw new JSExn("can't return a method to a paused context");
+ if(get) i.stack.push(o);
+ return i.resume();
}
- public void unpause(JSExn e) {
- // FIXME: Throw the JSExn into the js world
- throw new Error("Exception " + e + " thrown from background task");
+ public JS unpause(JSExn e) throws JSExn {
+ i.catchException(e);
+ return i.resume();
}
}