new js api
[org.ibex.core.git] / src / org / ibex / js / JSExn.java
index 6f2a1ab..e01b769 100644 (file)
@@ -7,20 +7,21 @@ 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) {
+    private JS js = null; 
+    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(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) {
+    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]);
         // FIXME: "trap on property"
         /*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);
+            JS element = stack.elementAt(i);
             if (element instanceof Interpreter.CallMarker) {
                 Interpreter.CallMarker cm = (Interpreter.CallMarker)element;
                 if (cm.f != null)
@@ -39,9 +40,9 @@ public class JSExn extends Exception {
         for(int i=0; i<backtrace.size(); i++) ps.println("    at " + (String) backtrace.elementAt(i));
         super.printStackTrace(ps);
     }
-    public String toString() { return "JSExn: " + js; }
+    public String toString() { return "JSExn: " + JS.debugToString(js); }
     public String getMessage() { return toString(); }
-    public Object getObject() { return js; } 
+    public JS getObject() { return js; } 
     public void addBacktrace(String line) { backtrace.addElement(line); }
 
 
@@ -52,13 +53,3 @@ public class JSExn extends Exception {
         }
     }
 } 
-
-/** should only be used for failed coercions */
-class JSRuntimeExn extends RuntimeException {
-    private Object js = null; 
-    public JSRuntimeExn(Object js) { this.js = js; } 
-    public String toString() { return "JSRuntimeExn: " + js; }
-    public String getMessage() { return toString(); }
-    public Object getObject() { return js; } 
-}
-