X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2Fjs%2FJS.java;h=0336e2712cfc14f77136e5181d606608ee5cc346;hb=772b947b9b23de711953d0a1e33cef5f356c442a;hp=de0c5fcc8ee36f910409934b69ff6c73bf214424;hpb=565aae615b34b3fa4d61a72d93b651ff648eb3c3;p=org.ibex.core.git diff --git a/src/org/xwt/js/JS.java b/src/org/xwt/js/JS.java index de0c5fc..0336e27 100644 --- a/src/org/xwt/js/JS.java +++ b/src/org/xwt/js/JS.java @@ -11,6 +11,14 @@ public class JS extends org.xwt.util.BalancedTree { // Static Interpreter Control Methods /////////////////////////////////////////////////////////////// + /** log a message with the current JavaScript sourceName/line */ + public static void log(Object o, Object message) { log(message); } + public static void log(Object message) { Log.echo(JS.getSourceName() + ":" + JS.getLine(), message); } + public static void log(JSExn e) { + Log.echo(e,"JS Exception: " + e.getObject() + "\n" + e.backtrace()); + Log.echo(e,e); + } + public static int getLine() { Interpreter c = Interpreter.current(); return c == null || c.f == null || c.pc < 0 || c.pc >= c.f.size ? -1 : c.f.line[c.pc]; @@ -21,15 +29,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 +39,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); @@ -160,7 +160,7 @@ public class JS extends org.xwt.util.BalancedTree { /** override and return true to allow placing traps on this object. * if isRead true, this is a read trap, otherwise write trap **/ - protected boolean isTrappable(Object name, boolean isRead) { return false; } + protected boolean isTrappable(Object name, boolean isRead) { return true; } /** performs a put, triggering traps if present; traps are run in an unpauseable interpreter */ public void putAndTriggerTraps(Object key, Object value) throws JSExn { @@ -219,9 +219,12 @@ public class JS extends org.xwt.util.BalancedTree { // Typing Support ////////////////////////////////////////////////////////////////////////////// - public Number coerceToNumber() { throw new JSRuntimeExn("tried to coerce a JavaScript object to a Number"); } - public String coerceToString() { throw new JSRuntimeExn("tried to coerce a JavaScript object to a String"); } - public boolean coerceToBoolean() { throw new JSRuntimeExn("tried to coerce a JavaScript object to a Boolean"); } + public Number coerceToNumber() { throw new JSRuntimeExn("tried to coerce a JavaScript object of type " + + getClass().getName() + " to a Number"); } + public String coerceToString() { throw new JSRuntimeExn("tried to coerce a JavaScript object of type " + + getClass().getName() + " to a String"); } + public boolean coerceToBoolean() { throw new JSRuntimeExn("tried to coerce a JavaScript object of type " + + getClass().getName() + " to a Boolean"); } public String typeName() { return "object"; }