throw new JSExn("method not found (" + JS.debugToString(method) + ")");
}
- // FIXME: JSArgs objects, pointers into stack frame
public JS call(JS a0, JS a1, JS a2, JS[] rest, int nargs) throws JSExn {
throw new JSExn("you cannot call this object (class=" + this.getClass().getName() +")");
}
Trap getTrap(JS key) { return null; }
void putTrap(JS key, Trap value) throws JSExn { throw new JSExn("traps cannot be placed on this object (class=" + this.getClass().getName() +")"); }
String coerceToString() throws JSExn { throw new JSExn("can't coerce to a string (class=" + getClass().getName() +")"); }
+ String debugToString() { return "[class=" + getClass().getName() + "]"; }
boolean jsequals(JS o) { return this == o; }
public static class O extends JS {
public static String debugToString(JS o) {
try { return toString(o); }
- catch(JSExn e) { return "[class=" + o.getClass().getName() + "]"; }
+ catch(JSExn e) { return o.debugToString(); }
}
public static boolean isInt(JS o) {
a.setElementAt(elementAt(start+i),i);
return a;
}
-
+
private static final Vec.CompareFunc defaultSort = new Vec.CompareFunc() {
public int compare(Object a, Object b) {
try {
return JS.toString((JS)a).compareTo(JS.toString((JS)b));
- } catch(JSExn e) {
- // FIXME: See emca about this
- throw new RuntimeException(e.toString());
- }
+ } catch(JSExn e) { throw new JSExn.Wrapper(e); }
}
};
private JS sort(JS tmp) throws JSExn {
Vec vec = toVec();
- if(tmp instanceof JS) {
- final JS jsFunc = (JS) tmp;
- vec.sort(new Vec.CompareFunc() {
- public int compare(Object a, Object b) {
- try {
- return JS.toInt(jsFunc.call((JS)a, (JS)b, null, null, 2));
- } catch (JSExn e) {
- // FIXME: Check ecma to see what we should do here
- throw new RuntimeException(e.toString());
+ try {
+ if(tmp instanceof JS) {
+ final JS jsFunc = (JS) tmp;
+ vec.sort(new Vec.CompareFunc() {
+ public int compare(Object a, Object b) {
+ try {
+ return JS.toInt(jsFunc.call((JS)a, (JS)b, null, null, 2));
+ } catch(JSExn e) { throw new JSExn.Wrapper(e); }
}
- }
- });
- } else {
- vec.sort(defaultSort);
+ });
+ } else {
+ vec.sort(defaultSort);
+ }
+ } catch(JSExn.Wrapper e) {
+ throw e.refill();
}
setFromVec(vec);
return this;
private Vec backtrace = new Vec();
private JS js;
public JSExn(String s) { this(JS.S(s)); }
- public JSExn(JS js) { this(js,Interpreter.current()); }
- public JSExn(JS js, Interpreter cx) {
- this.js = js;
- if(cx != null) fill(cx);
- }
+ 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);
}
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());
// Debugging //////////////////////////////////////////////////////////////////////
- // FIXME: Put this back in
- public String xtoString() { return "JSFunction [" + sourceName + ":" + firstLine + "]"; }
+ String debugToString() { return "JSFunction [" + sourceName + ":" + firstLine + "]"; }
String dump() { return dump(""); }
private String dump(String prefix) {
public JS callMethod(JS method, JS a0, JS a1, JS a2, JS[] rest, int nargs) throws JSExn {
if(!JS.isString(method)) return null;
if("print".equals(JS.toString(method))) {
- System.out.println(JS.toString(a0));
+ System.out.println(JS.debugToString(a0));
return null;
}
return null;