X-Git-Url: http://git.megacz.com/?p=org.ibex.core.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fjs%2FJSExn.java;h=2afcef188c89e25c0192151c2739d3f34d26628a;hp=13011994403a1e1dc413fde53b24167f1042e6f5;hb=3f8aa5300e178e8975b0edc896a5a9d303e7bdf3;hpb=4c96b0f7e40e4689434c46e4300cc9bef9d0fab9 diff --git a/src/org/ibex/js/JSExn.java b/src/org/ibex/js/JSExn.java index 1301199..2afcef1 100644 --- a/src/org/ibex/js/JSExn.java +++ b/src/org/ibex/js/JSExn.java @@ -7,27 +7,16 @@ import java.io.*; /** An exception which can be thrown and caught by JavaScript code */ public class JSExn extends Exception { private Vec backtrace = new Vec(); - private JS js = null; + private JS js; public JSExn(String s) { this(JS.S(s)); } - public JSExn(JS js) { - this.js = js; - if (Interpreter.current() != null) - fill(Interpreter.current().stack, Interpreter.current().f, Interpreter.current().pc, Interpreter.current().scope); - } - public JSExn(JS js, Interpreter.Stack stack, JSFunction f, int pc, JSScope scope) { this.js = js; fill(stack, f, pc, scope); } - private void fill(Interpreter.Stack stack, JSFunction f, int pc, JSScope scope) { - addBacktrace(f.sourceName + ":" + f.line[pc]); - for(int i=stack.size()-1; i>=0; i--) { - JS element = stack.elementAt(i); - if (element instanceof Interpreter.CallMarker) { - Interpreter.CallMarker cm = (Interpreter.CallMarker)element; - if(cm.f == null) break; - String s = cm.f.sourceName + ":" + cm.f.line[cm.pc-1]; - if(cm instanceof Interpreter.TrapMarker) - s += " (trap on " + JS.debugToString(((Interpreter.TrapMarker)cm).key) + ")"; - addBacktrace(s); - } - } + public JSExn(JS js) { this(js,null); } + public JSExn(JS js, Interpreter cx) { this.js = js; fill(cx); } + + private void fill(Interpreter cx) { + if(cx == null) cx = Interpreter.current(); + if(cx == null) return; + addBacktrace(cx.f.sourceName + ":" + cx.f.line[cx.pc]); + cx.stack.backtrace(this); } public void printStackTrace() { printStackTrace(System.err); } public void printStackTrace(PrintWriter pw) { @@ -41,9 +30,19 @@ public class JSExn extends Exception { public String toString() { return "JSExn: " + JS.debugToString(js); } public String getMessage() { return toString(); } public JS getObject() { return js; } - public void addBacktrace(String line) { backtrace.addElement(line); } - - + + void addBacktrace(String line) { backtrace.addElement(line); } + + public static class Wrapper extends RuntimeException { + public final JSExn e; + public Wrapper(JSExn e) { this.e = e; } + public JSExn refill() { + e.addBacktrace("[foreign code]"); + e.fill(null); + return e; + } + } + public static class IO extends JSExn { public IO(java.io.IOException ioe) { super("ibex.io: " + ioe.toString());