X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2Fjs%2FJSExn.java;h=df905e8b7b3f2d9101cda2e1871b6f1e864398df;hb=73131826a18c93af4fb04672bc3ec820e1197ad1;hp=1fda3c763c2a1e85fab6bdecf1fc6b1e22e66025;hpb=4145cca4956fbcee2a976bd01829ed785e603cc0;p=org.ibex.js.git diff --git a/src/org/ibex/js/JSExn.java b/src/org/ibex/js/JSExn.java index 1fda3c7..df905e8 100644 --- a/src/org/ibex/js/JSExn.java +++ b/src/org/ibex/js/JSExn.java @@ -1,4 +1,7 @@ -// Copyright 2004 Adam Megacz, see the COPYING file for licensing [GPL] +// Copyright 2000-2005 the Contributors, as shown in the revision logs. +// Licensed under the Apache Public Source License 2.0 ("the License"). +// You may not use this file except in compliance with the License. + package org.ibex.js; import org.ibex.util.*; @@ -7,27 +10,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 Object js = null; - public JSExn(Object js) { - this.js = js; - if (Interpreter.current() != null) - fill(Interpreter.current().stack, Interpreter.current().f, Interpreter.current().pc, Interpreter.current().scope); - } - public JSExn(Object js, Vec stack, JSFunction f, int pc, JSScope scope) { this.js = js; fill(stack, f, pc, scope); } - private void fill(Vec stack, JSFunction f, int pc, JSScope scope) { - addBacktrace(f.sourceName + ":" + f.line[pc]); - if (scope != null && scope instanceof Trap.TrapScope) - addBacktrace("trap on property \"" + ((Trap.TrapScope)scope).t.name + "\""); - for(int i=stack.size()-1; i>=0; i--) { - Object element = stack.elementAt(i); - if (element instanceof Interpreter.CallMarker) { - Interpreter.CallMarker cm = (Interpreter.CallMarker)element; - if (cm.f != null) - addBacktrace(cm.f.sourceName + ":" + cm.f.line[cm.pc-1]); - if (cm.scope != null && cm.scope instanceof Trap.TrapScope) - addBacktrace("trap on property \"" + ((Trap.TrapScope)cm.scope).t.name + "\""); - } - } + private JS js; + public JSExn(String s) { this(JS.S(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) { @@ -38,12 +30,22 @@ public class JSExn extends Exception { for(int i=0; i